Skip to content
Snippets Groups Projects
Commit efeb875e authored by mxh's avatar mxh
Browse files

Issue #3351331 by solene_ggd, mxh: Support for Contextual links

parent 154cca0c
No related branches found
No related tags found
1 merge request!13Draft: Issue #3447073 by yohansenso: Per-bundle view permissions are not checked for unpublished entities
......@@ -24,7 +24,7 @@ use Drupal\user\UserInterface;
* bundle_label = @Translation("Storage type"),
* handlers = {
* "storage" = "Drupal\storage\StorageStorage",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "view_builder" = "Drupal\storage\StorageViewBuilder",
* "list_builder" = "Drupal\storage\StorageListBuilder",
* "views_data" = "Drupal\storage\Entity\StorageViewsData",
* "translation" = "Drupal\storage\StorageTranslationHandler",
......
<?php
namespace Drupal\storage;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\storage\Entity\StorageInterface;
/**
* View builder handler for storage entities.
*/
class StorageViewBuilder extends EntityViewBuilder {
/**
* {@inheritdoc}
*/
protected function addContextualLinks(array &$build, EntityInterface $entity) {
if ($entity->isNew() || !($entity instanceof StorageInterface)) {
return;
}
$key = $entity->getEntityTypeId();
$rel = 'canonical';
if (!$entity->isDefaultRevision()) {
$rel = 'revision';
$key .= '_revision';
}
$build['#contextual_links'][$key] = [
'route_parameters' => [$key => $entity->id()],
'metadata' => ['changed' => $entity->getChangedTime()],
];
if ($entity->hasLinkTemplate($rel) && $entity->toUrl($rel)->isRouted()) {
$build['#contextual_links'][$key]['route_parameters'] = $entity->toUrl($rel)->getRouteParameters();
}
}
}
entity.storage.edit_form:
route_name: entity.storage.edit_form
group: storage
title: Edit
entity.storage.delete_form:
route_name: entity.storage.delete_form
group: storage
title: Delete
weight: 10
......@@ -9,6 +9,7 @@
* Available variables:
* - content: A list of content items. Use 'content' to print all content, or
* - attributes: HTML attributes for the container element.
* - title_suffix: Additional output populated by modules.
*
* @see template_preprocess_storage()
*
......@@ -16,6 +17,7 @@
*/
#}
<div{{ attributes.addClass('storage') }}>
{{ title_suffix }}
{% if content %}
{{- content -}}
{% endif %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment