public function BreadcrumbExtraFieldSettingsForm::buildForm in Breadcrumb Extra Field 8
Same name and namespace in other branches
- 2.x src/Form/BreadcrumbExtraFieldSettingsForm.php \Drupal\breadcrumb_extra_field\Form\BreadcrumbExtraFieldSettingsForm::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 ConfigFormBase::buildForm
File
- src/
Form/ BreadcrumbExtraFieldSettingsForm.php, line 23
Class
- BreadcrumbExtraFieldSettingsForm
- BreadcrumbExtraFieldSettingsForm Class.
Namespace
Drupal\breadcrumb_extra_field\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('breadcrumb_extra_field.settings');
$entity_info = \Drupal::service('entity_type.manager')
->getDefinitions();
$admin = $config
->get(BREADCRUMB_EXTRA_FIELD_ADMIN);
$allowed_entity_types = unserialize(BREADCRUMB_EXTRA_FIELD_ALLOWED_ENTITY_TYPES);
$form[BREADCRUMB_EXTRA_FIELD_ADMIN] = [
'#type' => 'fieldset',
'#title' => $this
->t('Select entity types which are going to use the breadcrumb extra field'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
'#description' => $this
->t('Enable extra field for these entity types and bundles.'),
];
foreach ($entity_info as $entity_type_key => $entity_type) {
$bundle_options = [];
// Skip not allowed entity types.
if (in_array($entity_type_key, $allowed_entity_types)) {
$bundles = \Drupal::service('entity_type.bundle.info')
->getBundleInfo($entity_type_key);
foreach ($bundles as $bundle_key => $bundle) {
$bundle_options[$bundle_key] = $bundle['label'];
}
$form[BREADCRUMB_EXTRA_FIELD_ADMIN][$entity_type_key] = [
'#type' => 'checkboxes',
'#title' => $entity_type
->getLabel(),
'#options' => $bundle_options,
'#default_value' => !empty($admin[$entity_type_key]) ? array_keys(array_filter($admin[$entity_type_key])) : [],
];
}
}
return parent::buildForm($form, $form_state);
}