ShortcutLazyBuilders.php in Drupal 9
File
core/modules/shortcut/src/ShortcutLazyBuilders.php
View source
<?php
namespace Drupal\shortcut;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Url;
class ShortcutLazyBuilders implements TrustedCallbackInterface {
protected $renderer;
public function __construct(RendererInterface $renderer) {
$this->renderer = $renderer;
}
public static function trustedCallbacks() {
return [
'lazyLinks',
];
}
public function lazyLinks() {
$shortcut_set = shortcut_current_displayed_set();
$links = shortcut_renderable_links();
$configure_link = NULL;
if (shortcut_set_edit_access($shortcut_set)
->isAllowed()) {
$configure_link = [
'#type' => 'link',
'#title' => 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;
}
}