public PathFormBase::validateForm(array &$form, FormStateInterface $form_state)
Form validation handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormBase::validateForm
File
- core/modules/path/src/Form/PathFormBase.php, line 158
Class
- PathFormBase
- Provides a base class for path add/edit forms.
Namespace
Drupal\path\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | public function validateForm( array & $form , FormStateInterface $form_state ) { $source = & $form_state ->getValue( 'source' ); $source = $this ->aliasManager->getPathByAlias( $source ); $alias = & $form_state ->getValue( 'alias' ); // Trim the submitted value of whitespace and slashes. Ensure to not trim // the slash on the left side. $alias = rtrim(trim(trim( $alias ), '' ), "\\/" ); if ( $source [0] !== '/' ) { $form_state ->setErrorByName( 'source' , 'The source path has to start with a slash.' ); } if ( $alias [0] !== '/' ) { $form_state ->setErrorByName( 'alias' , 'The alias path has to start with a slash.' ); } // Language is only set if language.module is enabled, otherwise save for all // languages. $langcode = $form_state ->getValue( 'langcode' , LanguageInterface::LANGCODE_NOT_SPECIFIED); if ( $this ->aliasStorage->aliasExists( $alias , $langcode , $this ->path[ 'source' ])) { $stored_alias = $this ->aliasStorage->load([ 'alias' => $alias , 'langcode' => $langcode ]); if ( $stored_alias [ 'alias' ] !== $alias ) { // The alias already exists with different capitalization as the default // implementation of AliasStorageInterface::aliasExists is // case-insensitive. $form_state ->setErrorByName( 'alias' , t( 'The alias %alias could not be added because it is already in use in this language with different capitalization: %stored_alias.' , [ '%alias' => $alias , '%stored_alias' => $stored_alias [ 'alias' ], ])); } else { $form_state ->setErrorByName( 'alias' , t( 'The alias %alias is already in use in this language.' , [ '%alias' => $alias ])); } } if (! $this ->pathValidator->isValid(trim( $source , '/' ))) { $form_state ->setErrorByName( 'source' , t( "The path '@link_path' is either invalid or you do not have access to it." , array ( '@link_path' => $source ))); } } |
Please login to continue.