function WorkspaceDeleteForm::buildForm
Same name in other branches
- 9 core/modules/workspaces/src/Form/WorkspaceDeleteForm.php \Drupal\workspaces\Form\WorkspaceDeleteForm::buildForm()
- 8.9.x core/modules/workspaces/src/Form/WorkspaceDeleteForm.php \Drupal\workspaces\Form\WorkspaceDeleteForm::buildForm()
- 11.x core/modules/workspaces/src/Form/WorkspaceDeleteForm.php \Drupal\workspaces\Form\WorkspaceDeleteForm::buildForm()
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\FormCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.