You are here

public function AvailableEntitiesConfigurationForm::buildForm in Menu Token 8

Same name and namespace in other branches
  1. 9.1.x src/Form/AvailableEntitiesConfigurationForm.php \Drupal\menu_token\Form\AvailableEntitiesConfigurationForm::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/AvailableEntitiesConfigurationForm.php, line 63

Class

AvailableEntitiesConfigurationForm
Class AvailableEntitiesConfigurationForm.

Namespace

Drupal\menu_token\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('menu_token.availableentitiesconfiguration');
  $form['available_entities'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Available entities'),
    '#description' => $this
      ->t('Available entities'),
  ];
  $entity_type_definitions = $this->entityTypeManager
    ->getDefinitions();

  /* @var $definition EntityTypeManagerInterface */
  foreach ($entity_type_definitions as $definition) {
    if ($definition instanceof ContentEntityType) {
      if (!empty($config
        ->getRawData()['available_entities'][$definition
        ->id()])) {
        $form['available_entities']['#options'][$definition
          ->id()] = $definition
          ->id();

        // Definition that is marked for check is checked.
        $form['available_entities']['#default_value'][] = $definition
          ->id();
      }
      else {
        $form['available_entities']['#options'][$definition
          ->id()] = $definition
          ->id();
      }
    }
  }
  return parent::buildForm($form, $form_state);
}