function DefaultsEntityForm::buildMessage

Same name in other branches
  1. 8.9.x 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()
  3. 11.x 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,
    ];
}

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