public function PathFormBase::buildForm in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/path/src/Form/PathFormBase.php \Drupal\path\Form\PathFormBase::buildForm()
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
1 call to PathFormBase::buildForm()
- EditForm::buildForm in core/
modules/ path/ src/ Form/ EditForm.php - Form constructor.
1 method overrides PathFormBase::buildForm()
- EditForm::buildForm in core/
modules/ path/ src/ Form/ EditForm.php - Form constructor.
File
- core/
modules/ path/ src/ Form/ PathFormBase.php, line 101 - Contains \Drupal\path\Form\PathFormBase.
Class
- PathFormBase
- Provides a base class for path add/edit forms.
Namespace
Drupal\path\FormCode
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. Use a relative path with a slash in front..'),
'#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'),
);
return $form;
}