From ae69f9a0c9e8c38537d55d374d6208a530e05b5b Mon Sep 17 00:00:00 2001 From: Thomas Speer Date: Thu, 27 Oct 2016 17:35:30 +0200 Subject: [PATCH 1/6] Add Permission Checkst for Event,Topic,Group to Account Header Block (cherry picked from commit 22c74e8) --- .../src/Plugin/Block/AccountHeaderBlock.php | 131 ++++++++++-------- 1 file changed, 74 insertions(+), 57 deletions(-) diff --git a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php index 9e1d0ef8c0d..df85dbeb35d 100644 --- a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php +++ b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php @@ -15,66 +15,78 @@ */ class AccountHeaderBlock extends BlockBase { - /** - * {@inheritdoc} - */ - public function build() { - $account = \Drupal::currentUser(); - if ($account->id() !== 0) { - $account_name = $account->getAccountName(); - $account_uid = $account->id(); + /** + * {@inheritdoc} + */ + public function build() { + $account = \Drupal::currentUser(); + if ($account->id() !== 0) { + $account_name = $account->getAccountName(); + $account_uid = $account->id(); - $links = [ - 'add' => array( - 'classes' => 'dropdown', - 'link_attributes' => 'data-toggle=dropdown aria-expanded=true aria-haspopup=true role=button', - 'link_classes' => 'dropdown-toggle clearfix', - 'icon_classes' => 'icon-add_box', - 'title' => t('Add content'), - 'title_classes' => 'sr-only', - 'url' => '#', - 'below' => array( - 'add_event' => array( - 'classes' => '', - 'link_attributes' => '', - 'link_classes' => '', - 'icon_classes' => '', - 'icon_label' => '', - 'title' => t('New Event'), - 'title_classes' => '', - 'url' => Url::fromUserInput('/node/add/event'), - ), - 'add_topic' => array( - 'classes' => '', - 'link_attributes' => '', - 'link_classes' => '', - 'icon_classes' => '', - 'icon_label' => '', - 'title' => t('New Topic'), - 'title_classes' => '', - 'url' => Url::fromUserInput('/node/add/topic'), - ), - 'add_group' => array( - 'classes' => '', - 'link_attributes' => '', - 'link_classes' => '', - 'icon_classes' => '', - 'icon_label' => '', - 'title' => t('New Group'), - 'title_classes' => '', - 'url' => Url::fromUserInput('/group/add/open_group'), - ), - ), - ), - 'groups' => array( + $links = [ + 'add' => array( + 'classes' => 'dropdown', + 'link_attributes' => 'data-toggle=dropdown aria-expanded=true aria-haspopup=true role=button', + 'link_classes' => 'dropdown-toggle clearfix', + 'icon_classes' => 'icon-add_box', + 'title' => t('Add content'), + 'title_classes' => 'sr-only', + 'url' => '#', + 'below' => array(), + ), + 'groups' => array( + 'classes' => '', + 'link_attributes' => '', + 'icon_classes' => 'icon-group', + 'title' => t('My groups'), + 'title_classes' => 'sr-only', + 'url' => Url::fromUserInput('/user/' . $account_uid . '/groups'), + ), + ]; + + // Check is the User is allowd to create Events + if($account->hasPermission('create event content')){ + $links['add']['below']['add_event'] = array( + 'classes' => '', + 'link_attributes' => '', + 'link_classes' => '', + 'icon_classes' => '', + 'icon_label' => '', + 'title' => t('New Event'), + 'title_classes' => '', + 'url' => Url::fromUserInput('/node/add/event'), + ); + } + + // Check is the User is allowd to create Topics + if($account->hasPermission('create topic content')){ + $links['add']['below']['add_topic'] = array( 'classes' => '', 'link_attributes' => '', - 'icon_classes' => 'icon-group', - 'title' => t('My groups'), - 'title_classes' => 'sr-only', - 'url' => Url::fromUserInput('/user/' . $account_uid . '/groups'), - ), - ]; + 'link_classes' => '', + 'icon_classes' => '', + 'icon_label' => '', + 'title' => t('New Topic'), + 'title_classes' => '', + 'url' => Url::fromUserInput('/node/add/topic'), + ); + } + + + // Check if the user is allowed to create new Groups + if($account->hasPermission('create open_group group')){ + $links['add']['below']['add_group'] = array( + 'classes' => '', + 'link_attributes' => '', + 'link_classes' => '', + 'icon_classes' => '', + 'icon_label' => '', + 'title' => t('New Group'), + 'title_classes' => '', + 'url' => Url::fromUserInput('/group/add/open_group'), + ); + } // Check if the current user is allowed to create new books. if (\Drupal::moduleHandler()->moduleExists('social_book') && $account->hasPermission('create new books')) { @@ -104,6 +116,11 @@ public function build() { ); } + // Check if user cann add anything if nor remove add link + if(count($links['add']['below']) == 0){ + unset($links['add']); + } + if (\Drupal::moduleHandler()->moduleExists('activity_creator')) { $notifications_view = views_embed_view('activity_stream_notifications', 'block_1'); $notifications = \Drupal::service('renderer')->render($notifications_view); From 2854f07e69a3ce2571a9108a00e03ee7011257ad Mon Sep 17 00:00:00 2001 From: Thomas Speer Date: Mon, 16 Jan 2017 18:48:49 +0100 Subject: [PATCH 2/6] missed som attributes in merge... --- .../src/Plugin/Block/AccountHeaderBlock.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php index a0fa5b46b31..d9f397d3930 100644 --- a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php +++ b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php @@ -37,13 +37,15 @@ public function build() { 'below' => array(), ), 'groups' => array( - 'classes' => '', - 'link_attributes' => '', - 'icon_classes' => 'icon-group', - 'title' => $this->t('My Groups'), - 'label' => $this->t('My Groups'), - 'title_classes' => 'sr-only', - 'url' => Url::fromUserInput('/user/' . $account_uid . '/groups'), + 'classes' => '', + 'link_attributes' => '', + 'link_classes' => '', + 'icon_classes' => '', + 'icon_label' => '', + 'title' => $this->t('Create New Group'), + 'label' => $this->t('New group'), + 'title_classes' => '', + 'url' => Url::fromUserInput('/group/add/open_group'), ), ]; From 315756cf0c1b31cab6657de0e74e501abb9d1c98 Mon Sep 17 00:00:00 2001 From: Thomas Speer Date: Mon, 16 Jan 2017 18:51:14 +0100 Subject: [PATCH 3/6] fix typo --- .../social_user/src/Plugin/Block/AccountHeaderBlock.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php index d9f397d3930..fc40f1c5983 100644 --- a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php +++ b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php @@ -123,7 +123,7 @@ public function build() { ); } - // Check if user can add anything if nor remove add link + // Check if user can add anything if not remove add link if(count($links['add']['below']) == 0){ unset($links['add']); } From c1c625f5cfce0e184f9fca01acdb26f137cc722f Mon Sep 17 00:00:00 2001 From: Thomas Speer Date: Mon, 16 Jan 2017 19:00:23 +0100 Subject: [PATCH 4/6] indentation --- .../src/Plugin/Block/AccountHeaderBlock.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php index fc40f1c5983..2edb525859f 100644 --- a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php +++ b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php @@ -37,15 +37,15 @@ public function build() { 'below' => array(), ), 'groups' => array( - 'classes' => '', - 'link_attributes' => '', - 'link_classes' => '', - 'icon_classes' => '', - 'icon_label' => '', - 'title' => $this->t('Create New Group'), - 'label' => $this->t('New group'), - 'title_classes' => '', - 'url' => Url::fromUserInput('/group/add/open_group'), + 'classes' => '', + 'link_attributes' => '', + 'link_classes' => '', + 'icon_classes' => '', + 'icon_label' => '', + 'title' => $this->t('Create New Group'), + 'label' => $this->t('New group'), + 'title_classes' => '', + 'url' => Url::fromUserInput('/group/add/open_group'), ), ]; From f4bef2ff9001586cfd5619cab914d1b09cb15c99 Mon Sep 17 00:00:00 2001 From: Thomas Speer Date: Mon, 16 Jan 2017 19:05:28 +0100 Subject: [PATCH 5/6] copyed wrong block in commit 2854f07e --- .../src/Plugin/Block/AccountHeaderBlock.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php index 2edb525859f..7f519cf35bb 100644 --- a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php +++ b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php @@ -39,13 +39,11 @@ public function build() { 'groups' => array( 'classes' => '', 'link_attributes' => '', - 'link_classes' => '', - 'icon_classes' => '', - 'icon_label' => '', - 'title' => $this->t('Create New Group'), - 'label' => $this->t('New group'), - 'title_classes' => '', - 'url' => Url::fromUserInput('/group/add/open_group'), + 'icon_classes' => 'icon-group', + 'title' => $this->t('My Groups'), + 'label' => $this->t('My Groups'), + 'title_classes' => 'sr-only', + 'url' => Url::fromUserInput('/user/' . $account_uid . '/groups'), ), ]; From 442eccf150f9cf36003a309437e8c2eba989e893 Mon Sep 17 00:00:00 2001 From: Thomas Speer Date: Mon, 16 Jan 2017 19:11:17 +0100 Subject: [PATCH 6/6] typos in comments --- .../social_user/src/Plugin/Block/AccountHeaderBlock.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php index 7f519cf35bb..dfcf66f03d8 100644 --- a/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php +++ b/modules/social_features/social_user/src/Plugin/Block/AccountHeaderBlock.php @@ -47,7 +47,7 @@ public function build() { ), ]; - // Check is the User is allowd to create Events + // Check if the current user is allowed to create Events if($account->hasPermission('create event content')){ $links['add']['below']['add_event'] = array( 'classes' => '', @@ -62,7 +62,7 @@ public function build() { ); } - // Check is the User is allowd to create Topics + // Check if the current user is allowed to create Topics if($account->hasPermission('create topic content')){ $links['add']['below']['add_topic'] = array( 'classes' => '', @@ -78,7 +78,7 @@ public function build() { } - // Check if the user is allowed to create new Groups + // Check if the current user is allowed to create new Groups if($account->hasPermission('create open_group group')){ $links['add']['below']['add_group'] = array( 'classes' => '', @@ -121,7 +121,7 @@ public function build() { ); } - // Check if user can add anything if not remove add link + // Check if user can create anything of the above if not remove add link if(count($links['add']['below']) == 0){ unset($links['add']); }