public function FieldBlockConfigForm::buildForm in Field as Block 8.2
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/ FieldBlockConfigForm.php, line 111
Class
- FieldBlockConfigForm
- Configuration for select Entity types and delete blocks of unused types.
Namespace
Drupal\fieldblock\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$enabled = $this->fieldblockController
->getEnabledEntityTypes();
$form['enabled_entity_types'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Enable Entity Types'),
'#options' => $this
->getEntityTypeLabels(),
'#description' => $this
->t('Select the Entity Types to expose as field blocks.'),
'#default_value' => $enabled,
];
$orphaned_types = $this
->getOrphanedEntityTypes($enabled);
$cleanup_options = [];
$entity_type_definitions = $this->entityTypeManager
->getDefinitions();
foreach ($orphaned_types as $entity_type) {
if (isset($entity_type_definitions[$entity_type]) && $entity_type_definitions[$entity_type] instanceof ContentEntityTypeInterface) {
// This entity type still exists on the site.
$cleanup_options[$entity_type] = $entity_type_definitions[$entity_type]
->getLabel();
}
else {
// This entity type no longer exists on the site.
$cleanup_options[$entity_type] = $this
->t('Missing entity type: @type', [
'@type' => $entity_type,
]);
}
}
if (!empty($cleanup_options)) {
$form['cleanup'] = [
'#type' => 'checkboxes',
'#required' => FALSE,
'#title' => t('Clean up remaining field blocks of removed entity types'),
'#description' => t('These entity types no longer exist, but one or more of their field blocks still do. Select the entity type(s) of which the field block(s) must be removed.'),
'#default_value' => [],
'#options' => $cleanup_options,
];
}
return parent::buildForm($form, $form_state);
}