You are here

public function BatchUpdateForm::buildForm in Entity Usage 8

Same name and namespace in other branches
  1. 8.2 src/Form/BatchUpdateForm.php \Drupal\entity_usage\Form\BatchUpdateForm::buildForm()
  2. 8.3 src/Form/BatchUpdateForm.php \Drupal\entity_usage\Form\BatchUpdateForm::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 FormInterface::buildForm

File

src/Form/BatchUpdateForm.php, line 52

Class

BatchUpdateForm
Form to launch batch tracking of existing entities.

Namespace

Drupal\entity_usage\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $entity_types = $this->entityTypeManager
    ->getDefinitions();
  $types = [];
  foreach ($entity_types as $type => $entity_type) {

    // Only look for content entities.
    if ($entity_type
      ->entityClassImplements('\\Drupal\\Core\\Entity\\ContentEntityInterface')) {
      $types[$type] = new FormattableMarkup('@label (@machine_name)', [
        '@label' => $entity_type
          ->getLabel(),
        '@machine_name' => $type,
      ]);
    }
  }
  $form['description'] = [
    '#markup' => $this
      ->t("This form allows you to reset and track again all entity usages in your system.<br /> It may be useful if you want to have available the information about the relationships between entities before installing the module.<br /><b>Be aware though that using this operation will delete all tracked statistics and recreate everything again.</b>"),
  ];
  $form['host_entity_types'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Delete and recreate all usage statistics for these entity types:'),
    '#options' => $types,
    '#default_value' => array_keys($types),
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => $this
      ->t('Recreate entity usage statistics'),
  ];
  return $form;
}