You are here

public function TaxonomyEntityIndexAdminReindexForm::buildForm in Taxonomy Entity Index 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 FormInterface::buildForm

File

src/Form/TaxonomyEntityIndexAdminReindexForm.php, line 63

Class

TaxonomyEntityIndexAdminReindexForm
Provides the reindex form.

Namespace

Drupal\taxonomy_entity_index\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  $entity_types_to_index = $this->configFactory
    ->get('taxonomy_entity_index.settings')
    ->get('types');
  foreach ($entity_types as $entity_type_id => $entity_type) {
    if (!is_null($entity_type
      ->getBaseTable()) && $entity_type
      ->entityClassImplements('\\Drupal\\Core\\Entity\\ContentEntityInterface') && in_array($entity_type_id, $entity_types_to_index)) {
      $options[$entity_type_id] = $entity_type
        ->getLabel() . " <em>({$entity_type_id})</em>";
    }
  }
  asort($options);
  $form['description'] = [
    '#markup' => $this
      ->t('<p>Use this form to reindex all terms for the selected entity types.</p>'),
  ];
  $form['types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Entity types'),
    '#options' => $options,
    '#description' => $this
      ->t('Re-index all terms for the selected entity types.'),
    '#required' => TRUE,
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Rebuild index'),
  ];
  return $form;
}