public function VocabularyForm::form in Drupal 10
Same name and namespace in other branches
- 8 core/modules/taxonomy/src/VocabularyForm.php \Drupal\taxonomy\VocabularyForm::form()
- 9 core/modules/taxonomy/src/VocabularyForm.php \Drupal\taxonomy\VocabularyForm::form()
File
- core/modules/taxonomy/src/VocabularyForm.php, line 48
Class
- VocabularyForm
- Base form for vocabulary edit forms.
Namespace
Drupal\taxonomy
Code
public function form(array $form, FormStateInterface $form_state) {
$vocabulary = $this->entity;
if ($vocabulary
->isNew()) {
$form['#title'] = $this
->t('Add vocabulary');
}
else {
$form['#title'] = $this
->t('Edit vocabulary');
}
$form['name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Name'),
'#default_value' => $vocabulary
->label(),
'#maxlength' => 255,
'#required' => TRUE,
];
$form['vid'] = [
'#type' => 'machine_name',
'#default_value' => $vocabulary
->id(),
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'source' => [
'name',
],
],
];
$form['description'] = [
'#type' => 'textfield',
'#title' => $this
->t('Description'),
'#default_value' => $vocabulary
->getDescription(),
];
$form['langcode'] = [
'#type' => 'language_select',
'#title' => $this
->t('Vocabulary language'),
'#languages' => LanguageInterface::STATE_ALL,
'#default_value' => $vocabulary
->language()
->getId(),
];
if ($this->moduleHandler
->moduleExists('language')) {
$form['default_terms_language'] = [
'#type' => 'details',
'#title' => $this
->t('Term language'),
'#open' => TRUE,
];
$form['default_terms_language']['default_language'] = [
'#type' => 'language_configuration',
'#entity_information' => [
'entity_type' => 'taxonomy_term',
'bundle' => $vocabulary
->id(),
],
'#default_value' => ContentLanguageSettings::loadByEntityTypeBundle('taxonomy_term', $vocabulary
->id()),
];
}
$form['hierarchy'] = [
'#type' => 'value',
'#value' => '0',
];
$form = parent::form($form, $form_state);
return $this
->protectBundleIdElement($form);
}