function LazyBuilders::renderAnnouncements

Same name in other branches
  1. 11.x core/modules/announcements_feed/src/LazyBuilders.php \Drupal\announcements_feed\LazyBuilders::renderAnnouncements()

Render announcements.

Return value

array Render array.

File

core/modules/announcements_feed/src/LazyBuilders.php, line 37

Class

LazyBuilders
Defines a class for lazy building render arrays.

Namespace

Drupal\announcements_feed

Code

public function renderAnnouncements() : array {
    $build = [
        '#type' => 'link',
        '#cache' => [
            'context' => [
                'user.permissions',
            ],
        ],
        '#title' => t('Announcements'),
        '#url' => Url::fromRoute('announcements_feed.announcement'),
        '#id' => Html::getId('toolbar-item-announcement'),
        '#attributes' => [
            'title' => t('Announcements'),
            'data-drupal-announce-trigger' => '',
            'class' => [
                'toolbar-icon',
                'toolbar-item',
                'toolbar-icon-announce',
                'use-ajax',
                'announce-canvas-link',
                'announce-default',
            ],
            'data-dialog-renderer' => 'off_canvas',
            'data-dialog-type' => 'dialog',
            'data-dialog-options' => Json::encode([
                'announce' => TRUE,
                'width' => '25%',
                'classes' => [
                    'ui-dialog' => 'announce-dialog',
                    'ui-dialog-titlebar' => 'announce-titlebar',
                    'ui-dialog-title' => 'announce-title',
                    'ui-dialog-titlebar-close' => 'announce-close',
                    'ui-dialog-content' => 'announce-body',
                ],
            ]),
        ],
        '#attached' => [
            'library' => [
                'announcements_feed/drupal.announcements_feed.toolbar',
            ],
        ],
    ];
    // The renderer has already added element defaults by the time the lazy
    // builder is run.
    // @see https://www.drupal.org/project/drupal/issues/2609250
    $build += $this->elementInfo
        ->getInfo('link');
    return $build;
}

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