From dcda82925f90b344381ba3137ab1577baed635e8 Mon Sep 17 00:00:00 2001 From: sagesolutions <mike@sagesolutionsinc.ca> Date: Tue, 9 May 2023 14:37:16 +0000 Subject: [PATCH] added check if user is in route --- config/install/views.view.user_personal_notes.yml | 2 +- src/Plugin/Block/PersonalNotesBlock.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/install/views.view.user_personal_notes.yml b/config/install/views.view.user_personal_notes.yml index 3ac9649..81472ed 100644 --- a/config/install/views.view.user_personal_notes.yml +++ b/config/install/views.view.user_personal_notes.yml @@ -200,7 +200,7 @@ display: group_type: group admin_label: '' plugin_id: text_custom - empty: false + empty: true content: '<a href="/user/{{ arguments.user }}/add-note" class="button button--action button--primary">Add Note</a>' tokenize: true footer: { } diff --git a/src/Plugin/Block/PersonalNotesBlock.php b/src/Plugin/Block/PersonalNotesBlock.php index 471bbbd..25e94ef 100644 --- a/src/Plugin/Block/PersonalNotesBlock.php +++ b/src/Plugin/Block/PersonalNotesBlock.php @@ -8,6 +8,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\personal_notes\Entity\PersonalNote; +use Drupal\user\UserInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -79,7 +80,7 @@ class PersonalNotesBlock extends BlockBase implements ContainerFactoryPluginInte */ public function build(): array { // User must be logged on to have personal notes. - if (!$this->currentUser->isAnonymous()) { + if (!$this->currentUser->isAnonymous() && $this->routeMatch->getParameter('user') instanceof UserInterface) { $user = $this->routeMatch->getParameter('user'); -- GitLab