public function SimpleSitemapTypeEntityForm::form in Simple XML sitemap 4.x
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ SimpleSitemapTypeEntityForm.php, line 44
Class
- SimpleSitemapTypeEntityForm
- Class SimpleSitemapTypeEntityForm
Namespace
Drupal\simple_sitemap\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $this->entity
->label(),
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $this->entity
->id(),
'#disabled' => !$this->entity
->isNew(),
'#maxlength' => EntityTypeInterface::ID_MAX_LENGTH,
'#required' => TRUE,
'#machine_name' => [
'exists' => '\\Drupal\\simple_sitemap\\Entity\\SimpleSitemapType::load',
],
];
$form['sitemap_generator'] = [
'#type' => 'select',
'#title' => $this
->t('Sitemap generator'),
'#options' => array_map(function ($sitemap_generator) {
return $sitemap_generator['label'];
}, \Drupal::service('plugin.manager.simple_sitemap.sitemap_generator')
->getDefinitions()),
'#default_value' => !$this->entity
->isNew() ? $this->entity
->get('sitemap_generator') : NULL,
'#required' => TRUE,
];
$form['url_generators'] = [
'#type' => 'select',
'#title' => $this
->t('URL generators'),
'#options' => array_map(function ($url_generator) {
return $url_generator['label'];
}, \Drupal::service('plugin.manager.simple_sitemap.url_generator')
->getDefinitions()),
'#default_value' => !$this->entity
->isNew() ? $this->entity
->get('url_generators') : NULL,
'#multiple' => TRUE,
'#required' => TRUE,
];
$form['description'] = [
'#type' => 'textarea',
'#default_value' => $this->entity
->get('description'),
'#title' => $this
->t('Description'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}