public PathFormBase::buildForm(array $form, FormStateInterface $form_state, $pid = NULL)
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- core/modules/path/src/Form/PathFormBase.php, line 96
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | public function buildForm( array $form , FormStateInterface $form_state , $pid = NULL) { $this ->path = $this ->buildPath( $pid ); $form [ 'source' ] = array ( '#type' => 'textfield' , '#title' => $this ->t( 'Existing system path' ), '#default_value' => $this ->path[ 'source' ], '#maxlength' => 255, '#size' => 45, '#description' => $this ->t( 'Specify the existing path you wish to alias. For example: /node/28, /forum/1, /taxonomy/term/1.' ), '#field_prefix' => $this ->requestContext->getCompleteBaseUrl(), '#required' => TRUE, ); $form [ 'alias' ] = array ( '#type' => 'textfield' , '#title' => $this ->t( 'Path alias' ), '#default_value' => $this ->path[ 'alias' ], '#maxlength' => 255, '#size' => 45, '#description' => $this ->t( 'Specify an alternative path by which this data can be accessed. For example, type "/about" when writing an about page.' ), '#field_prefix' => $this ->requestContext->getCompleteBaseUrl(), '#required' => TRUE, ); // A hidden value unless language.module is enabled. if (\Drupal::moduleHandler()->moduleExists( 'language' )) { $languages = \Drupal::languageManager()->getLanguages(); $language_options = array (); foreach ( $languages as $langcode => $language ) { $language_options [ $langcode ] = $language ->getName(); } $form [ 'langcode' ] = array ( '#type' => 'select' , '#title' => $this ->t( 'Language' ), '#options' => $language_options , '#empty_value' => LanguageInterface::LANGCODE_NOT_SPECIFIED, '#empty_option' => $this ->t( '- None -' ), '#default_value' => $this ->path[ 'langcode' ], '#weight' => -10, '#description' => $this ->t( 'A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set as <em>- None -</em>.' ), ); } else { $form [ 'langcode' ] = array ( '#type' => 'value' , '#value' => $this ->path[ 'langcode' ] ); } $form [ 'actions' ] = array ( '#type' => 'actions' ); $form [ 'actions' ][ 'submit' ] = array ( '#type' => 'submit' , '#value' => $this ->t( 'Save' ), '#button_type' => 'primary' , ); return $form ; } |
Please login to continue.