You are here

public function EntityUsageSettingsForm::buildForm in Entity Usage 8

Same name and namespace in other branches
  1. 8.4 src/Form/EntityUsageSettingsForm.php \Drupal\entity_usage\Form\EntityUsageSettingsForm::buildForm()
  2. 8.2 src/Form/EntityUsageSettingsForm.php \Drupal\entity_usage\Form\EntityUsageSettingsForm::buildForm()
  3. 8.3 src/Form/EntityUsageSettingsForm.php \Drupal\entity_usage\Form\EntityUsageSettingsForm::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/EntityUsageSettingsForm.php, line 79

Class

EntityUsageSettingsForm
Form to configure entity_usage settings.

Namespace

Drupal\entity_usage\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('entity_usage.settings');
  $configured_types = $config
    ->get('local_task_enabled_entity_types') ?: [];
  $form['local_task_enabled_entity_types'] = [
    '#type' => 'details',
    '#open' => TRUE,
    '#title' => $this
      ->t('Local tasks'),
    '#description' => $this
      ->t('Check in which entity types there should be a tab (local task) linking to the usage page.'),
    '#tree' => TRUE,
  ];

  // Get all applicable entity types.
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if ($entity_type instanceof ContentEntityTypeInterface && $entity_type
      ->hasLinkTemplate('canonical')) {
      $form['local_task_enabled_entity_types'][$entity_type_id] = [
        '#type' => 'checkbox',
        '#title' => $entity_type
          ->getLabel(),
        '#default_value' => in_array($entity_type_id, $configured_types),
      ];
    }
  }
  return parent::buildForm($form, $form_state);
}