From 0861e3d8ab3bdcf7221baed7a3f4e404425ab36a Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen.haas@lakedrops.com> Date: Thu, 27 Jul 2023 13:55:19 +0200 Subject: [PATCH] Update patch for gin_toolbar --- patches/d10.json | 2 +- patches/d9.json | 2 +- patches/gin_toolbar-permissions.patch | 41 +++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 patches/gin_toolbar-permissions.patch diff --git a/patches/d10.json b/patches/d10.json index 5243f65..86580d8 100644 --- a/patches/d10.json +++ b/patches/d10.json @@ -130,7 +130,7 @@ "#3355054 Default value for empty actions": "https://git.drupalcode.org/project/gin/-/merge_requests/246.diff" }, "drupal/gin_toolbar": { - "#3319445 Permission check": "https://git.drupalcode.org/project/gin_toolbar/-/merge_requests/30.diff" + "#3319445 Permission check": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/gin_toolbar-permissions.patch" }, "drupal/glossify": { "#3338553 PHP 8.1": "https://git.drupalcode.org/project/glossify/-/merge_requests/10.diff", diff --git a/patches/d9.json b/patches/d9.json index 217c0e2..416a70d 100644 --- a/patches/d9.json +++ b/patches/d9.json @@ -134,7 +134,7 @@ "#3355054 Default value for empty actions": "https://git.drupalcode.org/project/gin/-/merge_requests/246.diff" }, "drupal/gin_toolbar": { - "#3319445 Permission check": "https://git.drupalcode.org/project/gin_toolbar/-/merge_requests/30.diff" + "#3319445 Permission check": "https://gitlab.lakedrops.com/composer/plugin/drupal-environment/-/raw/main/patches/gin_toolbar-permissions.patch" }, "drupal/glossify": { "#3338553 PHP 8.1": "https://git.drupalcode.org/project/glossify/-/merge_requests/10.diff", diff --git a/patches/gin_toolbar-permissions.patch b/patches/gin_toolbar-permissions.patch new file mode 100644 index 0000000..16dff66 --- /dev/null +++ b/patches/gin_toolbar-permissions.patch @@ -0,0 +1,41 @@ +diff --git a/gin_toolbar.module b/gin_toolbar.module +index 02bfce3568b53852a49092f0d6a6b3db89216a9d..1ced229a9910d12d0243ebd465f576e6c78361cf 100644 +--- a/gin_toolbar.module ++++ b/gin_toolbar.module +@@ -8,6 +8,7 @@ + use Drupal\Component\Utility\Html; + use Drupal\Core\Entity\EntityInterface; + use Drupal\Core\Routing\RouteMatchInterface; ++use Drupal\Core\Url; + use Drupal\gin_toolbar\Render\Element\GinToolbar; + use Drupal\gin\GinSettings; + use Drupal\gin\GinUserPicture; +@@ -194,8 +195,13 @@ function gin_toolbar_preprocess_toolbar(&$variables) { + $entity = \Drupal::request()->attributes->get($matches['entity_type_id']); + + if ($entity instanceof EntityInterface && $entity->hasLinkTemplate('edit-form')) { +- $variables['entity_title'] = $entity->label(); +- $variables['entity_edit_url'] = $entity->toUrl('edit-form'); ++ if ($entity->access('update')) { ++ $variables['entity_title'] = $entity->label(); ++ $variables['entity_edit_url'] = $entity->toUrl('edit-form'); ++ } ++ elseif (Url::fromRoute('system.admin_content')->access(\Drupal::currentUser())) { ++ $variables['access_admin_content'] = TRUE; ++ } + } + } + } +diff --git a/templates/toolbar.html.twig b/templates/toolbar.html.twig +index e82bc1ceae19f14a3a7109a8d433e78dbf0d5ef3..5380e54f1899ef763f3036edef08f91e5b5d0a88 100644 +--- a/templates/toolbar.html.twig ++++ b/templates/toolbar.html.twig +@@ -16,7 +16,7 @@ + <li class="gin-breadcrumb__item"> + {% if entity_edit_url and entity_title %} + <a class="gin-breadcrumb__link gin-back-to-admin" href="{{ entity_edit_url }}">{{ 'Edit %title'|t({ '%title': entity_title }) }}</a> +- {% else %} ++ {% elseif access_admin_content %} + <a class="gin-breadcrumb__link gin-back-to-admin" href="{{ path('system.admin_content') }}">{{ 'Back to Administration'|t }}</a> + {% endif %} + </li> -- GitLab