You are here

public function WorkspaceDeleteForm::buildForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/workspaces/src/Form/WorkspaceDeleteForm.php \Drupal\workspaces\Form\WorkspaceDeleteForm::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 ContentEntityDeleteForm::buildForm

File

core/modules/workspaces/src/Form/WorkspaceDeleteForm.php, line 79

Class

WorkspaceDeleteForm
Provides a form for deleting a workspace.

Namespace

Drupal\workspaces\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $workspace_tree = $this->workspaceRepository
    ->loadTree();
  if (!empty($workspace_tree[$this->entity
    ->id()]['descendants'])) {
    $form['description']['#markup'] = $this
      ->t('The %label workspace can not be deleted because it has child workspaces.', [
      '%label' => $this->entity
        ->label(),
    ]);
    $form['actions']['submit']['#disabled'] = TRUE;
    return $form;
  }
  $tracked_entities = $this->workspaceAssociation
    ->getTrackedEntities($this->entity
    ->id());
  $items = [];
  foreach ($tracked_entities as $entity_type_id => $entity_ids) {
    $revision_ids = $this->workspaceAssociation
      ->getAssociatedRevisions($this->entity
      ->id(), $entity_type_id, $entity_ids);
    $label = $this->entityTypeManager
      ->getDefinition($entity_type_id)
      ->getLabel();
    $items[] = $this
      ->formatPlural(count($revision_ids), '1 @label revision.', '@count @label revisions.', [
      '@label' => $label,
    ]);
  }
  $form['revisions'] = [
    '#theme' => 'item_list',
    '#title' => $this
      ->t('The following will also be deleted:'),
    '#items' => $items,
  ];
  return $form;
}