You are here

protected function DefaultsEntityForm::buildMessage in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/src/Form/DefaultsEntityForm.php \Drupal\layout_builder\Form\DefaultsEntityForm::buildMessage()
  2. 10 core/modules/layout_builder/src/Form/DefaultsEntityForm.php \Drupal\layout_builder\Form\DefaultsEntityForm::buildMessage()

Renders a message to display at the top of the layout builder.

Parameters

\Drupal\layout_builder\Entity\LayoutEntityDisplayInterface $entity: The entity view display being edited.

Return value

array A renderable array containing the message.

1 call to DefaultsEntityForm::buildMessage()
DefaultsEntityForm::buildForm in core/modules/layout_builder/src/Form/DefaultsEntityForm.php
Form constructor.

File

core/modules/layout_builder/src/Form/DefaultsEntityForm.php, line 114

Class

DefaultsEntityForm
Provides a form containing the Layout Builder UI for defaults.

Namespace

Drupal\layout_builder\Form

Code

protected function buildMessage(LayoutEntityDisplayInterface $entity) {
  $entity_type_id = $entity
    ->getTargetEntityTypeId();
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  $bundle_info = $this->entityTypeBundleInfo
    ->getBundleInfo($entity_type_id);
  $args = [
    '@bundle' => $bundle_info[$entity
      ->getTargetBundle()]['label'],
    '@plural_label' => $entity_type
      ->getPluralLabel(),
  ];
  if ($entity_type
    ->hasKey('bundle')) {
    $message = $this
      ->t('You are editing the layout template for all @bundle @plural_label.', $args);
  }
  else {
    $message = $this
      ->t('You are editing the layout template for all @plural_label.', $args);
  }
  return [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'layout-builder__message',
        'layout-builder__message--defaults',
      ],
    ],
    'message' => [
      '#theme' => 'status_messages',
      '#message_list' => [
        'status' => [
          $message,
        ],
      ],
      '#status_headings' => [
        'status' => $this
          ->t('Status message'),
      ],
    ],
    '#weight' => -900,
  ];
}