You are here

public function BetterFieldDescriptionsEntitiesForm::buildForm in Better Field Descriptions 8

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/BetterFieldDescriptionsEntitiesForm.php, line 58

Class

BetterFieldDescriptionsEntitiesForm
Displays the better_field_descriptions_entities settings form.

Namespace

Drupal\better_field_descriptions\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Get info on bundles.
  $all_bundles = $this->bundleInfoService
    ->getAllBundleInfo();

  // Sort into order on entity ids.
  ksort($all_bundles);

  // Get the editiable config.
  $config = $this
    ->config('better_field_descriptions.settings');

  // Get list of entities selected for better descriptions.
  $bfde = $config
    ->get('better_field_descriptions_entities');
  $form['descriptions'] = [
    '#type' => 'markup',
    '#markup' => $this
      ->t('Select entity types that should have better descriptions.'),
  ];
  $form['entities'] = [
    '#type' => 'item',
    '#prefix' => '<div id="better-descriptions-form-id-wrapper">',
    '#suffix' => '</div>',
    '#tree' => TRUE,
  ];
  foreach ($all_bundles as $entity_type => $bundles) {
    $form['entities'][$entity_type] = [
      '#type' => 'checkbox',
      '#title' => $entity_type,
      '#default_value' => isset($bfde[$entity_type]),
    ];
  }
  return parent::buildForm($form, $form_state);
}