public function LayoutAddForm::form in Layout builder library 8
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/ LayoutAddForm.php, line 70
Class
- LayoutAddForm
- Defines a form for adding a layout library layout.
Namespace
Drupal\layout_library\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['#title'] = $this
->t('Add layout');
$form['label'] = [
'#type' => 'textfield',
'#title' => t('Label'),
'#maxlength' => 255,
'#description' => t("Provide a label for this layout to help identify it in the administration pages."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#machine_name' => [
'exists' => '\\Drupal\\layout_library\\Entity\\Layout::load',
],
'#maxlength' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
];
$entityTypes = $this->entityTypeManager
->getDefinitions();
$options = [];
foreach ($entityTypes as $id => $entityType) {
if (!$entityType
->entityClassImplements(ContentEntityInterface::class)) {
continue;
}
foreach ($this->bundleInfo
->getBundleInfo($id) as $bundleId => $bundle) {
$options[(string) $entityType
->getLabel()]["{$id}:{$bundleId}"] = $bundle['label'];
}
}
$form['_entity_type'] = [
'#type' => 'select',
'#options' => $options,
'#title' => $this
->t('Entity Type'),
'#description' => $this
->t('Choose the entity type and bundle that this layout will be used for.'),
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => t('Save'),
];
return $form;
}