class ShortcutLazyBuilders

Same name and namespace in other branches
  1. 9 core/modules/shortcut/src/ShortcutLazyBuilders.php \Drupal\shortcut\ShortcutLazyBuilders
  2. 8.9.x core/modules/shortcut/src/ShortcutLazyBuilders.php \Drupal\shortcut\ShortcutLazyBuilders
  3. 10 core/modules/shortcut/src/ShortcutLazyBuilders.php \Drupal\shortcut\ShortcutLazyBuilders

Lazy builders for the shortcut module.

Hierarchy

Expanded class hierarchy of ShortcutLazyBuilders

1 file declares its use of ShortcutLazyBuilders
ShortcutLazyBuilder.php in core/modules/navigation/src/ShortcutLazyBuilder.php
1 string reference to 'ShortcutLazyBuilders'
shortcut.services.yml in core/modules/shortcut/shortcut.services.yml
core/modules/shortcut/shortcut.services.yml
1 service uses ShortcutLazyBuilders
shortcut.lazy_builders in core/modules/shortcut/shortcut.services.yml
Drupal\shortcut\ShortcutLazyBuilders

File

core/modules/shortcut/src/ShortcutLazyBuilders.php, line 15

Namespace

Drupal\shortcut
View source
class ShortcutLazyBuilders implements TrustedCallbackInterface {
  use StringTranslationTrait;
  
  /**
   * The renderer service.
   *
   * @var \Drupal\Core\Render\RendererInterface
   */
  protected $renderer;
  
  /**
   * Constructs a new ShortcutLazyBuilders object.
   *
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer service.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
   *   The entity type manager.
   * @param \Drupal\Core\Session\AccountInterface $currentUser
   *   The current user.
   */
  public function __construct(RendererInterface $renderer, protected EntityTypeManagerInterface $entityTypeManager, protected AccountInterface $currentUser) {
    $this->renderer = $renderer;
  }
  
  /**
   * {@inheritdoc}
   */
  public static function trustedCallbacks() {
    return [
      'lazyLinks',
    ];
  }
  
  /**
   * Render API callback: Builds shortcut toolbar links.
   *
   * This function is assigned as a #lazy_builder callback.
   *
   * @param bool $show_configure_link
   *   Boolean to indicate whether to include the configure link or not.
   *
   * @return array
   *   A renderable array of shortcut links.
   */
  public function lazyLinks(bool $show_configure_link = TRUE) {
    $shortcut_set = $this->entityTypeManager
      ->getStorage('shortcut_set')
      ->getDisplayedToUser($this->currentUser);
    $links = shortcut_renderable_links();
    $configure_link = NULL;
    if ($show_configure_link && shortcut_set_edit_access($shortcut_set)->isAllowed()) {
      $configure_link = [
        '#type' => 'link',
        '#title' => $this->t('Edit shortcuts'),
        '#url' => Url::fromRoute('entity.shortcut_set.customize_form', [
          'shortcut_set' => $shortcut_set->id(),
        ]),
        '#options' => [
          'attributes' => [
            'class' => [
              'edit-shortcuts',
            ],
          ],
        ],
      ];
    }
    $build = [
      'shortcuts' => $links,
      'configure' => $configure_link,
    ];
    $this->renderer
      ->addCacheableDependency($build, $shortcut_set);
    return $build;
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ShortcutLazyBuilders::$renderer protected property The renderer service.
ShortcutLazyBuilders::lazyLinks public function Render API callback: Builds shortcut toolbar links.
ShortcutLazyBuilders::trustedCallbacks public static function Overrides TrustedCallbackInterface::trustedCallbacks
ShortcutLazyBuilders::__construct public function Constructs a new ShortcutLazyBuilders object.
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language. 1
TrustedCallbackInterface::THROW_EXCEPTION constant Untrusted callbacks throw exceptions.
TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION constant Untrusted callbacks trigger silenced E_USER_DEPRECATION errors.

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