From 72b97ae36bd46ea2f0c1255cfb19041998478eed Mon Sep 17 00:00:00 2001 From: Jonathan Hedstrom Date: Wed, 24 May 2017 14:54:49 -0700 Subject: [PATCH] #92 - Keeping up with Flag API changes. --- config/optional/flag.flag.subscribe_node.yml | 1 - config/optional/flag.flag.subscribe_og.yml | 1 - .../config/optional/flag.flag.email_node.yml | 1 - src/Subscribers.php | 13 +++++++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/config/optional/flag.flag.subscribe_node.yml b/config/optional/flag.flag.subscribe_node.yml index 43f644e..b5ae151 100644 --- a/config/optional/flag.flag.subscribe_node.yml +++ b/config/optional/flag.flag.subscribe_node.yml @@ -24,7 +24,6 @@ flagTypeConfig: show_as_field: true show_on_form: false show_contextual_link: false - i18n: null extra_permissions: owner: '0' linkTypeConfig: { } diff --git a/config/optional/flag.flag.subscribe_og.yml b/config/optional/flag.flag.subscribe_og.yml index af11e32..3095387 100644 --- a/config/optional/flag.flag.subscribe_og.yml +++ b/config/optional/flag.flag.subscribe_og.yml @@ -25,6 +25,5 @@ flagTypeConfig: show_as_field: true show_on_form: false show_contextual_link: false - i18n: null extra_permissions: { } linkTypeConfig: { } diff --git a/message_subscribe_email/config/optional/flag.flag.email_node.yml b/message_subscribe_email/config/optional/flag.flag.email_node.yml index a96dd2c..16dcb72 100644 --- a/message_subscribe_email/config/optional/flag.flag.email_node.yml +++ b/message_subscribe_email/config/optional/flag.flag.email_node.yml @@ -25,7 +25,6 @@ flagTypeConfig: show_as_field: true show_on_form: false show_contextual_link: false - i18n: null extra_permissions: owner: '0' linkTypeConfig: { } diff --git a/src/Subscribers.php b/src/Subscribers.php index 287902a..904ec28 100644 --- a/src/Subscribers.php +++ b/src/Subscribers.php @@ -325,11 +325,16 @@ protected function isEntityOwner(EntityInterface $entity, $uid) { * {@inheritdoc} */ public function getFlags($entity_type = NULL, $bundle = NULL, AccountInterface $account = NULL) { + $flags = $this->flagService->getAllFlags($entity_type, $bundle); if ($account) { - $flags = $this->flagService->getUsersFlags($account, $entity_type, $bundle); - } - else { - $flags = $this->flagService->getAllFlags($entity_type, $bundle); + // Filter flags down to ones the account has action access for. + // @see https://www.drupal.org/node/2870375 + foreach ($flags as $flag_id => $flag) { + if (!$flag->actionAccess('flag', $account)->isAllowed() + && !$flag->actionAccess('unflag', $account)->isAllowed()) { + unset($flags[$flag_id]); + } + } } $ms_flags = []; $prefix = $this->config->get('flag_prefix') . '_';