Callback.php in Menu item content fields 8
File
src/Render/Callback.php
View source
<?php
namespace Drupal\menu_item_fields\Render;
use Drupal\Core\Security\TrustedCallbackInterface;
class Callback implements TrustedCallbackInterface {
public static function trustedCallbacks() {
return [
'preRenderMenuLinkContent',
];
}
public static function preRenderMenuLinkContent($element) {
if (!isset($element['link'])) {
return $element;
}
$contentLink =& $element['link'][0];
$contentUrl =& $contentLink['#url'];
$menuItemAttributes = $element['#menu_item']['url']
->getOption('attributes');
if (isset($menuItemAttributes['title'])) {
$contentLinkAttributes = $contentUrl
->getOption('attributes');
$contentLinkAttributes['title'] = $menuItemAttributes['title'];
$contentUrl
->setOption('attributes', $contentLinkAttributes);
}
$contentUrl
->setOption('set_active_class', $element['#menu_item']['url']
->getOption('set_active_class'));
if (is_string($contentLink['#title'])) {
$contentLink['#title'] = $element['#menu_item']['title'];
}
return $element;
}
}
Classes
Name |
Description |
Callback |
Provides a trusted callbacks to alter some elements markup. |