class LazyBuilders

Same name and namespace in other branches
  1. 11.x core/modules/announcements_feed/src/LazyBuilders.php \Drupal\announcements_feed\LazyBuilders

Defines a class for lazy building render arrays.

@internal

Hierarchy

Expanded class hierarchy of LazyBuilders

1 string reference to 'LazyBuilders'
announcements_feed.services.yml in core/modules/announcements_feed/announcements_feed.services.yml
core/modules/announcements_feed/announcements_feed.services.yml
1 service uses LazyBuilders
announcements_feed.lazy_builders in core/modules/announcements_feed/announcements_feed.services.yml
Drupal\announcements_feed\LazyBuilders

File

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

Namespace

Drupal\announcements_feed
View source
final class LazyBuilders implements TrustedCallbackInterface {
  
  /**
   * Constructs LazyBuilders object.
   *
   * @param \Drupal\Core\Render\ElementInfoManagerInterface $elementInfo
   *   Element info.
   */
  public function __construct(protected ElementInfoManagerInterface $elementInfo) {
  }
  
  /**
   * Render announcements.
   *
   * @return array
   *   Render array.
   */
  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;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() : array {
    return [
      'renderAnnouncements',
    ];
  }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title
LazyBuilders::renderAnnouncements public function Render announcements.
LazyBuilders::trustedCallbacks public static function Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface::trustedCallbacks
LazyBuilders::__construct public function Constructs LazyBuilders object.
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.
TrustedCallbackInterface::TRIGGER_WARNING Deprecated constant Untrusted callbacks trigger E_USER_WARNING errors.

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