You are here

public function OrphanedCompositeEntitiesDeleteForm::buildForm in Entity Reference Revisions 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/OrphanedCompositeEntitiesDeleteForm.php, line 77

Class

OrphanedCompositeEntitiesDeleteForm
Class OrphanedCompositeEntitiesDeleteForm.

Namespace

Drupal\entity_reference_revisions\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $this->messenger
    ->addWarning($this
    ->t('The submission of the current form can cause the deletion of entities that are still used, backup all data first.'), 'warning');
  $form['description'] = [
    '#markup' => $this
      ->t('Delete orphaned composite entities revisions that are no longer referenced. If there are no revisions left, the entity will be deleted as long as it is not used.'),
  ];
  $options = [];
  foreach ($this->purger
    ->getCompositeEntityTypes() as $entity_type) {
    $options[$entity_type
      ->id()] = $entity_type
      ->getLabel();
  }
  $form['composite_entity_types'] = [
    '#type' => 'checkboxes',
    '#required' => TRUE,
    '#title' => $this
      ->t('Select the entity types to check for orphans'),
    '#options' => $options,
    '#default_value' => array_keys($options),
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#button_type' => 'primary',
    '#value' => $this
      ->t('Delete orphaned composite revisions'),
  ];
  return $form;
}