You are here

public function EntityDescriptionFormTrait::form in Lightning Core 8

Same name and namespace in other branches
  1. 8.5 src/EntityDescriptionFormTrait.php \Drupal\lightning_core\EntityDescriptionFormTrait::form()
  2. 8.2 src/EntityDescriptionFormTrait.php \Drupal\lightning_core\EntityDescriptionFormTrait::form()
  3. 8.3 src/EntityDescriptionFormTrait.php \Drupal\lightning_core\EntityDescriptionFormTrait::form()
  4. 8.4 src/EntityDescriptionFormTrait.php \Drupal\lightning_core\EntityDescriptionFormTrait::form()

File

src/EntityDescriptionFormTrait.php, line 15

Class

EntityDescriptionFormTrait
Adds description support to entity forms.

Namespace

Drupal\lightning_core

Code

public function form(array $form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\Entity\EntityInterface|\Drupal\Core\Entity\EntityDescriptionInterface $entity */
  $entity = $this
    ->getEntity();
  $form = parent::form($form, $form_state);
  $form['description'] = [
    '#type' => 'textarea',
    '#title' => t('Description'),
    '#description' => $this
      ->t('Additional relevant information about this @entity_type, such as where it is used and what it is for.', [
      '@entity_type' => $entity
        ->getEntityType()
        ->getSingularLabel(),
    ]),
    '#rows' => 2,
    '#default_value' => $entity
      ->getDescription(),
  ];
  return $form;
}