MenuItemsLinkProvider.php in JSON:API Menu Items 1.1.x
File
src/Plugin/jsonapi_hypermedia/LinkProvider/MenuItemsLinkProvider.php
View source
<?php
namespace Drupal\jsonapi_menu_items\Plugin\jsonapi_hypermedia\LinkProvider;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\jsonapi\JsonApiResource\JsonApiDocumentTopLevel;
use Drupal\jsonapi_hypermedia\AccessRestrictedLink;
use Drupal\jsonapi_hypermedia\Plugin\LinkProviderBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class MenuItemsLinkProvider extends LinkProviderBase implements ContainerFactoryPluginInterface {
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition);
}
public function getLink($context) {
assert($context instanceof JsonApiDocumentTopLevel);
return AccessRestrictedLink::createLink(AccessResult::allowed(), new CacheableMetadata(), new Url('jsonapi_menu_items.menu', [
'menu' => $this->pluginDefinition['link_context']['menu_name'],
]), $this
->getLinkRelationType());
}
}