ContentEntityDeleteForm::buildForm

public ContentEntityDeleteForm::buildForm(array $form, FormStateInterface $form_state)

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 ContentEntityConfirmFormBase::buildForm

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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'] = array(
        '#theme' => 'item_list',
        '#title' => $this->t('The following @entity-type translations will be deleted:', [
          '@entity-type' => $entity->getEntityType()->getLowercaseLabel()
        ]),
        '#items' => $languages,
      );
 
      $form['actions']['submit']['#value'] = $this->t('Delete all translations');
    }
  }
  else {
    $form['actions']['submit']['#value'] = $this->t('Delete @language translation', array('@language' => $entity->language()->getName()));
  }
 
  return $form;
}
doc_Drupal
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.