function ContentEntityDeleteForm::buildForm

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php \Drupal\Core\Entity\ContentEntityDeleteForm::buildForm()
  2. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php \Drupal\Core\Entity\ContentEntityDeleteForm::buildForm()
  3. 10 core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php \Drupal\Core\Entity\ContentEntityDeleteForm::buildForm()

Overrides ContentEntityConfirmFormBase::buildForm

2 methods override ContentEntityDeleteForm::buildForm()
ContentTranslationDeleteForm::buildForm in core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php
Form constructor.
WorkspaceDeleteForm::buildForm in core/modules/workspaces/src/Form/WorkspaceDeleteForm.php
Form constructor.

File

core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php, line 25

Class

ContentEntityDeleteForm
Provides a generic base class for a content entity deletion form.

Namespace

Drupal\Core\Entity

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);
    
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    $entity = $this->getEntity();
    if ($entity->isDefaultTranslation()) {
        if (count($entity->getTranslationLanguages()) > 1) {
            $languages = [];
            foreach ($entity->getTranslationLanguages() as $language) {
                $languages[] = $language->getName();
            }
            $form['deleted_translations'] = [
                '#theme' => 'item_list',
                '#title' => $this->t('The following @entity-type translations will be deleted:', [
                    '@entity-type' => $entity->getEntityType()
                        ->getSingularLabel(),
                ]),
                '#items' => $languages,
            ];
            $form['actions']['submit']['#value'] = $this->t('Delete all translations');
        }
    }
    else {
        $form['actions']['submit']['#value'] = $this->t('Delete @language translation', [
            '@language' => $entity->language()
                ->getName(),
        ]);
    }
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.