function OverridesEntityForm::buildMessage

Same name in other branches
  1. 9 core/modules/layout_builder/src/Form/OverridesEntityForm.php \Drupal\layout_builder\Form\OverridesEntityForm::buildMessage()
  2. 8.9.x core/modules/layout_builder/src/Form/OverridesEntityForm.php \Drupal\layout_builder\Form\OverridesEntityForm::buildMessage()
  3. 11.x core/modules/layout_builder/src/Form/OverridesEntityForm.php \Drupal\layout_builder\Form\OverridesEntityForm::buildMessage()

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

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity whose layout is being edited.

\Drupal\layout_builder\OverridesSectionStorageInterface $section_storage: The current section storage.

Return value

array A renderable array containing the message.

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

File

core/modules/layout_builder/src/Form/OverridesEntityForm.php, line 118

Class

OverridesEntityForm
Provides a form containing the Layout Builder UI for overrides.

Namespace

Drupal\layout_builder\Form

Code

protected function buildMessage(EntityInterface $entity, OverridesSectionStorageInterface $section_storage) {
    $entity_type = $entity->getEntityType();
    $bundle_info = $this->entityTypeBundleInfo
        ->getBundleInfo($entity->getEntityTypeId());
    $variables = [
        '@bundle' => $bundle_info[$entity->bundle()]['label'],
        '@singular_label' => $entity_type->getSingularLabel(),
        '@plural_label' => $entity_type->getPluralLabel(),
    ];
    $defaults_link = $section_storage->getDefaultSectionStorage()
        ->getLayoutBuilderUrl();
    if ($defaults_link->access($this->currentUser())) {
        $variables[':link'] = $defaults_link->toString();
        if ($entity_type->hasKey('bundle')) {
            $message = $this->t('You are editing the layout for this @bundle @singular_label. <a href=":link">Edit the template for all @bundle @plural_label instead.</a>', $variables);
        }
        else {
            $message = $this->t('You are editing the layout for this @singular_label. <a href=":link">Edit the template for all @plural_label instead.</a>', $variables);
        }
    }
    else {
        if ($entity_type->hasKey('bundle')) {
            $message = $this->t('You are editing the layout for this @bundle @singular_label.', $variables);
        }
        else {
            $message = $this->t('You are editing the layout for this @singular_label.', $variables);
        }
    }
    return $this->buildMessageContainer($message, 'overrides');
}

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