From 6e19874e97741305ecf6c60fef3a3a3f109ca25c Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 13 May 2016 18:06:56 +0300 Subject: [PATCH 01/88] Start implementing the roles overview. --- og_ui/og_ui.routing.yml | 2 +- og_ui/src/Form/OgRolesForm.php | 152 +++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 og_ui/src/Form/OgRolesForm.php diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 04c448b52..a47e6e46d 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -29,7 +29,7 @@ og_ui.roles_form: path: 'admin/config/group/roles/{entity_type}/{bundle}' defaults: _form: '\Drupal\og_ui\Form\OgRolesForm' - _title: '@todo - create title callback' + _title_callback: '\Drupal\og_ui\Form\OgRolesForm::titleCallback' requirements: _permission: 'administer group' diff --git a/og_ui/src/Form/OgRolesForm.php b/og_ui/src/Form/OgRolesForm.php new file mode 100644 index 000000000..29d0becc8 --- /dev/null +++ b/og_ui/src/Form/OgRolesForm.php @@ -0,0 +1,152 @@ +groupManager = $group_manager; + $this->entityTypeManager = $entity_type_manager; + $this->entityTypeBundleInfo = $entity_type_bundle_info; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('og.group.manager'), + $container->get('entity_type.manager'), + $container->get('entity_type.bundle.info') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'og_ui_roles_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { + $header = [t('Role name'), t('Operations')]; + $rows = []; + $properties = [ + 'group_type' => $entity_type, + 'group_bundle' => $bundle, + ]; + /** @var \Drupal\og\Entity\OgRole $role */ + foreach ($this->entityTypeManager->getStorage('og_role')->loadByProperties($properties) as $role) { + $rows[] = [ + [ + 'data' => $role->getLabel(), + ], + [ + 'data' => [ + // @todo Don't use a dropbutton, this doesn't work well with the + // locked fields. + '#type' => 'dropbutton', + '#links' => [ + 'simple_form' => [ + 'title' => $this->t('Edit role'), + // @todo update route. + 'url' => Url::fromRoute('og_ui.roles_form', [ + 'entity_type' => $entity_type, + 'bundle' => $bundle, + ]), + ], + 'demo' => [ + 'title' => $this->t('Edit permissions'), + // @todo update route. + 'url' => Url::fromRoute('og_ui.roles_form', [ + 'entity_type' => $entity_type, + 'bundle' => $bundle, + ]), + ], + ], + ], + ], + ]; + } + + $form['roles_table'] = [ + '#theme' => 'table', + '#header' => $header, + '#rows' => $rows, + '#empty' => $this->t('No roles available.'), + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + throw new \Exception('Implement ' . __METHOD__); + } + + /** + * Title callback for the form. + * + * @param string $entity_type + * The group entity type. + * @param string $bundle + * The group bundle. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + */ + public function titleCallback($entity_type, $bundle) { + return $this->t('OG @type - @bundle roles', [ + '@type' => $this->entityTypeManager->getDefinition($entity_type)->getLabel(), + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], + ]); + } + +} From 12515383a5e872f3d6a2440f3cb525ed07166e5a Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 10:10:14 +0300 Subject: [PATCH 02/88] Add provisionary routes for the roles and permissions edit forms so we can link to them. --- og_ui/og_ui.routing.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index a47e6e46d..4c2daf37c 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -33,6 +33,14 @@ og_ui.roles_form: requirements: _permission: 'administer group' +og_ui.roles_edit_form: + path: 'admin/config/group/role/{og_role}/edit' + defaults: + _form: '\Drupal\og_ui\Form\OgRolesEditForm' + _title_callback: '\Drupal\og_ui\Form\OgRolesEditForm::titleCallback' + requirements: + _permission: 'administer group' + og_ui.permissions_form: path: 'admin/config/group/permissions/{entity_type}/{bundle}' defaults: @@ -40,3 +48,11 @@ og_ui.permissions_form: _title: '@todo - create title callback' requirements: _permission: 'administer group' + +og_ui.permissions_edit_form: + path: 'admin/config/group/permission/{og_role}/edit' + defaults: + _form: '\Drupal\og_ui\Form\OgPermissionsEditForm' + _title_callback: '\Drupal\og_ui\Form\OgPermissionsEditForm::titleCallback' + requirements: + _permission: 'administer group' From 0896bee62a18b42c0fb1c8f26e75f5e36ff0c073 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 10:10:50 +0300 Subject: [PATCH 03/88] Add a method to determine whether a role is mutable. --- src/Entity/OgRole.php | 7 +++++++ src/OgRoleInterface.php | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 669705a03..55f0d8cc1 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -159,6 +159,13 @@ public function setName($name) { return $this; } + /** + * {@inheritdoc} + */ + public function isMutable() { + return $this->get('role_type') === OgRoleInterface::ROLE_TYPE_STANDARD; + } + /** * {@inheritdoc} */ diff --git a/src/OgRoleInterface.php b/src/OgRoleInterface.php index 210e5b0ff..947b2100f 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -196,4 +196,15 @@ public static function getRole($entity_type_id, $bundle, $role_name); */ public function isRequired(); + /** + * Returns whether or not a role can be changed. + * + * This will return TRUE for all roles except the default roles 'non-member' + * and 'member'. + * + * @return bool + * Whether or not the role is mutable. + */ + public function isMutable(); + } From da38761a9ffdc59c4bae2c6e55267daa50988f6e Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 10:11:30 +0300 Subject: [PATCH 04/88] Show the links for editing roles and permissions in the table. --- og_ui/src/Form/OgRolesForm.php | 54 +++++++++++++++------------------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/og_ui/src/Form/OgRolesForm.php b/og_ui/src/Form/OgRolesForm.php index 29d0becc8..9b43abbec 100644 --- a/og_ui/src/Form/OgRolesForm.php +++ b/og_ui/src/Form/OgRolesForm.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\og\GroupManager; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -75,7 +76,7 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { - $header = [t('Role name'), t('Operations')]; + $header = [t('Role name'), ['data' => t('Operations'), 'colspan' => 2]]; $rows = []; $properties = [ 'group_type' => $entity_type, @@ -83,36 +84,29 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t ]; /** @var \Drupal\og\Entity\OgRole $role */ foreach ($this->entityTypeManager->getStorage('og_role')->loadByProperties($properties) as $role) { - $rows[] = [ - [ - 'data' => $role->getLabel(), - ], - [ - 'data' => [ - // @todo Don't use a dropbutton, this doesn't work well with the - // locked fields. - '#type' => 'dropbutton', - '#links' => [ - 'simple_form' => [ - 'title' => $this->t('Edit role'), - // @todo update route. - 'url' => Url::fromRoute('og_ui.roles_form', [ - 'entity_type' => $entity_type, - 'bundle' => $bundle, - ]), - ], - 'demo' => [ - 'title' => $this->t('Edit permissions'), - // @todo update route. - 'url' => Url::fromRoute('og_ui.roles_form', [ - 'entity_type' => $entity_type, - 'bundle' => $bundle, - ]), - ], - ], - ], - ], + // Add the role name cell. + $columns = [['data' => $role->getLabel()]]; + + // Add the edit role link if the role is editable. + if ($role->isMutable()) { + $columns[] = [ + 'data' => Link::createFromRoute(t('Edit role'), 'og_ui.roles_edit_form', [ + 'og_role' => $role->id(), + ]), + ]; + } + else { + $columns[] = ['data' => t('Locked')]; + } + + // Add the edit permissions link. + $columns[] = [ + 'data' => Link::createFromRoute(t('Edit permissions'), 'og_ui.permissions_edit_form', [ + 'og_role' => $role->id(), + ]), ]; + + $rows[] = $columns; } $form['roles_table'] = [ From a798f5bba30a2b707fd7683edcae4b634e9930c7 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 16:04:42 +0300 Subject: [PATCH 05/88] Turn the roles overview from a form into a controller. --- og_ui/og_ui.routing.yml | 14 +-- og_ui/src/Controller/OgUiController.php | 75 +++++++++++- og_ui/src/Form/OgRolesForm.php | 146 ------------------------ 3 files changed, 81 insertions(+), 154 deletions(-) delete mode 100644 og_ui/src/Form/OgRolesForm.php diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 4c2daf37c..9e084d7d1 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -25,23 +25,23 @@ og_ui.roles_permissions_overview: _permission: 'administer group' type: '^(roles|permissions)$' -og_ui.roles_form: +og_ui.roles_overview: path: 'admin/config/group/roles/{entity_type}/{bundle}' defaults: - _form: '\Drupal\og_ui\Form\OgRolesForm' - _title_callback: '\Drupal\og_ui\Form\OgRolesForm::titleCallback' + _controller: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPage' + _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' requirements: _permission: 'administer group' -og_ui.roles_edit_form: +og_ui.role_edit_form: path: 'admin/config/group/role/{og_role}/edit' defaults: - _form: '\Drupal\og_ui\Form\OgRolesEditForm' - _title_callback: '\Drupal\og_ui\Form\OgRolesEditForm::titleCallback' + _form: '\Drupal\og_ui\Form\OgRoleEditForm' + _title_callback: '\Drupal\og_ui\Form\OgRoleEditForm::titleCallback' requirements: _permission: 'administer group' -og_ui.permissions_form: +og_ui.permissions_overview: path: 'admin/config/group/permissions/{entity_type}/{bundle}' defaults: _form: '\Drupal\og_ui\Form\OgPermissionsForm' diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index f9bf4a0b3..92a208806 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -86,7 +86,7 @@ public function rolesPermissionsOverviewPage($type) { 'data' => $definition->getLabel() . ' - ' . $bundle_info[$bundle]['label'], ], [ - 'data' => Link::createFromRoute($action, 'og_ui.' . $type . '_form', [ + 'data' => Link::createFromRoute($action, 'og_ui.' . $type . '_overview', [ 'entity_type' => $entity_type, 'bundle' => $bundle, ]), @@ -118,4 +118,77 @@ public function rolesPermissionsOverviewTitleCallback($type) { return $this->t('OG @type overview', ['@type' => $type]); } + /** + * Returns the OG role overview page for a given entity type and bundle. + * + * @param string $entity_type + * The entity type for which to show the OG roles. + * @param string $bundle + * The bundle for which to show the OG roles. + * + * @return array + * The overview as a render array. + */ + public function rolesOverviewPage($entity_type = '', $bundle = '') { + $rows = []; + + $properties = [ + 'group_type' => $entity_type, + 'group_bundle' => $bundle, + ]; + /** @var \Drupal\og\Entity\OgRole $role */ + foreach ($this->entityTypeManager->getStorage('og_role')->loadByProperties($properties) as $role) { + // Add the role name cell. + $columns = [['data' => $role->getLabel()]]; + + // Add the edit role link if the role is editable. + if ($role->isMutable()) { + $columns[] = [ + 'data' => Link::createFromRoute($this->t('Edit role'), 'og_ui.role_edit_form', [ + 'og_role' => $role->id(), + ]), + ]; + } + else { + $columns[] = ['data' => $this->t('Locked')]; + } + + // Add the edit permissions link. + $columns[] = [ + 'data' => Link::createFromRoute($this->t('Edit permissions'), 'og_ui.permissions_edit_form', [ + 'og_role' => $role->id(), + ]), + ]; + + $rows[] = $columns; + } + + return [ + '#theme' => 'table', + '#header' => [ + $this->t('Role name'), + ['data' => $this->t('Operations'), 'colspan' => 2], + ], + '#rows' => $rows, + '#empty' => $this->t('No roles available.'), + ]; + } + + /** + * Title callback for the roles overview page. + * + * @param string $entity_type + * The group entity type. + * @param string $bundle + * The group bundle. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + */ + public function rolesOverviewPageTitleCallback($entity_type, $bundle) { + return $this->t('OG @type - @bundle roles', [ + '@type' => $this->entityTypeManager->getDefinition($entity_type)->getLabel(), + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], + ]); + } + } diff --git a/og_ui/src/Form/OgRolesForm.php b/og_ui/src/Form/OgRolesForm.php deleted file mode 100644 index 9b43abbec..000000000 --- a/og_ui/src/Form/OgRolesForm.php +++ /dev/null @@ -1,146 +0,0 @@ -groupManager = $group_manager; - $this->entityTypeManager = $entity_type_manager; - $this->entityTypeBundleInfo = $entity_type_bundle_info; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('og.group.manager'), - $container->get('entity_type.manager'), - $container->get('entity_type.bundle.info') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'og_ui_roles_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { - $header = [t('Role name'), ['data' => t('Operations'), 'colspan' => 2]]; - $rows = []; - $properties = [ - 'group_type' => $entity_type, - 'group_bundle' => $bundle, - ]; - /** @var \Drupal\og\Entity\OgRole $role */ - foreach ($this->entityTypeManager->getStorage('og_role')->loadByProperties($properties) as $role) { - // Add the role name cell. - $columns = [['data' => $role->getLabel()]]; - - // Add the edit role link if the role is editable. - if ($role->isMutable()) { - $columns[] = [ - 'data' => Link::createFromRoute(t('Edit role'), 'og_ui.roles_edit_form', [ - 'og_role' => $role->id(), - ]), - ]; - } - else { - $columns[] = ['data' => t('Locked')]; - } - - // Add the edit permissions link. - $columns[] = [ - 'data' => Link::createFromRoute(t('Edit permissions'), 'og_ui.permissions_edit_form', [ - 'og_role' => $role->id(), - ]), - ]; - - $rows[] = $columns; - } - - $form['roles_table'] = [ - '#theme' => 'table', - '#header' => $header, - '#rows' => $rows, - '#empty' => $this->t('No roles available.'), - ]; - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - throw new \Exception('Implement ' . __METHOD__); - } - - /** - * Title callback for the form. - * - * @param string $entity_type - * The group entity type. - * @param string $bundle - * The group bundle. - * - * @return \Drupal\Core\StringTranslation\TranslatableMarkup - */ - public function titleCallback($entity_type, $bundle) { - return $this->t('OG @type - @bundle roles', [ - '@type' => $this->entityTypeManager->getDefinition($entity_type)->getLabel(), - '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], - ]); - } - -} From 142fe56be3184d6d4883fd8049462f0c0c83982b Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 16:06:23 +0300 Subject: [PATCH 06/88] Provide a local action to add a role. --- og_ui/og_ui.links.action.yml | 5 +++++ og_ui/og_ui.routing.yml | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 og_ui/og_ui.links.action.yml diff --git a/og_ui/og_ui.links.action.yml b/og_ui/og_ui.links.action.yml new file mode 100644 index 000000000..d08588ae0 --- /dev/null +++ b/og_ui/og_ui.links.action.yml @@ -0,0 +1,5 @@ +og_ui.role_add: + route_name: og_ui.role_add_form + title: 'Add role' + appears_on: + - og_ui.roles_overview diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 9e084d7d1..69581d72a 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -33,6 +33,14 @@ og_ui.roles_overview: requirements: _permission: 'administer group' +og_ui.role_add_form: + path: 'admin/config/group/role/{entity_type}/{bundle}/add' + defaults: + _form: '\Drupal\og_ui\Form\OgRoleAddForm' + _title_callback: '\Drupal\og_ui\Form\OgRoleAddForm::titleCallback' + requirements: + _permission: 'administer group' + og_ui.role_edit_form: path: 'admin/config/group/role/{og_role}/edit' defaults: From a1777f65bfdf51845594d0a05924fff7bdf183c7 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 16:06:47 +0300 Subject: [PATCH 07/88] Return a 404 on the group role overview when the entity is not a group. --- og_ui/src/Controller/OgUiController.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 92a208806..458ae8c77 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -7,7 +7,9 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; use Drupal\og\GroupTypeManagerInterface; +use Drupal\og\Og; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * The OG UI controller. @@ -130,6 +132,11 @@ public function rolesPermissionsOverviewTitleCallback($type) { * The overview as a render array. */ public function rolesOverviewPage($entity_type = '', $bundle = '') { + // Return a 404 error when this is not a group. + if (!Og::isGroup($entity_type, $bundle)) { + throw new NotFoundHttpException(); + } + $rows = []; $properties = [ From 397ecf4c5f738ab3bc5f640c1d7c98094746e54c Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 09:13:06 +0200 Subject: [PATCH 08/88] Add a skeleton for the roles form. --- og_ui/src/Form/OgRolesForm.php | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 og_ui/src/Form/OgRolesForm.php diff --git a/og_ui/src/Form/OgRolesForm.php b/og_ui/src/Form/OgRolesForm.php new file mode 100644 index 000000000..f864f5c0a --- /dev/null +++ b/og_ui/src/Form/OgRolesForm.php @@ -0,0 +1,51 @@ +ogRoleStorage = $og_role_storage; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ + $entity_type_manager = $container->get('entity_type.manager'); + return new static( + $entity_type_manager->getStorage('og_role') + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'og_ui_roles_form'; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state, $entity_type = NULL, $bundle = NULL) { + // Retrieve a list of all roles for this bundle. + $roles = $this->ogRoleStorage->loadByProperties(['group_type' => $entity_type, 'group_bundle' => $bundle]); + $args = func_get_args(); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + // TODO: Implement submitForm() method. + } + +} From 46bd056ea786af6a0e362b5920d63bc1419f54c3 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 10:53:48 +0200 Subject: [PATCH 09/88] Change the method from isMutable() to isLocked() so it matches what is shown in the UI. --- src/Entity/OgRole.php | 4 ++-- src/OgRoleInterface.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 55f0d8cc1..80c63b805 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -162,8 +162,8 @@ public function setName($name) { /** * {@inheritdoc} */ - public function isMutable() { - return $this->get('role_type') === OgRoleInterface::ROLE_TYPE_STANDARD; + public function isLocked() { + return $this->get('role_type') !== OgRoleInterface::ROLE_TYPE_STANDARD; } /** diff --git a/src/OgRoleInterface.php b/src/OgRoleInterface.php index 947b2100f..cb09fc07b 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -199,12 +199,12 @@ public function isRequired(); /** * Returns whether or not a role can be changed. * - * This will return TRUE for all roles except the default roles 'non-member' + * This will return FALSE for all roles except the default roles 'non-member' * and 'member'. * * @return bool - * Whether or not the role is mutable. + * Whether or not the role is locked. */ - public function isMutable(); + public function isLocked(); } From 23a465e94230dc5097b03ec769a6a2b8e2f2731e Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 11:44:57 +0200 Subject: [PATCH 10/88] Update documentation. --- og_ui/src/Controller/OgUiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 458ae8c77..927c0b8d7 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -108,7 +108,7 @@ public function rolesPermissionsOverviewPage($type) { } /** - * Title callback for rolesPermissionsOverviewPage. + * Title callback for rolesPermissionsOverviewPage(). * * @param string $type * The type of overview, either 'roles' or 'permissions'. From 5c6411f1aab156816ede9e7e3dc749014c25604e Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 11:45:39 +0200 Subject: [PATCH 11/88] Revert "Add a skeleton for the roles form." This reverts commit be6b209016aa0f2364be067509ebd0801741ca80. --- og_ui/src/Form/OgRolesForm.php | 51 ---------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 og_ui/src/Form/OgRolesForm.php diff --git a/og_ui/src/Form/OgRolesForm.php b/og_ui/src/Form/OgRolesForm.php deleted file mode 100644 index f864f5c0a..000000000 --- a/og_ui/src/Form/OgRolesForm.php +++ /dev/null @@ -1,51 +0,0 @@ -ogRoleStorage = $og_role_storage; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ - $entity_type_manager = $container->get('entity_type.manager'); - return new static( - $entity_type_manager->getStorage('og_role') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'og_ui_roles_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type = NULL, $bundle = NULL) { - // Retrieve a list of all roles for this bundle. - $roles = $this->ogRoleStorage->loadByProperties(['group_type' => $entity_type, 'group_bundle' => $bundle]); - $args = func_get_args(); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - // TODO: Implement submitForm() method. - } - -} From 8cae14b696b4695a92ce8726e1d0c98f2f34f035 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 11:40:58 +0200 Subject: [PATCH 12/88] isMutable() has been inverted and is now called isLocked(). --- og_ui/src/Controller/OgUiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 927c0b8d7..b7eff6908 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -149,7 +149,7 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { $columns = [['data' => $role->getLabel()]]; // Add the edit role link if the role is editable. - if ($role->isMutable()) { + if (!$role->isLocked()) { $columns[] = [ 'data' => Link::createFromRoute($this->t('Edit role'), 'og_ui.role_edit_form', [ 'og_role' => $role->id(), From 1bd2e7198066bd080154bcaad80eeec4cd3e3be8 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 11:41:43 +0200 Subject: [PATCH 13/88] Add links to the OG Role entity declaration. --- src/Entity/OgRole.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 80c63b805..58f1eb254 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -22,6 +22,12 @@ * "label" = "label", * "weight" = "weight" * }, + * links = { + * "delete-form" = "/admin/config/group/role/{og_role}/delete", + * "edit-form" = "/admin/config/group/role/{og_role}/edit", + * "edit-permissions-form" = "/admin/config/group/permission/{og_role}/edit", + * "collection" = "/admin/config/group/roles", + * }, * config_export = { * "id", * "label", From dc9291366cf7266dc534158c8efd316572c50aa8 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 14:15:55 +0200 Subject: [PATCH 14/88] Implement the role add/edit form. --- og_ui/og_ui.routing.yml | 6 ++- og_ui/src/Form/OgRoleForm.php | 81 +++++++++++++++++++++++++++++++++++ src/Entity/OgRole.php | 6 +++ 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 og_ui/src/Form/OgRoleForm.php diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 69581d72a..d541256f5 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -44,9 +44,11 @@ og_ui.role_add_form: og_ui.role_edit_form: path: 'admin/config/group/role/{og_role}/edit' defaults: - _form: '\Drupal\og_ui\Form\OgRoleEditForm' - _title_callback: '\Drupal\og_ui\Form\OgRoleEditForm::titleCallback' + _entity_form: og_role.default + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' requirements: + # Todo: This should become a dedicated permission: + # _entity_access: og_role.update _permission: 'administer group' og_ui.permissions_overview: diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php new file mode 100644 index 000000000..736504718 --- /dev/null +++ b/og_ui/src/Form/OgRoleForm.php @@ -0,0 +1,81 @@ +entity; + $form['label'] = [ + '#type' => 'textfield', + '#title' => $this->t('Role name'), + '#default_value' => $entity->label(), + '#size' => 30, + '#required' => TRUE, + '#maxlength' => 64, + '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), + ]; + + return parent::form($form, $form_state, $entity); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $entity = $this->entity; + + // Prevent leading and trailing spaces in role names. + $entity->set('label', trim($entity->label())); + $status = $entity->save(); + + $edit_link = $this->entity->link($this->t('Edit')); + if ($status == SAVED_UPDATED) { + drupal_set_message($this->t('OG role %label has been updated.', ['%label' => $entity->label()])); + $this->logger('user')->notice('OG role %label has been updated.', ['%label' => $entity->label(), 'link' => $edit_link]); + } + else { + drupal_set_message($this->t('OG role %label has been added.', ['%label' => $entity->label()])); + $this->logger('user')->notice('OG role %label has been added.', ['%label' => $entity->label(), 'link' => $edit_link]); + } + $form_state->setRedirect('og_ui.roles_overview', [ + 'entity_type' => $entity->getEntityTypeId(), + 'bundle' => $entity->bundle(), + ]); + } + + /** + * Title callback for the edit form for an OG role. + * + * @param \Drupal\og\Entity\OgRole $og_role + * The OG role being edited. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * An object that, when cast to a string, returns the translated title + * callback. + */ + public function editRoleTitleCallback(OgRole $og_role) { + return $this->t('Edit OG role %label', [ + '%label' => $og_role->getLabel(), + ]); + } + +} diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 58f1eb254..f100e0487 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -16,6 +16,12 @@ * @ConfigEntityType( * id = "og_role", * label = @Translation("OG role"), + * handlers = { + * "form" = { + * "default" = "Drupal\og_ui\Form\OgRoleForm", + * "delete" = "Drupal\Core\Entity\EntityDeleteForm" + * } + * }, * static_cache = TRUE, * entity_keys = { * "id" = "id", From 2cc8a37be0fd2090a79bb7df9fa8e765f2d12ee1 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 14:31:59 +0200 Subject: [PATCH 15/88] Use the correct naming scheme for entity forms. --- og_ui/og_ui.routing.yml | 2 +- og_ui/src/Controller/OgUiController.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index d541256f5..4861c8b64 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -41,7 +41,7 @@ og_ui.role_add_form: requirements: _permission: 'administer group' -og_ui.role_edit_form: +entity.og_role.edit_form: path: 'admin/config/group/role/{og_role}/edit' defaults: _entity_form: og_role.default diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index b7eff6908..797bc62c9 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -151,7 +151,7 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { // Add the edit role link if the role is editable. if (!$role->isLocked()) { $columns[] = [ - 'data' => Link::createFromRoute($this->t('Edit role'), 'og_ui.role_edit_form', [ + 'data' => Link::createFromRoute($this->t('Edit role'), 'entity.og_role.edit_form', [ 'og_role' => $role->id(), ]), ]; From 8d57411869b27f5d655f281e386f744eaa5955fb Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 14:32:23 +0200 Subject: [PATCH 16/88] Fix redirect link to role overview after editing a role. --- og_ui/src/Form/OgRoleForm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 736504718..89b181e03 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -57,8 +57,8 @@ public function save(array $form, FormStateInterface $form_state) { $this->logger('user')->notice('OG role %label has been added.', ['%label' => $entity->label(), 'link' => $edit_link]); } $form_state->setRedirect('og_ui.roles_overview', [ - 'entity_type' => $entity->getEntityTypeId(), - 'bundle' => $entity->bundle(), + 'entity_type' => $entity->getGroupType(), + 'bundle' => $entity->getGroupBundle(), ]); } From e389af6025aba64669b3a2284279ba129f3ebdbe Mon Sep 17 00:00:00 2001 From: Archie DOe Date: Wed, 1 Feb 2017 13:47:48 +0000 Subject: [PATCH 17/88] Role add controller and small form modification. --- og_ui/og_ui.routing.yml | 6 ++-- og_ui/src/Controller/OgRoleController.php | 40 +++++++++++++++++++++++ og_ui/src/Form/OgRoleForm.php | 30 +++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 og_ui/src/Controller/OgRoleController.php diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 4861c8b64..eff2188f0 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -36,9 +36,11 @@ og_ui.roles_overview: og_ui.role_add_form: path: 'admin/config/group/role/{entity_type}/{bundle}/add' defaults: - _form: '\Drupal\og_ui\Form\OgRoleAddForm' - _title_callback: '\Drupal\og_ui\Form\OgRoleAddForm::titleCallback' + _controller: '\Drupal\og_ui\Controller\OgRoleController::add' + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' requirements: + # Todo: This should become a dedicated permission: + # _entity_access: og_role.add _permission: 'administer group' entity.og_role.edit_form: diff --git a/og_ui/src/Controller/OgRoleController.php b/og_ui/src/Controller/OgRoleController.php new file mode 100644 index 000000000..50cf28291 --- /dev/null +++ b/og_ui/src/Controller/OgRoleController.php @@ -0,0 +1,40 @@ +t('Create New Role'); + + // Show the actual reply box. + $og_role = $this->entityManager()->getStorage('og_role')->create(array( + 'group_type' => $entity_type, + 'group_bundle' => $bundle, + )); + $build['og_role_form'] = $this->entityFormBuilder()->getForm($og_role); + + return $build; + } + +} \ No newline at end of file diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 89b181e03..eab8b1465 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -33,6 +33,21 @@ public function form(array $form, FormStateInterface $form_state) { '#maxlength' => 64, '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), ]; + $form['name'] = array( + '#type' => 'machine_name', + '#default_value' => $entity->id(), + '#required' => TRUE, + '#disabled' => !$entity->isNew(), + '#size' => 30, + '#maxlength' => 64, + '#machine_name' => array( + 'exists' => ['\Drupal\og_uid\Entity\OgRole', 'load'], + ), + ); + $form['weight'] = array( + '#type' => 'value', + '#value' => $entity->getWeight(), + ); return parent::form($form, $form_state, $entity); } @@ -45,6 +60,7 @@ public function save(array $form, FormStateInterface $form_state) { // Prevent leading and trailing spaces in role names. $entity->set('label', trim($entity->label())); + $entity->set('name', trim($entity->get('name'))); $status = $entity->save(); $edit_link = $this->entity->link($this->t('Edit')); @@ -78,4 +94,18 @@ public function editRoleTitleCallback(OgRole $og_role) { ]); } + /** + * @param string $bundle + * Entity type bundle. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * An object that, when cast to a string, returns the translated title + * callback. + */ + public function addRoleTitleCallback($bundle) { + return $this->t('Create %bundle OG role', [ + '%bundle' => $bundle, + ]); + } + } From 9a725aff19105db453eb164aa4538643be05afea Mon Sep 17 00:00:00 2001 From: Archie DOe Date: Wed, 1 Feb 2017 15:03:53 +0000 Subject: [PATCH 18/88] Adding reoute for creation group-specific role links, restoring overview links removed in b4e89491fd4fae8616856ed8f402259075f138a9 --- og_ui/og_ui.links.menu.yml | 16 ++++++++++++++++ og_ui/og_ui.routing.yml | 12 +++++++++++- og_ui/src/Controller/OgRoleController.php | 7 ++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/og_ui/og_ui.links.menu.yml b/og_ui/og_ui.links.menu.yml index e315cbf0b..41b603b64 100644 --- a/og_ui/og_ui.links.menu.yml +++ b/og_ui/og_ui.links.menu.yml @@ -11,3 +11,19 @@ og_ui.settings: parent: og_ui.admin_index description: 'Administer OG settings.' route_name: og_ui.settings + +og_ui.roles_overview: + title: 'OG roles' + parent: og_ui.admin_index + description: 'Administer OG roles.' + route_name: og_ui.roles_permissions_overview + route_parameters: + type: 'roles' + +og_ui.permissions_overview: + title: 'OG permissions' + parent: og_ui.admin_index + description: 'Administer OG permissions.' + route_name: og_ui.roles_permissions_overview + route_parameters: + type: 'permissions' diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index eff2188f0..b428d1b9d 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -36,7 +36,17 @@ og_ui.roles_overview: og_ui.role_add_form: path: 'admin/config/group/role/{entity_type}/{bundle}/add' defaults: - _controller: '\Drupal\og_ui\Controller\OgRoleController::add' + _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupTypeRole' + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' + requirements: + # Todo: This should become a dedicated permission: + # _entity_access: og_role.add + _permission: 'administer group' + +og_ui.group_role_add_form: + path: 'admin/config/group/role/{entity_type}/{entity}/add' + defaults: + _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupRole' _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' requirements: # Todo: This should become a dedicated permission: diff --git a/og_ui/src/Controller/OgRoleController.php b/og_ui/src/Controller/OgRoleController.php index 50cf28291..7c67f07e6 100644 --- a/og_ui/src/Controller/OgRoleController.php +++ b/og_ui/src/Controller/OgRoleController.php @@ -3,6 +3,7 @@ namespace Drupal\og_ui\Controller; use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Entity\Entity; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; /** @@ -24,7 +25,7 @@ class OgRoleController extends ControllerBase implements ContainerInjectionInter * An associative array containing: * - og_role_form: The og_role form as a renderable array. */ - public function add($entity_type, $bundle) { + public function addGroupTypeRole($entity_type, $bundle) { $build['#title'] = $this->t('Create New Role'); // Show the actual reply box. @@ -37,4 +38,8 @@ public function add($entity_type, $bundle) { return $build; } + public function addGroupRole(Entity $entity) { + + } + } \ No newline at end of file From 7aae69589c1fe55a21415586d4133063fa15eb6f Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 21 Feb 2017 16:14:51 +0000 Subject: [PATCH 19/88] Add amitaibu/196 --- src/Entity/OgRole.php | 7 +++++++ src/OgRoleInterface.php | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index f100e0487..efceeb659 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -147,6 +147,13 @@ public function setRoleType($role_type) { return $this->set('role_type', $role_type); } + /** + * {@inheritdoc} + */ + public function isLocked() { + return $this->get('role_type') !== OgRoleInterface::ROLE_TYPE_STANDARD; + } + /** * {@inheritdoc} */ diff --git a/src/OgRoleInterface.php b/src/OgRoleInterface.php index cb09fc07b..53f9678a9 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -126,6 +126,17 @@ public function getRoleType(); */ public function setRoleType($role_type); + /* + * Returns whether or not a role can be changed. + * + * This will return FALSE for all roles except the default roles 'non-member' + * and 'member'. + * + * @return bool + * Whether or not the role is locked. + */ + public function isLocked(); + /** * Returns the role name. * From 746932f9221b80f24e3951fbb0d3f9ae5fc9cfa6 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 4 Jul 2018 19:21:45 +0200 Subject: [PATCH 20/88] Remove duplicated method. --- src/Entity/OgRole.php | 7 ------- src/OgRoleInterface.php | 11 ----------- 2 files changed, 18 deletions(-) diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index efceeb659..7d922f457 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -178,13 +178,6 @@ public function setName($name) { return $this; } - /** - * {@inheritdoc} - */ - public function isLocked() { - return $this->get('role_type') !== OgRoleInterface::ROLE_TYPE_STANDARD; - } - /** * {@inheritdoc} */ diff --git a/src/OgRoleInterface.php b/src/OgRoleInterface.php index 53f9678a9..fccc07f16 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -207,15 +207,4 @@ public static function getRole($entity_type_id, $bundle, $role_name); */ public function isRequired(); - /** - * Returns whether or not a role can be changed. - * - * This will return FALSE for all roles except the default roles 'non-member' - * and 'member'. - * - * @return bool - * Whether or not the role is locked. - */ - public function isLocked(); - } From d52259e7fbb7433ed34dbbf08d368033aef5eca7 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 21 Feb 2017 22:28:43 +0000 Subject: [PATCH 21/88] Fix clashing routes og_ui.role_add_form and og_ui.group_role_add_form using the same path, but pointing to different methods expecting different arguments. Commented out the group role add one for now --- og_ui/og_ui.routing.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index b428d1b9d..faa79deb5 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -43,15 +43,15 @@ og_ui.role_add_form: # _entity_access: og_role.add _permission: 'administer group' -og_ui.group_role_add_form: - path: 'admin/config/group/role/{entity_type}/{entity}/add' - defaults: - _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupRole' - _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' - requirements: - # Todo: This should become a dedicated permission: - # _entity_access: og_role.add - _permission: 'administer group' +#og_ui.group_role_add_form: +# path: 'admin/config/group/role/{entity_type}/{entity}/add' +# defaults: +# _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupRole' +# _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' +# requirements: +# # Todo: This should become a dedicated permission: +# # _entity_access: og_role.add +# _permission: 'administer group' entity.og_role.edit_form: path: 'admin/config/group/role/{og_role}/edit' From d50c8007fd57d22c7296710774f32acfd6a82621 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 21 Feb 2017 22:29:13 +0000 Subject: [PATCH 22/88] Fix new group roles considered required, rather than standard --- og_ui/src/Form/OgRoleForm.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index eab8b1465..cbf2eac04 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\og\Entity\OgRole; +use Drupal\og\OgRoleInterface; /** * Form to add or edit an OG role. @@ -49,6 +50,11 @@ public function form(array $form, FormStateInterface $form_state) { '#value' => $entity->getWeight(), ); + $form['role_type'] = [ + '#type' => 'value', + '#value' => OgRoleInterface::ROLE_TYPE_STANDARD, + ]; + return parent::form($form, $form_state, $entity); } From 297669e778b07ec207cc00739ede5e56f1712a59 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 21 Feb 2017 22:29:37 +0000 Subject: [PATCH 23/88] Add OG role deletion form --- og_ui/og_ui.routing.yml | 10 ++++++++ og_ui/src/Controller/OgUiController.php | 25 +++++++++++++++--- og_ui/src/Form/OgRoleDeleteForm.php | 34 +++++++++++++++++++++++++ src/Entity/OgRole.php | 9 ++++++- 4 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 og_ui/src/Form/OgRoleDeleteForm.php diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index faa79deb5..92f74b053 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -63,6 +63,16 @@ entity.og_role.edit_form: # _entity_access: og_role.update _permission: 'administer group' +entity.og_role.delete_form: + path: 'admin/config/group/role/{og_role}/delete' + defaults: + _entity_form: og_role.delete + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' + requirements: + # Todo: This should become a dedicated permission: + # _entity_access: og_role.delete + _permission: 'administer group' + og_ui.permissions_overview: path: 'admin/config/group/permissions/{entity_type}/{bundle}' defaults: diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 797bc62c9..98769e9c0 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -150,10 +150,29 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { // Add the edit role link if the role is editable. if (!$role->isLocked()) { + $operations = []; + // if ($role->access('update') && $role->hasLinkTemplate('edit-form')) { + if ($role->hasLinkTemplate('edit-form')) { + $operations['edit'] = [ + 'title' => $this->t('Edit role'), + 'weight' => 10, + 'url' => $role->urlInfo('edit-form'), + ]; + } + //if ($role->access('delete') && $role->hasLinkTemplate('delete-form')) { + if ($role->hasLinkTemplate('delete-form')) { + $operations['delete'] = [ + 'title' => $this->t('Delete role'), + 'weight' => 100, + 'url' => $role->urlInfo('delete-form'), + ]; + } + $columns[] = [ - 'data' => Link::createFromRoute($this->t('Edit role'), 'entity.og_role.edit_form', [ - 'og_role' => $role->id(), - ]), + 'data' => [ + '#type' => 'operations', + '#links' => $operations, + ], ]; } else { diff --git a/og_ui/src/Form/OgRoleDeleteForm.php b/og_ui/src/Form/OgRoleDeleteForm.php new file mode 100644 index 000000000..3b41f2204 --- /dev/null +++ b/og_ui/src/Form/OgRoleDeleteForm.php @@ -0,0 +1,34 @@ +getEntity(); + + return Url::fromRoute('og_ui.roles_overview', [ + 'entity_type' => $entity->group_type, + 'bundle' => $entity->group_bundle, + ]); + } + + /** + * {@inheritdoc} + */ + protected function getRedirectUrl() { + return $this->getCancelUrl(); + } + + +} diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 7d922f457..43e035c82 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -16,10 +16,17 @@ * @ConfigEntityType( * id = "og_role", * label = @Translation("OG role"), + * label_singular = @Translation("OG role"), + * label_plural = @Translation("OG roles"), + * label_count = @PluralTranslation( + * singular = "@count OG role", + * plural = "@count OG roles" + * ), * handlers = { * "form" = { * "default" = "Drupal\og_ui\Form\OgRoleForm", - * "delete" = "Drupal\Core\Entity\EntityDeleteForm" + * "delete" = "Drupal\og_ui\Form\OgRoleDeleteForm", + * "edit" = "Drupal\og_ui\Form\OgRoleForm", * } * }, * static_cache = TRUE, From f43ad367da3bce52e082e3172a0bfcea253a8689 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 7 Mar 2017 12:43:14 +0000 Subject: [PATCH 24/88] Add permissions overview and role permission forms --- og_ui/og_ui.routing.yml | 10 +- og_ui/src/Controller/OgUiController.php | 3 + og_ui/src/Form/OgPermissionsForm.php | 284 +++++++++++++++++++++++ og_ui/src/Form/OgRolePermissionsForm.php | 56 +++++ 4 files changed, 349 insertions(+), 4 deletions(-) create mode 100644 og_ui/src/Form/OgPermissionsForm.php create mode 100644 og_ui/src/Form/OgRolePermissionsForm.php diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 92f74b053..9e8229ad3 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -77,14 +77,16 @@ og_ui.permissions_overview: path: 'admin/config/group/permissions/{entity_type}/{bundle}' defaults: _form: '\Drupal\og_ui\Form\OgPermissionsForm' - _title: '@todo - create title callback' + _title_callback: '\Drupal\og_ui\Form\OgPermissionsForm::titleCallback' requirements: _permission: 'administer group' +# Todo: the {og_role} parameter could use being the simple form +# i.e. administrator instead of entity_type-bundle-role og_ui.permissions_edit_form: - path: 'admin/config/group/permission/{og_role}/edit' + path: 'admin/config/group/permissions/{entity_type}/{bundle}/{og_role}' defaults: - _form: '\Drupal\og_ui\Form\OgPermissionsEditForm' - _title_callback: '\Drupal\og_ui\Form\OgPermissionsEditForm::titleCallback' + _form: '\Drupal\og_ui\Form\OgRolePermissionsForm' + _title_callback: '\Drupal\og_ui\Form\OgRolePermissionsForm::titleCallback' requirements: _permission: 'administer group' diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 98769e9c0..105b5e177 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -180,8 +180,11 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { } // Add the edit permissions link. + // @TODO investigate using a clean id string (id() is "node-bundle-rid") $columns[] = [ 'data' => Link::createFromRoute($this->t('Edit permissions'), 'og_ui.permissions_edit_form', [ + 'entity_type' => $entity_type, + 'bundle' => $bundle, 'og_role' => $role->id(), ]), ]; diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php new file mode 100644 index 000000000..2f85bf668 --- /dev/null +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -0,0 +1,284 @@ +permissionManager = $permission_manager; + $this->roleManager = $role_manager; + $this->groupTypeManager = $group_type_manager; + $this->entityTypeBundleInfo = $entity_type_bundle_info; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('og.permission_manager'), + $container->get('og.role_manager'), + $container->get('og.group_type_manager'), + $container->get('entity_type.bundle.info') + ); + } + + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'group_permissions'; + } + + /** + * Title callback for the roles overview page. + * + * @param string $entity_type + * The group entity type id. + * @param string $bundle + * The group bundle id. + * + * @return \Drupal\Core\StringTranslation\TranslatableMarkup + */ + public function titleCallback($entity_type, $bundle) { + return $this->t('@bundle permissions', [ + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], + ]); + } + + /** + * Returns the group roles to display in the form. + * + * @param string $entity_type + * The group entity type id. + * @param string $bundle + * The group entity bundle id. + * + * @return array + */ + public function getGroupRoles($entity_type, $bundle) { + if (empty($this->roles)) { + $this->roles = $this->roleManager->getRolesByBundle($entity_type, $bundle); + } + + return $this->roles; + } + + /** + * {@inheritdoc} + * + * @param \Drupal\og\Entity\OgRole $group_role + */ + public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { + // Render the link for hiding descriptions. + $form['system_compact_link'] = [ + '#id' => FALSE, + '#type' => 'system_compact_link', + ]; + + $hide_descriptions = system_admin_compact_mode(); + + $form['permissions'] = [ + '#type' => 'table', + '#header' => [$this->t('Permission')], + '#id' => 'permissions', + '#attributes' => ['class' => ['permissions', 'js-permissions']], + '#sticky' => TRUE, + ]; + + $roles = $this->getGroupRoles($entity_type, $bundle); + + /** @var \Drupal\og\Entity\OgRole $role */ + foreach ($roles as $role) { + $form['permissions']['#header'][] = [ + 'data' => $role->getLabel(), + 'class' => ['checkbox'], + ]; + } + + $bundles = $this->groupTypeManager->getGroupContentBundleIdsByGroupBundle($entity_type, $bundle); + $group_permissions = $this->permissionManager->getDefaultGroupPermissions($entity_type, $bundle); + $group_content_permissions = $this->permissionManager->getDefaultEntityOperationPermissions($entity_type, $bundle, $bundles); + + $permissions_by_provider = [ + 'Group' => $group_permissions, + 'Group content' => $group_content_permissions, + ]; + + foreach ($permissions_by_provider as $provider => $permissions) { + // Module name. + $form['permissions'][$provider] = [ + [ + '#wrapper_attributes' => [ + 'colspan' => count($roles) + 1, + 'class' => ['module'], + 'id' => 'module-' . $provider, + ], + '#markup' => $provider, + ], + ]; + + /** @var \Drupal\og\Permission $permission */ + foreach ($permissions as $perm => $permission) { + + // Fill in default values for the permission. + $perm_item = [ + 'title' => $permission->getTitle(), + 'description' => $permission->getDescription(), + 'restrict access' => $permission->getRestrictAccess(), + 'warning' => $permission->getRestrictAccess() ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '', + ]; + + $form['permissions'][$perm]['description'] = [ + '#type' => 'inline_template', + '#template' => '
{{ title }}{% if description or warning %}
{% if warning %}{{ warning }} {% endif %}{{ description }}
{% endif %}
', + '#context' => [ + 'title' => $perm_item['title'], + ], + ]; + // Show the permission description. + if (!$hide_descriptions) { + $form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description']; + $form['permissions'][$perm]['description']['#context']['warning'] = $perm_item['warning']; + } + foreach ($roles as $rid => $role) { + list(,, $rid_simple) = explode('-', $rid, 3); + + // The roles variable indicates which roles the permission applies to. + $permission_applies = TRUE; + if (property_exists($permission, 'roles')) { + $target_roles = $permission->get('roles'); + $permission_applies = empty($target_roles) || in_array($rid_simple, $target_roles); + } + + if ($permission_applies) { + $form['permissions'][$perm][$rid] = [ + '#title' => $role->getName() . ': ' . $perm_item['title'], + '#title_display' => 'invisible', + '#wrapper_attributes' => [ + 'class' => ['checkbox'], + ], + '#type' => 'checkbox', + '#default_value' => $role->hasPermission($perm) ? 1 : 0, + '#attributes' => ['class' => ['rid-' . $rid, 'js-rid-' . $rid]], + '#parents' => [$rid, $perm], + ]; + // Show a column of disabled but checked checkboxes. + + if ($roles[$rid]->get('is_admin') || + in_array($rid_simple, $permission->getDefaultRoles())) { + $form['permissions'][$perm][$rid]['#disabled'] = TRUE; + $form['permissions'][$perm][$rid]['#default_value'] = TRUE; + } + } + else { + $form['permissions'][$perm][$rid] = [ + '#title' => $role->getName() . ': ' . $perm_item['title'], + '#title_display' => 'invisible', + '#wrapper_attributes' => [ + 'class' => ['checkbox'], + ], + '#markup' => '-', + ]; + } + } + } + } + + $form['actions'] = ['#type' => 'actions']; + $form['actions']['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Save permissions'), + '#button_type' => 'primary', + ]; + + $form['#attached']['library'][] = 'user/drupal.user.permissions'; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + + /** @var \Drupal\og\Entity\OgRole $role */ + foreach ($this->roles as $rid => $role) { + if (!$form_state->hasValue($rid)) { + continue; + } + + $permissions = $form_state->getValue($rid); + foreach ($permissions as $permission => $grant) { + if ($grant) { + $role->grantPermission($permission); + } + else { + $role->revokePermission($permission); + } + } + + $role->save(); + } + } + +} diff --git a/og_ui/src/Form/OgRolePermissionsForm.php b/og_ui/src/Form/OgRolePermissionsForm.php new file mode 100644 index 000000000..f45648ad5 --- /dev/null +++ b/og_ui/src/Form/OgRolePermissionsForm.php @@ -0,0 +1,56 @@ +t('@bundle roles - @role permissions', [ + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], + '@role' => $role->getLabel(), + ]); + } + + /** + * {@inheritdoc} + * + * @param \Drupal\og\Entity\OgRole $group_role + */ + public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '', $og_role = '') { + $this->roles = [OgRole::load($og_role)]; + + return parent::buildForm($form, $form_state, $entity_type, $bundle); + } + +} From 8e9483641030f45c74006f37ea3459b884b675c7 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 7 Mar 2017 17:31:02 +0000 Subject: [PATCH 25/88] Fix PHP warnings --- og_ui/og_ui.routing.yml | 2 +- og_ui/src/Form/OgPermissionsForm.php | 16 ++++++++++------ og_ui/src/Form/OgRolePermissionsForm.php | 9 ++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 9e8229ad3..84c47fe88 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -87,6 +87,6 @@ og_ui.permissions_edit_form: path: 'admin/config/group/permissions/{entity_type}/{bundle}/{og_role}' defaults: _form: '\Drupal\og_ui\Form\OgRolePermissionsForm' - _title_callback: '\Drupal\og_ui\Form\OgRolePermissionsForm::titleCallback' + _title_callback: '\Drupal\og_ui\Form\OgRolePermissionsForm::rolePermissionTitleCallback' requirements: _permission: 'administer group' diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 2f85bf668..f807b9ac2 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -126,7 +126,10 @@ public function getGroupRoles($entity_type, $bundle) { /** * {@inheritdoc} * - * @param \Drupal\og\Entity\OgRole $group_role + * @param string $entity_type + * The group entity type id. + * @param string $bundle + * The group bundle id. */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { // Render the link for hiding descriptions. @@ -165,13 +168,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t ]; foreach ($permissions_by_provider as $provider => $permissions) { - // Module name. + // Provider. $form['permissions'][$provider] = [ [ '#wrapper_attributes' => [ 'colspan' => count($roles) + 1, 'class' => ['module'], - 'id' => 'module-' . $provider, + 'id' => 'provider-' . $provider, ], '#markup' => $provider, ], @@ -179,7 +182,6 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t /** @var \Drupal\og\Permission $permission */ foreach ($permissions as $perm => $permission) { - // Fill in default values for the permission. $perm_item = [ 'title' => $permission->getTitle(), @@ -195,6 +197,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t 'title' => $perm_item['title'], ], ]; + // Show the permission description. if (!$hide_descriptions) { $form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description']; @@ -203,7 +206,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t foreach ($roles as $rid => $role) { list(,, $rid_simple) = explode('-', $rid, 3); - // The roles variable indicates which roles the permission applies to. + // The roles property indicates which roles the permission applies to. $permission_applies = TRUE; if (property_exists($permission, 'roles')) { $target_roles = $permission->get('roles'); @@ -222,8 +225,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t '#attributes' => ['class' => ['rid-' . $rid, 'js-rid-' . $rid]], '#parents' => [$rid, $perm], ]; - // Show a column of disabled but checked checkboxes. + // Show a column of disabled but checked checkboxes. + // Only applies to admins or default roles. if ($roles[$rid]->get('is_admin') || in_array($rid_simple, $permission->getDefaultRoles())) { $form['permissions'][$perm][$rid]['#disabled'] = TRUE; diff --git a/og_ui/src/Form/OgRolePermissionsForm.php b/og_ui/src/Form/OgRolePermissionsForm.php index f45648ad5..bf7156e2e 100644 --- a/og_ui/src/Form/OgRolePermissionsForm.php +++ b/og_ui/src/Form/OgRolePermissionsForm.php @@ -33,8 +33,9 @@ public function getFormId() { * The group bundle id. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * The role permission form title. */ - public function titleCallback($entity_type, $bundle, $og_role) { + public function rolePermissionTitleCallback($entity_type, $bundle, $og_role) { $role = OgRole::load($og_role); return $this->t('@bundle roles - @role permissions', [ '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], @@ -45,10 +46,12 @@ public function titleCallback($entity_type, $bundle, $og_role) { /** * {@inheritdoc} * - * @param \Drupal\og\Entity\OgRole $group_role + * @param string $og_role + * The group role id. */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '', $og_role = '') { - $this->roles = [OgRole::load($og_role)]; + $role = OgRole::load($og_role); + $this->roles = [$role->id() => $role]; return parent::buildForm($form, $form_state, $entity_type, $bundle); } From bcdfb4035c018a806c3ded8fd24ddba2c6535daf Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 10 Mar 2017 17:38:38 +0000 Subject: [PATCH 26/88] Fix role edit fails because of wrong 'exists' check --- og_ui/src/Form/OgRoleForm.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index cbf2eac04..736838c98 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -41,14 +41,14 @@ public function form(array $form, FormStateInterface $form_state) { '#disabled' => !$entity->isNew(), '#size' => 30, '#maxlength' => 64, - '#machine_name' => array( - 'exists' => ['\Drupal\og_uid\Entity\OgRole', 'load'], - ), + '#machine_name' => [ + 'exists' => ['\Drupal\og_ui\Entity\OgRole', 'load'], + ], ); - $form['weight'] = array( + $form['weight'] = [ '#type' => 'value', '#value' => $entity->getWeight(), - ); + ]; $form['role_type'] = [ '#type' => 'value', From 4241159bccee77610267ee8e57d2c7f3418b64f8 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 10 Mar 2017 17:59:33 +0000 Subject: [PATCH 27/88] Use _entity_access for og_role routes --- og_ui/og_ui.links.action.yml | 2 +- og_ui/og_ui.routing.yml | 22 +++--------------- src/Entity/OgRole.php | 2 ++ src/OgRoleAccessControlHandler.php | 37 ++++++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 src/OgRoleAccessControlHandler.php diff --git a/og_ui/og_ui.links.action.yml b/og_ui/og_ui.links.action.yml index d08588ae0..adf690e6f 100644 --- a/og_ui/og_ui.links.action.yml +++ b/og_ui/og_ui.links.action.yml @@ -1,5 +1,5 @@ og_ui.role_add: - route_name: og_ui.role_add_form + route_name: og_ui.role_add title: 'Add role' appears_on: - og_ui.roles_overview diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 84c47fe88..06a0b342f 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -33,35 +33,21 @@ og_ui.roles_overview: requirements: _permission: 'administer group' -og_ui.role_add_form: +og_ui.role_add: path: 'admin/config/group/role/{entity_type}/{bundle}/add' defaults: _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupTypeRole' _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' requirements: - # Todo: This should become a dedicated permission: - # _entity_access: og_role.add _permission: 'administer group' -#og_ui.group_role_add_form: -# path: 'admin/config/group/role/{entity_type}/{entity}/add' -# defaults: -# _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupRole' -# _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' -# requirements: -# # Todo: This should become a dedicated permission: -# # _entity_access: og_role.add -# _permission: 'administer group' - entity.og_role.edit_form: path: 'admin/config/group/role/{og_role}/edit' defaults: _entity_form: og_role.default _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' requirements: - # Todo: This should become a dedicated permission: - # _entity_access: og_role.update - _permission: 'administer group' + _entity_access: 'og_role.update' entity.og_role.delete_form: path: 'admin/config/group/role/{og_role}/delete' @@ -69,9 +55,7 @@ entity.og_role.delete_form: _entity_form: og_role.delete _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' requirements: - # Todo: This should become a dedicated permission: - # _entity_access: og_role.delete - _permission: 'administer group' + _entity_access: 'og_role.delete' og_ui.permissions_overview: path: 'admin/config/group/permissions/{entity_type}/{bundle}' diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 43e035c82..14c8fc554 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -23,12 +23,14 @@ * plural = "@count OG roles" * ), * handlers = { + * "access" = "Drupal\og\OgRoleAccessControlHandler", * "form" = { * "default" = "Drupal\og_ui\Form\OgRoleForm", * "delete" = "Drupal\og_ui\Form\OgRoleDeleteForm", * "edit" = "Drupal\og_ui\Form\OgRoleForm", * } * }, + * admin_permission = "administer group", * static_cache = TRUE, * entity_keys = { * "id" = "id", diff --git a/src/OgRoleAccessControlHandler.php b/src/OgRoleAccessControlHandler.php new file mode 100644 index 000000000..9fe8aee49 --- /dev/null +++ b/src/OgRoleAccessControlHandler.php @@ -0,0 +1,37 @@ +id() == OgRoleInterface::ANONYMOUS || $entity->id() == OgRoleInterface::AUTHENTICATED) { + return AccessResult::forbidden(); + } + } + + // Group roles have no 'view' route, but can be used in views to show what + // roles a member has. We therefore allow 'view' access so field formatters + // such as entity_reference_label will work. + if ($operation == 'view') { + return AccessResult::allowed()->addCacheableDependency($entity); + } + + return parent::checkAccess($entity, $operation, $account); + } + +} From 0dbad653a8abe5a030231f8c05d906245b2dd474 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 10 Mar 2017 18:13:07 +0000 Subject: [PATCH 28/88] Fix go role validation issue --- og_ui/src/Form/OgRoleForm.php | 46 +++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 736838c98..04f578dbc 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -24,30 +24,40 @@ class OgRoleForm extends EntityForm { * {@inheritdoc} */ public function form(array $form, FormStateInterface $form_state) { - $entity = $this->entity; + $og_role = $this->entity; $form['label'] = [ '#type' => 'textfield', '#title' => $this->t('Role name'), - '#default_value' => $entity->label(), + '#default_value' => $og_role->label(), '#size' => 30, '#required' => TRUE, '#maxlength' => 64, '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), ]; - $form['name'] = array( + + $role_id = ''; + if ($og_role->id()) { + // The actual role id is -- + // Given the machine_name constraints, we go back to ID here + // as the full id is assembled in OgRole::save(). + list($entity_type, , $role_id) = explode('-', $og_role->id(), 3); + } + + $form['name'] = [ '#type' => 'machine_name', - '#default_value' => $entity->id(), + '#default_value' => $role_id, '#required' => TRUE, - '#disabled' => !$entity->isNew(), + '#disabled' => !$og_role->isNew(), '#size' => 30, '#maxlength' => 64, '#machine_name' => [ 'exists' => ['\Drupal\og_ui\Entity\OgRole', 'load'], ], - ); + '#field_prefix' => $og_role->getGroupType() . '-' . $og_role->getGroupBundle() . '-', + ]; $form['weight'] = [ '#type' => 'value', - '#value' => $entity->getWeight(), + '#value' => $og_role->getWeight(), ]; $form['role_type'] = [ @@ -55,32 +65,32 @@ public function form(array $form, FormStateInterface $form_state) { '#value' => OgRoleInterface::ROLE_TYPE_STANDARD, ]; - return parent::form($form, $form_state, $entity); + return parent::form($form, $form_state, $og_role); } /** * {@inheritdoc} */ public function save(array $form, FormStateInterface $form_state) { - $entity = $this->entity; + $og_role = $this->entity; // Prevent leading and trailing spaces in role names. - $entity->set('label', trim($entity->label())); - $entity->set('name', trim($entity->get('name'))); - $status = $entity->save(); + $og_role->set('label', trim($og_role->label())); + $og_role->set('name', trim($og_role->get('name'))); + $status = $og_role->save(); $edit_link = $this->entity->link($this->t('Edit')); if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('OG role %label has been updated.', ['%label' => $entity->label()])); - $this->logger('user')->notice('OG role %label has been updated.', ['%label' => $entity->label(), 'link' => $edit_link]); + drupal_set_message($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); + $this->logger('user')->notice('OG role %label has been updated.', ['%label' => $og_role->label(), 'link' => $edit_link]); } else { - drupal_set_message($this->t('OG role %label has been added.', ['%label' => $entity->label()])); - $this->logger('user')->notice('OG role %label has been added.', ['%label' => $entity->label(), 'link' => $edit_link]); + drupal_set_message($this->t('OG role %label has been added.', ['%label' => $og_role->label()])); + $this->logger('user')->notice('OG role %label has been added.', ['%label' => $og_role->label(), 'link' => $edit_link]); } $form_state->setRedirect('og_ui.roles_overview', [ - 'entity_type' => $entity->getGroupType(), - 'bundle' => $entity->getGroupBundle(), + 'entity_type' => $og_role->getGroupType(), + 'bundle' => $og_role->getGroupBundle(), ]); } From 04b0dc98d4f653fd1352af2a7b97bbd315e739dd Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 10 Mar 2017 18:13:26 +0000 Subject: [PATCH 29/88] Linting --- og_ui/src/Controller/OgRoleController.php | 6 +----- og_ui/src/Controller/OgUiController.php | 10 ++++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/og_ui/src/Controller/OgRoleController.php b/og_ui/src/Controller/OgRoleController.php index 7c67f07e6..867e313a5 100644 --- a/og_ui/src/Controller/OgRoleController.php +++ b/og_ui/src/Controller/OgRoleController.php @@ -38,8 +38,4 @@ public function addGroupTypeRole($entity_type, $bundle) { return $build; } - public function addGroupRole(Entity $entity) { - - } - -} \ No newline at end of file +} diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 105b5e177..e778d1f33 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -6,7 +6,10 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; +<<<<<<< HEAD use Drupal\og\GroupTypeManagerInterface; +======= +>>>>>>> Linting use Drupal\og\Og; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -151,16 +154,14 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { // Add the edit role link if the role is editable. if (!$role->isLocked()) { $operations = []; - // if ($role->access('update') && $role->hasLinkTemplate('edit-form')) { - if ($role->hasLinkTemplate('edit-form')) { + if ($role->access('update') && $role->hasLinkTemplate('edit-form')) { $operations['edit'] = [ 'title' => $this->t('Edit role'), 'weight' => 10, 'url' => $role->urlInfo('edit-form'), ]; } - //if ($role->access('delete') && $role->hasLinkTemplate('delete-form')) { - if ($role->hasLinkTemplate('delete-form')) { + if ($role->access('delete') && $role->hasLinkTemplate('delete-form')) { $operations['delete'] = [ 'title' => $this->t('Delete role'), 'weight' => 100, @@ -212,6 +213,7 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { * The group bundle. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * The roles overview page title. */ public function rolesOverviewPageTitleCallback($entity_type, $bundle) { return $this->t('OG @type - @bundle roles', [ From 416eacd861c7a5e61b82e12dc5b0f398694764f8 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 10 Mar 2017 23:28:23 +0000 Subject: [PATCH 30/88] Restrict deletion for default OG roles --- src/OgRoleAccessControlHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OgRoleAccessControlHandler.php b/src/OgRoleAccessControlHandler.php index 9fe8aee49..eab6f272b 100644 --- a/src/OgRoleAccessControlHandler.php +++ b/src/OgRoleAccessControlHandler.php @@ -19,7 +19,8 @@ class OgRoleAccessControlHandler extends EntityAccessControlHandler { */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { if ($operation == 'delete') { - if ($entity->id() == OgRoleInterface::ANONYMOUS || $entity->id() == OgRoleInterface::AUTHENTICATED) { + list(, , $id) = explode('-', $entity->id(), 3); + if (in_array($id, [OgRoleInterface::ANONYMOUS, OgRoleInterface::AUTHENTICATED, OgRoleInterface::ADMINISTRATOR])) { return AccessResult::forbidden(); } } From c195c8004d570fc6eb5f65e50479a9c4b967ba7a Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 10 Mar 2017 23:41:24 +0000 Subject: [PATCH 31/88] Tweak roles list operations --- og_ui/src/Controller/OgUiController.php | 41 +++++++++++++------------ 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index e778d1f33..18b04c6bc 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -6,10 +6,8 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; -<<<<<<< HEAD use Drupal\og\GroupTypeManagerInterface; -======= ->>>>>>> Linting +use Drupal\Core\Url; use Drupal\og\Og; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -150,10 +148,19 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { foreach ($this->entityTypeManager->getStorage('og_role')->loadByProperties($properties) as $role) { // Add the role name cell. $columns = [['data' => $role->getLabel()]]; + $operations = []; + $edit_permissions = [ + 'title' => $this->t('Edit permissions'), + 'weight' => 10, + 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ + 'entity_type' => $entity_type, + 'bundle' => $bundle, + 'og_role' => $role->id(), + ]), + ]; // Add the edit role link if the role is editable. if (!$role->isLocked()) { - $operations = []; if ($role->access('update') && $role->hasLinkTemplate('edit-form')) { $operations['edit'] = [ 'title' => $this->t('Edit role'), @@ -161,6 +168,8 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { 'url' => $role->urlInfo('edit-form'), ]; } + + $operations['permissions'] = $edit_permissions; if ($role->access('delete') && $role->hasLinkTemplate('delete-form')) { $operations['delete'] = [ 'title' => $this->t('Delete role'), @@ -168,26 +177,18 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { 'url' => $role->urlInfo('delete-form'), ]; } - - $columns[] = [ - 'data' => [ - '#type' => 'operations', - '#links' => $operations, - ], - ]; } else { - $columns[] = ['data' => $this->t('Locked')]; + // Add the edit permissions link. + // @TODO investigate using a clean id string (id() is "node-bundle-rid"). + $operations['permissions'] = $edit_permissions; } - // Add the edit permissions link. - // @TODO investigate using a clean id string (id() is "node-bundle-rid") $columns[] = [ - 'data' => Link::createFromRoute($this->t('Edit permissions'), 'og_ui.permissions_edit_form', [ - 'entity_type' => $entity_type, - 'bundle' => $bundle, - 'og_role' => $role->id(), - ]), + 'data' => [ + '#type' => 'operations', + '#links' => $operations, + ], ]; $rows[] = $columns; @@ -197,7 +198,7 @@ public function rolesOverviewPage($entity_type = '', $bundle = '') { '#theme' => 'table', '#header' => [ $this->t('Role name'), - ['data' => $this->t('Operations'), 'colspan' => 2], + ['data' => $this->t('Operations')], ], '#rows' => $rows, '#empty' => $this->t('No roles available.'), From 4a5f2a33afd5798c979b96bb0641e105581fbaed Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Mon, 13 Mar 2017 11:03:58 +0000 Subject: [PATCH 32/88] Change group role overview page to DraggableListBuilder --- og_ui/og_ui.routing.yml | 5 +- og_ui/src/Controller/OgUiController.php | 86 +----------- og_ui/src/Form/OgRoleForm.php | 2 +- src/Entity/OgRole.php | 12 +- src/Entity/OgRoleListBuilder.php | 165 ++++++++++++++++++++++++ src/Entity/OgRoleRouteProvider.php | 60 +++++++++ 6 files changed, 237 insertions(+), 93 deletions(-) create mode 100644 src/Entity/OgRoleListBuilder.php create mode 100644 src/Entity/OgRoleRouteProvider.php diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 06a0b342f..609e0f817 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -26,10 +26,9 @@ og_ui.roles_permissions_overview: type: '^(roles|permissions)$' og_ui.roles_overview: - path: 'admin/config/group/roles/{entity_type}/{bundle}' + path: 'admin/config/group/roles/{entity_type_id}/{bundle}' defaults: - _controller: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPage' - _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' + _entity_list: 'og_role' requirements: _permission: 'administer group' diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 18b04c6bc..be90bc178 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -90,7 +90,7 @@ public function rolesPermissionsOverviewPage($type) { ], [ 'data' => Link::createFromRoute($action, 'og_ui.' . $type . '_overview', [ - 'entity_type' => $entity_type, + 'entity_type_id' => $entity_type, 'bundle' => $bundle, ]), ], @@ -121,90 +121,6 @@ public function rolesPermissionsOverviewTitleCallback($type) { return $this->t('OG @type overview', ['@type' => $type]); } - /** - * Returns the OG role overview page for a given entity type and bundle. - * - * @param string $entity_type - * The entity type for which to show the OG roles. - * @param string $bundle - * The bundle for which to show the OG roles. - * - * @return array - * The overview as a render array. - */ - public function rolesOverviewPage($entity_type = '', $bundle = '') { - // Return a 404 error when this is not a group. - if (!Og::isGroup($entity_type, $bundle)) { - throw new NotFoundHttpException(); - } - - $rows = []; - - $properties = [ - 'group_type' => $entity_type, - 'group_bundle' => $bundle, - ]; - /** @var \Drupal\og\Entity\OgRole $role */ - foreach ($this->entityTypeManager->getStorage('og_role')->loadByProperties($properties) as $role) { - // Add the role name cell. - $columns = [['data' => $role->getLabel()]]; - $operations = []; - $edit_permissions = [ - 'title' => $this->t('Edit permissions'), - 'weight' => 10, - 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ - 'entity_type' => $entity_type, - 'bundle' => $bundle, - 'og_role' => $role->id(), - ]), - ]; - - // Add the edit role link if the role is editable. - if (!$role->isLocked()) { - if ($role->access('update') && $role->hasLinkTemplate('edit-form')) { - $operations['edit'] = [ - 'title' => $this->t('Edit role'), - 'weight' => 10, - 'url' => $role->urlInfo('edit-form'), - ]; - } - - $operations['permissions'] = $edit_permissions; - if ($role->access('delete') && $role->hasLinkTemplate('delete-form')) { - $operations['delete'] = [ - 'title' => $this->t('Delete role'), - 'weight' => 100, - 'url' => $role->urlInfo('delete-form'), - ]; - } - } - else { - // Add the edit permissions link. - // @TODO investigate using a clean id string (id() is "node-bundle-rid"). - $operations['permissions'] = $edit_permissions; - } - - $columns[] = [ - 'data' => [ - '#type' => 'operations', - '#links' => $operations, - ], - ]; - - $rows[] = $columns; - } - - return [ - '#theme' => 'table', - '#header' => [ - $this->t('Role name'), - ['data' => $this->t('Operations')], - ], - '#rows' => $rows, - '#empty' => $this->t('No roles available.'), - ]; - } - /** * Title callback for the roles overview page. * diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 04f578dbc..a94882154 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -40,7 +40,7 @@ public function form(array $form, FormStateInterface $form_state) { // The actual role id is -- // Given the machine_name constraints, we go back to ID here // as the full id is assembled in OgRole::save(). - list($entity_type, , $role_id) = explode('-', $og_role->id(), 3); + list(, , $role_id) = explode('-', $og_role->id(), 3); } $form['name'] = [ diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 14c8fc554..49b7a18ba 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -28,7 +28,11 @@ * "default" = "Drupal\og_ui\Form\OgRoleForm", * "delete" = "Drupal\og_ui\Form\OgRoleDeleteForm", * "edit" = "Drupal\og_ui\Form\OgRoleForm", - * } + * }, + * "route_provider" = { + * "html" = "Drupal\og\Entity\OgRoleRouteProvider", + * }, + * "list_builder" = "Drupal\og\Entity\OgRoleListBuilder", * }, * admin_permission = "administer group", * static_cache = TRUE, @@ -38,10 +42,10 @@ * "weight" = "weight" * }, * links = { - * "delete-form" = "/admin/config/group/role/{og_role}/delete", + * "add-form" = "/admin/config/group/role/{entity_type}/{bundle}/add", * "edit-form" = "/admin/config/group/role/{og_role}/edit", - * "edit-permissions-form" = "/admin/config/group/permission/{og_role}/edit", - * "collection" = "/admin/config/group/roles", + * "delete-form" = "/admin/config/group/role/{og_role}/delete", + * "collection" = "/admin/config/group/roles/{entity_type_id}/{bundle}", * }, * config_export = { * "id", diff --git a/src/Entity/OgRoleListBuilder.php b/src/Entity/OgRoleListBuilder.php new file mode 100644 index 000000000..3e95a1734 --- /dev/null +++ b/src/Entity/OgRoleListBuilder.php @@ -0,0 +1,165 @@ +get('entity.manager')->getStorage($entity_type->id()), + $container->get('current_route_match') + ); + } + + /** + * Constructs a new OgRoleListBuilder object. + * + * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type + * The entity type definition. + * @param \Drupal\Core\Entity\EntityStorageInterface $storage + * The entity storage class. + * @param \Drupal\Core\Routing\RouteMatchInterface $route_match + * The route matcher. + */ + public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RouteMatchInterface $route_match) { + parent::__construct($entity_type, $storage); + + // When on the default og_role list route, + //we should have a group entity type and bundle. + if ($route_match->getRouteName() == 'entity.og_role.collection') { + $parameters = $route_match->getParameters(); + + // Check if the route had a group type parameter. + if ($parameters->has('entity_type_id')) { + $this->group_type = $parameters->get('entity_type_id'); + } + if ($parameters->has('bundle')) { + $this->group_bundle = $parameters->get('bundle'); + } + } + } + + /** + * {@inheritdoc} + */ + protected function getEntityIds() { + $query = $this->getStorage()->getQuery() + ->condition('group_type', $this->group_type, '=') + ->condition('group_bundle', $this->group_bundle, '=') + ->sort($this->entityType->getKey('weight')); + + // Only add the pager if a limit is specified. + if ($this->limit) { + $query->pager($this->limit); + } + + return array_values($query->execute()); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'og_roles_admin'; + } + + /** + * {@inheritdoc} + */ + public function buildHeader() { + $header['label'] = t('Name'); + return $header + parent::buildHeader(); + } + + /** + * {@inheritdoc} + */ + public function buildRow(EntityInterface $entity) { + $row['label'] = $entity->label(); + return $row + parent::buildRow($entity); + } + + /** + * {@inheritdoc} + */ + public function getDefaultOperations(EntityInterface $role) { + $operations = parent::getDefaultOperations($role); + + // @TODO if ($entity->hasLinkTemplate('edit-permissions-form')). + $operations['permissions'] = [ + 'title' => t('Edit permissions'), + 'weight' => 20, + 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ + 'entity_type' => $this->group_type, + 'bundle' => $this->group_bundle, + 'og_role' => $role->id(), + ]), + ]; + + if ($role->isLocked()) { + if (isset($operations['edit'])) { + unset($operations['edit']); + } + + if (isset($operations['delete'])) { + unset($operations['delete']); + } + } + + return $operations; + } + + /** + * {@inheritdoc} + */ + public function render() { + // Return a 404 error when this is not a group. + if (!Og::isGroup($this->group_type, $this->group_bundle)) { + throw new NotFoundHttpException(); + } + + $build = parent::render(); + $build['entities']['#empty'] = $this->t('There are no OG roles available yet. Add an OG role.', [ + '@link' => Url::fromRoute('entity.og_role.add_form', [ + 'entity_type' => $this->group_type, + 'bundle' => $this->group_bundle, + ])->toString() + ]); + + return $build; + } + +} diff --git a/src/Entity/OgRoleRouteProvider.php b/src/Entity/OgRoleRouteProvider.php new file mode 100644 index 000000000..b358bea85 --- /dev/null +++ b/src/Entity/OgRoleRouteProvider.php @@ -0,0 +1,60 @@ +setOption('parameters', ['entity_type' => ['type' => 'entity:{entity_type}']]) + ->setOption('parameters', ['bundle' => ['type' => '{entity_type}:{bundle}']]); + return $route; + } + } + + /** + * {@inheritdoc} + */ + protected function getEditFormRoute(EntityTypeInterface $entity_type) { + if ($route = parent::getEditFormRoute($entity_type)) { + $route->setDefault('_title_callback', '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback') + ->setOption('parameters', ['group_type' => ['type' => 'entity:group_type']]) + ->setRequirement('_entity_access', 'og_role.update'); + return $route; + } + } + + /** + * {@inheritdoc} + */ + protected function getDeleteFormRoute(EntityTypeInterface $entity_type) { + if ($route = parent::getDeleteFormRoute($entity_type)) { + $route->setDefault('_title_callback', '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback'); + $route->setOption('parameters', ['group_type' => ['type' => 'entity:group_type']]); + return $route; + } + } + + /** + * {@inheritdoc} + */ + protected function getCollectionRoute(EntityTypeInterface $entity_type) { + if ($route = parent::getCollectionRoute($entity_type)) { + $route->setDefault('_title_callback', '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback') + ->setOption('parameters', ['entity_type' => ['type' => 'entity:{entity_type}']]) + ->setRequirement('_permission', 'administer group'); + return $route; + } + } + +} From 49eaed52ac6705233e1b7749da52361cb84d1c0b Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Wed, 12 Apr 2017 12:28:26 +0100 Subject: [PATCH 33/88] Fix coding standards issues --- og_ui/src/Controller/OgRoleController.php | 5 ++-- og_ui/src/Controller/OgUiController.php | 3 --- og_ui/src/Form/OgPermissionsForm.php | 32 ++++++++++++++--------- og_ui/src/Form/OgRoleDeleteForm.php | 2 -- og_ui/src/Form/OgRoleForm.php | 3 ++- og_ui/src/Form/OgRolePermissionsForm.php | 20 ++++++++------ src/Entity/OgRoleListBuilder.php | 28 ++++++++++---------- src/Entity/OgRoleRouteProvider.php | 1 - src/OgRoleAccessControlHandler.php | 8 +++++- 9 files changed, 57 insertions(+), 45 deletions(-) diff --git a/og_ui/src/Controller/OgRoleController.php b/og_ui/src/Controller/OgRoleController.php index 867e313a5..9eba5b150 100644 --- a/og_ui/src/Controller/OgRoleController.php +++ b/og_ui/src/Controller/OgRoleController.php @@ -3,7 +3,6 @@ namespace Drupal\og_ui\Controller; use Drupal\Core\Controller\ControllerBase; -use Drupal\Core\Entity\Entity; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; /** @@ -29,10 +28,10 @@ public function addGroupTypeRole($entity_type, $bundle) { $build['#title'] = $this->t('Create New Role'); // Show the actual reply box. - $og_role = $this->entityManager()->getStorage('og_role')->create(array( + $og_role = $this->entityTypeManager()->getStorage('og_role')->create([ 'group_type' => $entity_type, 'group_bundle' => $bundle, - )); + ]); $build['og_role_form'] = $this->entityFormBuilder()->getForm($og_role); return $build; diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index be90bc178..182c8a952 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -7,10 +7,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; use Drupal\og\GroupTypeManagerInterface; -use Drupal\Core\Url; -use Drupal\og\Og; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * The OG UI controller. diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index f807b9ac2..6d300a493 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -23,14 +23,14 @@ class OgPermissionsForm extends FormBase { protected $permissionManager; /** - * The role manager + * The role manager. * * @var \Drupal\og\OgRoleManagerInterface */ protected $roleManager; /** - * The group type manager + * The group type manager. * * @var \Drupal\og\GroupTypeManager */ @@ -46,7 +46,7 @@ class OgPermissionsForm extends FormBase { /** * The group roles. * - * @var [] + * @var array */ protected $roles; @@ -81,7 +81,6 @@ public static function create(ContainerInterface $container) { ); } - /** * {@inheritdoc} */ @@ -90,7 +89,7 @@ public function getFormId() { } /** - * Title callback for the roles overview page. + * Title callback for the group permissions page. * * @param string $entity_type * The group entity type id. @@ -98,6 +97,7 @@ public function getFormId() { * The group bundle id. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup + * The group permission title. */ public function titleCallback($entity_type, $bundle) { return $this->t('@bundle permissions', [ @@ -114,6 +114,7 @@ public function titleCallback($entity_type, $bundle) { * The group entity bundle id. * * @return array + * The group roles. */ public function getGroupRoles($entity_type, $bundle) { if (empty($this->roles)) { @@ -124,12 +125,19 @@ public function getGroupRoles($entity_type, $bundle) { } /** - * {@inheritdoc} + * The group permissions form constructor. * + * @param array $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. * @param string $entity_type * The group entity type id. * @param string $bundle * The group bundle id. + * + * @return array + * The form structure. */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { // Render the link for hiding descriptions. @@ -171,12 +179,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t // Provider. $form['permissions'][$provider] = [ [ - '#wrapper_attributes' => [ - 'colspan' => count($roles) + 1, - 'class' => ['module'], - 'id' => 'provider-' . $provider, - ], - '#markup' => $provider, + '#wrapper_attributes' => [ + 'colspan' => count($roles) + 1, + 'class' => ['module'], + 'id' => 'provider-' . $provider, + ], + '#markup' => $provider, ], ]; diff --git a/og_ui/src/Form/OgRoleDeleteForm.php b/og_ui/src/Form/OgRoleDeleteForm.php index 3b41f2204..435fbed63 100644 --- a/og_ui/src/Form/OgRoleDeleteForm.php +++ b/og_ui/src/Form/OgRoleDeleteForm.php @@ -5,7 +5,6 @@ use Drupal\Core\Entity\EntityDeleteForm; use Drupal\Core\Url; - /** * Provides a form for deleting a node. */ @@ -30,5 +29,4 @@ protected function getRedirectUrl() { return $this->getCancelUrl(); } - } diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index a94882154..56bfba99e 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -1,6 +1,5 @@ getRouteName() == 'entity.og_role.collection') { $parameters = $route_match->getParameters(); // Check if the route had a group type parameter. if ($parameters->has('entity_type_id')) { - $this->group_type = $parameters->get('entity_type_id'); + $this->groupType = $parameters->get('entity_type_id'); } if ($parameters->has('bundle')) { - $this->group_bundle = $parameters->get('bundle'); + $this->groupBundle = $parameters->get('bundle'); } } } @@ -77,8 +77,8 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter */ protected function getEntityIds() { $query = $this->getStorage()->getQuery() - ->condition('group_type', $this->group_type, '=') - ->condition('group_bundle', $this->group_bundle, '=') + ->condition('group_type', $this->groupType, '=') + ->condition('group_bundle', $this->groupBundle, '=') ->sort($this->entityType->getKey('weight')); // Only add the pager if a limit is specified. @@ -122,9 +122,9 @@ public function getDefaultOperations(EntityInterface $role) { $operations['permissions'] = [ 'title' => t('Edit permissions'), 'weight' => 20, - 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ - 'entity_type' => $this->group_type, - 'bundle' => $this->group_bundle, + 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ + 'entity_type' => $this->groupType, + 'bundle' => $this->groupBundle, 'og_role' => $role->id(), ]), ]; @@ -147,16 +147,16 @@ public function getDefaultOperations(EntityInterface $role) { */ public function render() { // Return a 404 error when this is not a group. - if (!Og::isGroup($this->group_type, $this->group_bundle)) { + if (!Og::isGroup($this->groupType, $this->groupBundle)) { throw new NotFoundHttpException(); } $build = parent::render(); $build['entities']['#empty'] = $this->t('There are no OG roles available yet. Add an OG role.', [ '@link' => Url::fromRoute('entity.og_role.add_form', [ - 'entity_type' => $this->group_type, - 'bundle' => $this->group_bundle, - ])->toString() + 'entity_type' => $this->groupType, + 'bundle' => $this->groupBundle, + ])->toString(), ]); return $build; diff --git a/src/Entity/OgRoleRouteProvider.php b/src/Entity/OgRoleRouteProvider.php index b358bea85..ea85f4757 100644 --- a/src/Entity/OgRoleRouteProvider.php +++ b/src/Entity/OgRoleRouteProvider.php @@ -2,7 +2,6 @@ namespace Drupal\og\Entity; - use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider; diff --git a/src/OgRoleAccessControlHandler.php b/src/OgRoleAccessControlHandler.php index eab6f272b..ccf917c5b 100644 --- a/src/OgRoleAccessControlHandler.php +++ b/src/OgRoleAccessControlHandler.php @@ -20,7 +20,13 @@ class OgRoleAccessControlHandler extends EntityAccessControlHandler { protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { if ($operation == 'delete') { list(, , $id) = explode('-', $entity->id(), 3); - if (in_array($id, [OgRoleInterface::ANONYMOUS, OgRoleInterface::AUTHENTICATED, OgRoleInterface::ADMINISTRATOR])) { + $roles = [ + OgRoleInterface::ANONYMOUS, + OgRoleInterface::AUTHENTICATED, + OgRoleInterface::ADMINISTRATOR, + ]; + + if (in_array($id, $roles)) { return AccessResult::forbidden(); } } From 6c1235a596a8567833a26ca519662b87f2c315fa Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 00:27:43 +0100 Subject: [PATCH 34/88] Use OgRole name --- og_ui/src/Form/OgRoleForm.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 56bfba99e..81703f32a 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -34,17 +34,9 @@ public function form(array $form, FormStateInterface $form_state) { '#description' => $this->t('The name for this role. Example: "Moderator", "Editorial board", "Site architect".'), ]; - $role_id = ''; - if ($og_role->id()) { - // The actual role id is -- - // Given the machine_name constraints, we go back to ID here - // as the full id is assembled in OgRole::save(). - list(, , $role_id) = explode('-', $og_role->id(), 3); - } - $form['name'] = [ '#type' => 'machine_name', - '#default_value' => $role_id, + '#default_value' => $og_role->getName(), '#required' => TRUE, '#disabled' => !$og_role->isNew(), '#size' => 30, From f74626db56ff78734a1f5c4a6889e03b1fdfb42e Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 00:28:09 +0100 Subject: [PATCH 35/88] Fix machine name validation --- og_ui/src/Form/OgRoleForm.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 81703f32a..e588b5853 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -42,7 +42,7 @@ public function form(array $form, FormStateInterface $form_state) { '#size' => 30, '#maxlength' => 64, '#machine_name' => [ - 'exists' => ['\Drupal\og_ui\Entity\OgRole', 'load'], + 'exists' => [$this, 'exists'], ], '#field_prefix' => $og_role->getGroupType() . '-' . $og_role->getGroupBundle() . '-', ]; @@ -59,6 +59,29 @@ public function form(array $form, FormStateInterface $form_state) { return parent::form($form, $form_state, $og_role); } + /** + * Machine name callback. + * + * Cannot use OgRole::load as the #machine_name callback as we are only + * allowing editing the role name. + * + * @param string $role_name + * The role name. + * + * @return OgRole|NULL + * The OG role if it exists. NULL otherwise. + */ + public function exists($role_name) { + $og_role = $this->entity; + $role_id = implode('-', [ + $og_role->getGroupType(), + $og_role->getGroupBundle(), + $role_name, + ]); + + return OgRole::load($role_id); + } + /** * {@inheritdoc} */ From 1c0320e11b57324445c4200c0a5c72238e38592d Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 00:28:26 +0100 Subject: [PATCH 36/88] Fix typos --- og_ui/src/Form/OgRoleForm.php | 2 +- src/Plugin/Derivative/OgLocalTask.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index e588b5853..b31b60cd2 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -103,7 +103,7 @@ public function save(array $form, FormStateInterface $form_state) { $this->logger('user')->notice('OG role %label has been added.', ['%label' => $og_role->label(), 'link' => $edit_link]); } $form_state->setRedirect('og_ui.roles_overview', [ - 'entity_type' => $og_role->getGroupType(), + 'entity_type_id' => $og_role->getGroupType(), 'bundle' => $og_role->getGroupBundle(), ]); } diff --git a/src/Plugin/Derivative/OgLocalTask.php b/src/Plugin/Derivative/OgLocalTask.php index c861065c4..dd1019f80 100644 --- a/src/Plugin/Derivative/OgLocalTask.php +++ b/src/Plugin/Derivative/OgLocalTask.php @@ -28,7 +28,7 @@ class OgLocalTask extends DeriverBase implements ContainerDeriverInterface { * * @var \Drupal\Core\Routing\RouteProvider */ - protected $routProvider; + protected $routeProvider; /** * Creates an OgLocalTask object. @@ -40,7 +40,7 @@ class OgLocalTask extends DeriverBase implements ContainerDeriverInterface { */ public function __construct(GroupTypeManagerInterface $group_type_manager, RouteProvider $route_provider) { $this->groupTypeManager = $group_type_manager; - $this->routProvider = $route_provider; + $this->routeProvider = $route_provider; } /** @@ -62,7 +62,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { foreach (array_keys($this->groupTypeManager->getGroupMap()) as $entity_type_id) { $route_name = "entity.$entity_type_id.og_admin_routes"; - if (!$this->routProvider->getRoutesByNames([$route_name])) { + if (!$this->routeProvider->getRoutesByNames([$route_name])) { // Route not found. continue; } From 0bf45ecff72ffaef0545e6f30fb365aa6ec3f795 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 00:43:54 +0100 Subject: [PATCH 37/88] Fix roles overview page title --- og_ui/src/Controller/OgUiController.php | 8 ++++---- src/Entity/OgRoleRouteProvider.php | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 182c8a952..f1e5926c3 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -121,7 +121,7 @@ public function rolesPermissionsOverviewTitleCallback($type) { /** * Title callback for the roles overview page. * - * @param string $entity_type + * @param string $entity_type_id * The group entity type. * @param string $bundle * The group bundle. @@ -129,10 +129,10 @@ public function rolesPermissionsOverviewTitleCallback($type) { * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The roles overview page title. */ - public function rolesOverviewPageTitleCallback($entity_type, $bundle) { + public function rolesOverviewPageTitleCallback($entity_type_id, $bundle) { return $this->t('OG @type - @bundle roles', [ - '@type' => $this->entityTypeManager->getDefinition($entity_type)->getLabel(), - '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], + '@type' => $this->entityTypeManager->getDefinition($entity_type_id)->getLabel(), + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle]['label'], ]); } diff --git a/src/Entity/OgRoleRouteProvider.php b/src/Entity/OgRoleRouteProvider.php index ea85f4757..e30510ef5 100644 --- a/src/Entity/OgRoleRouteProvider.php +++ b/src/Entity/OgRoleRouteProvider.php @@ -49,9 +49,7 @@ protected function getDeleteFormRoute(EntityTypeInterface $entity_type) { */ protected function getCollectionRoute(EntityTypeInterface $entity_type) { if ($route = parent::getCollectionRoute($entity_type)) { - $route->setDefault('_title_callback', '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback') - ->setOption('parameters', ['entity_type' => ['type' => 'entity:{entity_type}']]) - ->setRequirement('_permission', 'administer group'); + $route->setDefault('_title_callback', '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback'); return $route; } } From e5b4ec3526e14199365e76c456e8abfce75c2909 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 01:28:34 +0100 Subject: [PATCH 38/88] Update single permission form to use role name in path --- og_ui/og_ui.routing.yml | 4 +--- og_ui/src/Form/OgRolePermissionsForm.php | 28 ++++++++++++++++++------ src/Entity/OgRoleListBuilder.php | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 609e0f817..40bb23dc2 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -64,10 +64,8 @@ og_ui.permissions_overview: requirements: _permission: 'administer group' -# Todo: the {og_role} parameter could use being the simple form -# i.e. administrator instead of entity_type-bundle-role og_ui.permissions_edit_form: - path: 'admin/config/group/permissions/{entity_type}/{bundle}/{og_role}' + path: 'admin/config/group/permissions/{entity_type}/{bundle}/{role_name}' defaults: _form: '\Drupal\og_ui\Form\OgRolePermissionsForm' _title_callback: '\Drupal\og_ui\Form\OgRolePermissionsForm::rolePermissionTitleCallback' diff --git a/og_ui/src/Form/OgRolePermissionsForm.php b/og_ui/src/Form/OgRolePermissionsForm.php index 97d02460c..6b720f3ba 100644 --- a/og_ui/src/Form/OgRolePermissionsForm.php +++ b/og_ui/src/Form/OgRolePermissionsForm.php @@ -24,12 +24,19 @@ public function getFormId() { * The group entity type id. * @param string $bundle * The group bundle id. + * @param string $role_name + * The group role name. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The role permission form title. */ - public function rolePermissionTitleCallback($entity_type, $bundle, $og_role) { - $role = OgRole::load($og_role); + public function rolePermissionTitleCallback($entity_type, $bundle, $role_name) { + $role_id = implode('-', [ + $entity_type, + $bundle, + $role_name, + ]); + $role = OgRole::load($role_id); return $this->t('@bundle roles - @role permissions', [ '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], '@role' => $role->getLabel(), @@ -47,15 +54,22 @@ public function rolePermissionTitleCallback($entity_type, $bundle, $og_role) { * The group entity type id. * @param string $bundle * The group bundle id. - * @param string $og_role - * The group role id. + * @param string $role_name + * The group role name. * * @return array * The form structure. */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '', $og_role = '') { - $role = OgRole::load($og_role); - $this->roles = [$role->id() => $role]; + public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '', $role_name = '') { + $role_id = implode('-', [ + $entity_type, + $bundle, + $role_name, + ]); + + if ($role = OgRole::load($role_id)) { + $this->roles = [$role->id() => $role]; + } return parent::buildForm($form, $form_state, $entity_type, $bundle); } diff --git a/src/Entity/OgRoleListBuilder.php b/src/Entity/OgRoleListBuilder.php index 575698d6e..77403647c 100644 --- a/src/Entity/OgRoleListBuilder.php +++ b/src/Entity/OgRoleListBuilder.php @@ -125,7 +125,7 @@ public function getDefaultOperations(EntityInterface $role) { 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ 'entity_type' => $this->groupType, 'bundle' => $this->groupBundle, - 'og_role' => $role->id(), + 'role_name' => $role->getName(), ]), ]; From fd9581d3842ad597bc039a3ce5b35317b34466cd Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 01:34:00 +0100 Subject: [PATCH 39/88] Add permission page parameters validation --- og_ui/src/Form/OgPermissionsForm.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 6d300a493..805f11ac2 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -6,9 +6,11 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\og\GroupTypeManager; +use Drupal\og\Og; use Drupal\og\OgRoleManagerInterface; use Drupal\og\PermissionManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** * Provide the group permissions form. @@ -140,6 +142,11 @@ public function getGroupRoles($entity_type, $bundle) { * The form structure. */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { + if (!Og::isGroup($entity_type, $bundle)) { + // Not a valid entity. + throw new AccessDeniedHttpException(); + } + // Render the link for hiding descriptions. $form['system_compact_link'] = [ '#id' => FALSE, From 96c42265155b9ddb555afbe357f87352c11c6bb9 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 01:37:47 +0100 Subject: [PATCH 40/88] Return 404 instead of access denied --- og_ui/src/Form/OgPermissionsForm.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 805f11ac2..6142c2d68 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -10,7 +10,7 @@ use Drupal\og\OgRoleManagerInterface; use Drupal\og\PermissionManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Provide the group permissions form. @@ -142,9 +142,9 @@ public function getGroupRoles($entity_type, $bundle) { * The form structure. */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { + // Return a 404 error when this is not a group. if (!Og::isGroup($entity_type, $bundle)) { - // Not a valid entity. - throw new AccessDeniedHttpException(); + throw new NotFoundHttpException(); } // Render the link for hiding descriptions. From 6361f2f31dde0ebd78c9df33e0749218b0a35681 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 02:05:18 +0100 Subject: [PATCH 41/88] Standardise parameter names --- og_ui/og_ui.routing.yml | 8 +++--- og_ui/src/Controller/OgRoleController.php | 10 +++---- og_ui/src/Controller/OgUiController.php | 8 +++--- og_ui/src/Form/OgPermissionsForm.php | 32 +++++++++++------------ og_ui/src/Form/OgRoleDeleteForm.php | 4 +-- og_ui/src/Form/OgRoleForm.php | 8 +++--- og_ui/src/Form/OgRolePermissionsForm.php | 24 ++++++++--------- src/Entity/OgRole.php | 4 +-- src/Entity/OgRoleListBuilder.php | 12 ++++----- src/Entity/OgRoleRouteProvider.php | 4 +-- 10 files changed, 57 insertions(+), 57 deletions(-) diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 40bb23dc2..63ae150c4 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -26,14 +26,14 @@ og_ui.roles_permissions_overview: type: '^(roles|permissions)$' og_ui.roles_overview: - path: 'admin/config/group/roles/{entity_type_id}/{bundle}' + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' defaults: _entity_list: 'og_role' requirements: _permission: 'administer group' og_ui.role_add: - path: 'admin/config/group/role/{entity_type}/{bundle}/add' + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' defaults: _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupTypeRole' _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' @@ -57,7 +57,7 @@ entity.og_role.delete_form: _entity_access: 'og_role.delete' og_ui.permissions_overview: - path: 'admin/config/group/permissions/{entity_type}/{bundle}' + path: 'admin/config/group/permissions/{entity_type_id}/{bundle_id}' defaults: _form: '\Drupal\og_ui\Form\OgPermissionsForm' _title_callback: '\Drupal\og_ui\Form\OgPermissionsForm::titleCallback' @@ -65,7 +65,7 @@ og_ui.permissions_overview: _permission: 'administer group' og_ui.permissions_edit_form: - path: 'admin/config/group/permissions/{entity_type}/{bundle}/{role_name}' + path: 'admin/config/group/permissions/{entity_type_id}/{bundle_id}/{role_name}' defaults: _form: '\Drupal\og_ui\Form\OgRolePermissionsForm' _title_callback: '\Drupal\og_ui\Form\OgRolePermissionsForm::rolePermissionTitleCallback' diff --git a/og_ui/src/Controller/OgRoleController.php b/og_ui/src/Controller/OgRoleController.php index 9eba5b150..a4de5304a 100644 --- a/og_ui/src/Controller/OgRoleController.php +++ b/og_ui/src/Controller/OgRoleController.php @@ -15,22 +15,22 @@ class OgRoleController extends ControllerBase implements ContainerInjectionInter /** * Form constructor for OgRole add form. * - * @param string $entity_type + * @param string $entity_type_id * Group type. - * @param string $bundle + * @param string $bundle_id * Group bundle. * * @return array * An associative array containing: * - og_role_form: The og_role form as a renderable array. */ - public function addGroupTypeRole($entity_type, $bundle) { + public function addGroupTypeRole($entity_type_id, $bundle_id) { $build['#title'] = $this->t('Create New Role'); // Show the actual reply box. $og_role = $this->entityTypeManager()->getStorage('og_role')->create([ - 'group_type' => $entity_type, - 'group_bundle' => $bundle, + 'group_type' => $entity_type_id, + 'group_bundle' => $bundle_id, ]); $build['og_role_form'] = $this->entityFormBuilder()->getForm($og_role); diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index f1e5926c3..ca9673cfb 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -88,7 +88,7 @@ public function rolesPermissionsOverviewPage($type) { [ 'data' => Link::createFromRoute($action, 'og_ui.' . $type . '_overview', [ 'entity_type_id' => $entity_type, - 'bundle' => $bundle, + 'bundle_id' => $bundle, ]), ], ]; @@ -123,16 +123,16 @@ public function rolesPermissionsOverviewTitleCallback($type) { * * @param string $entity_type_id * The group entity type. - * @param string $bundle + * @param string $bundle_id * The group bundle. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The roles overview page title. */ - public function rolesOverviewPageTitleCallback($entity_type_id, $bundle) { + public function rolesOverviewPageTitleCallback($entity_type_id, $bundle_id) { return $this->t('OG @type - @bundle roles', [ '@type' => $this->entityTypeManager->getDefinition($entity_type_id)->getLabel(), - '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle]['label'], + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle_id]['label'], ]); } diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 6142c2d68..831eb1f8c 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -93,34 +93,34 @@ public function getFormId() { /** * Title callback for the group permissions page. * - * @param string $entity_type + * @param string $entity_type_id * The group entity type id. - * @param string $bundle + * @param string $bundle_id * The group bundle id. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The group permission title. */ - public function titleCallback($entity_type, $bundle) { + public function titleCallback($entity_type_id, $bundle_id) { return $this->t('@bundle permissions', [ - '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle_id]['label'], ]); } /** * Returns the group roles to display in the form. * - * @param string $entity_type + * @param string $entity_type_id * The group entity type id. - * @param string $bundle + * @param string $bundle_id * The group entity bundle id. * * @return array * The group roles. */ - public function getGroupRoles($entity_type, $bundle) { + public function getGroupRoles($entity_type_id, $bundle_id) { if (empty($this->roles)) { - $this->roles = $this->roleManager->getRolesByBundle($entity_type, $bundle); + $this->roles = $this->roleManager->getRolesByBundle($entity_type_id, $bundle_id); } return $this->roles; @@ -133,17 +133,17 @@ public function getGroupRoles($entity_type, $bundle) { * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. - * @param string $entity_type + * @param string $entity_type_id * The group entity type id. - * @param string $bundle + * @param string $bundle_id * The group bundle id. * * @return array * The form structure. */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '') { + public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = '', $bundle_id = '') { // Return a 404 error when this is not a group. - if (!Og::isGroup($entity_type, $bundle)) { + if (!Og::isGroup($entity_type_id, $bundle_id)) { throw new NotFoundHttpException(); } @@ -163,7 +163,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t '#sticky' => TRUE, ]; - $roles = $this->getGroupRoles($entity_type, $bundle); + $roles = $this->getGroupRoles($entity_type_id, $bundle_id); /** @var \Drupal\og\Entity\OgRole $role */ foreach ($roles as $role) { @@ -173,9 +173,9 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t ]; } - $bundles = $this->groupTypeManager->getGroupContentBundleIdsByGroupBundle($entity_type, $bundle); - $group_permissions = $this->permissionManager->getDefaultGroupPermissions($entity_type, $bundle); - $group_content_permissions = $this->permissionManager->getDefaultEntityOperationPermissions($entity_type, $bundle, $bundles); + $bundles = $this->groupTypeManager->getGroupContentBundleIdsByGroupBundle($entity_type_id, $bundle_id); + $group_permissions = $this->permissionManager->getDefaultGroupPermissions($entity_type_id, $bundle_id); + $group_content_permissions = $this->permissionManager->getDefaultEntityOperationPermissions($entity_type_id, $bundle_id, $bundles); $permissions_by_provider = [ 'Group' => $group_permissions, diff --git a/og_ui/src/Form/OgRoleDeleteForm.php b/og_ui/src/Form/OgRoleDeleteForm.php index 435fbed63..7d7dda2ed 100644 --- a/og_ui/src/Form/OgRoleDeleteForm.php +++ b/og_ui/src/Form/OgRoleDeleteForm.php @@ -17,8 +17,8 @@ public function getCancelUrl() { $entity = $this->getEntity(); return Url::fromRoute('og_ui.roles_overview', [ - 'entity_type' => $entity->group_type, - 'bundle' => $entity->group_bundle, + 'entity_type_id' => $entity->group_type, + 'bundle_id' => $entity->group_bundle, ]); } diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index b31b60cd2..9731ce370 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -104,7 +104,7 @@ public function save(array $form, FormStateInterface $form_state) { } $form_state->setRedirect('og_ui.roles_overview', [ 'entity_type_id' => $og_role->getGroupType(), - 'bundle' => $og_role->getGroupBundle(), + 'bundle_id' => $og_role->getGroupBundle(), ]); } @@ -127,16 +127,16 @@ public function editRoleTitleCallback(OgRole $og_role) { /** * The role creation page title callback. * - * @param string $bundle + * @param string $bundle_id * Entity type bundle. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * An object that, when cast to a string, returns the translated title * callback. */ - public function addRoleTitleCallback($bundle) { + public function addRoleTitleCallback($bundle_id) { return $this->t('Create %bundle OG role', [ - '%bundle' => $bundle, + '%bundle' => $bundle_id, ]); } diff --git a/og_ui/src/Form/OgRolePermissionsForm.php b/og_ui/src/Form/OgRolePermissionsForm.php index 6b720f3ba..7c204de31 100644 --- a/og_ui/src/Form/OgRolePermissionsForm.php +++ b/og_ui/src/Form/OgRolePermissionsForm.php @@ -20,9 +20,9 @@ public function getFormId() { /** * Title callback for the roles overview page. * - * @param string $entity_type + * @param string $entity_type_id * The group entity type id. - * @param string $bundle + * @param string $bundle_id * The group bundle id. * @param string $role_name * The group role name. @@ -30,15 +30,15 @@ public function getFormId() { * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The role permission form title. */ - public function rolePermissionTitleCallback($entity_type, $bundle, $role_name) { + public function rolePermissionTitleCallback($entity_type_id, $bundle_id, $role_name) { $role_id = implode('-', [ - $entity_type, - $bundle, + $entity_type_id, + $bundle_id, $role_name, ]); $role = OgRole::load($role_id); return $this->t('@bundle roles - @role permissions', [ - '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type)[$bundle]['label'], + '@bundle' => $this->entityTypeBundleInfo->getBundleInfo($entity_type_id)[$bundle_id]['label'], '@role' => $role->getLabel(), ]); } @@ -50,9 +50,9 @@ public function rolePermissionTitleCallback($entity_type, $bundle, $role_name) { * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. - * @param string $entity_type + * @param string $entity_type_id * The group entity type id. - * @param string $bundle + * @param string $bundle_id * The group bundle id. * @param string $role_name * The group role name. @@ -60,10 +60,10 @@ public function rolePermissionTitleCallback($entity_type, $bundle, $role_name) { * @return array * The form structure. */ - public function buildForm(array $form, FormStateInterface $form_state, $entity_type = '', $bundle = '', $role_name = '') { + public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = '', $bundle_id = '', $role_name = '') { $role_id = implode('-', [ - $entity_type, - $bundle, + $entity_type_id, + $bundle_id, $role_name, ]); @@ -71,7 +71,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $this->roles = [$role->id() => $role]; } - return parent::buildForm($form, $form_state, $entity_type, $bundle); + return parent::buildForm($form, $form_state, $entity_type_id, $bundle_id); } } diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 49b7a18ba..7a60712dd 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -42,10 +42,10 @@ * "weight" = "weight" * }, * links = { - * "add-form" = "/admin/config/group/role/{entity_type}/{bundle}/add", + * "collection" = "/admin/config/group/roles/{entity_type_id}/{bundle_id}", + * "add-form" = "/admin/config/group/roles/{entity_type_id}/{bundle_id}/add", * "edit-form" = "/admin/config/group/role/{og_role}/edit", * "delete-form" = "/admin/config/group/role/{og_role}/delete", - * "collection" = "/admin/config/group/roles/{entity_type_id}/{bundle}", * }, * config_export = { * "id", diff --git a/src/Entity/OgRoleListBuilder.php b/src/Entity/OgRoleListBuilder.php index 77403647c..cfd46d04e 100644 --- a/src/Entity/OgRoleListBuilder.php +++ b/src/Entity/OgRoleListBuilder.php @@ -66,8 +66,8 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter if ($parameters->has('entity_type_id')) { $this->groupType = $parameters->get('entity_type_id'); } - if ($parameters->has('bundle')) { - $this->groupBundle = $parameters->get('bundle'); + if ($parameters->has('bundle_id')) { + $this->groupBundle = $parameters->get('bundle_id'); } } } @@ -123,8 +123,8 @@ public function getDefaultOperations(EntityInterface $role) { 'title' => t('Edit permissions'), 'weight' => 20, 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ - 'entity_type' => $this->groupType, - 'bundle' => $this->groupBundle, + 'entity_type_id' => $this->groupType, + 'bundle_id' => $this->groupBundle, 'role_name' => $role->getName(), ]), ]; @@ -154,8 +154,8 @@ public function render() { $build = parent::render(); $build['entities']['#empty'] = $this->t('There are no OG roles available yet. Add an OG role.', [ '@link' => Url::fromRoute('entity.og_role.add_form', [ - 'entity_type' => $this->groupType, - 'bundle' => $this->groupBundle, + 'entity_type_id' => $this->groupType, + 'bundle_id' => $this->groupBundle, ])->toString(), ]); diff --git a/src/Entity/OgRoleRouteProvider.php b/src/Entity/OgRoleRouteProvider.php index e30510ef5..ddd524f1b 100644 --- a/src/Entity/OgRoleRouteProvider.php +++ b/src/Entity/OgRoleRouteProvider.php @@ -15,8 +15,8 @@ class OgRoleRouteProvider extends AdminHtmlRouteProvider { */ protected function getAddFormRoute(EntityTypeInterface $entity_type) { if ($route = parent::getAddFormRoute($entity_type)) { - $route->setOption('parameters', ['entity_type' => ['type' => 'entity:{entity_type}']]) - ->setOption('parameters', ['bundle' => ['type' => '{entity_type}:{bundle}']]); + $route->setOption('parameters', ['entity_type_id' => ['type' => 'entity:{entity_type_id}']]) + ->setOption('parameters', ['bundle_id' => ['type' => '{entity_type}:{bundle_id}']]); return $route; } } From 7a3c87d029163965f41e86278345e6dcaa4e2da2 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 02:30:06 +0100 Subject: [PATCH 42/88] Stick to entity yaml routes for roles --- og_ui/og_ui.links.action.yml | 6 ++-- og_ui/og_ui.routing.yml | 9 ++--- og_ui/src/Controller/OgRoleController.php | 40 ----------------------- og_ui/src/Form/OgRoleForm.php | 16 --------- src/Entity/OgRole.php | 3 -- 5 files changed, 8 insertions(+), 66 deletions(-) delete mode 100644 og_ui/src/Controller/OgRoleController.php diff --git a/og_ui/og_ui.links.action.yml b/og_ui/og_ui.links.action.yml index adf690e6f..bef396cc5 100644 --- a/og_ui/og_ui.links.action.yml +++ b/og_ui/og_ui.links.action.yml @@ -1,5 +1,5 @@ -og_ui.role_add: - route_name: og_ui.role_add +entity.og_role.add_form: + route_name: entity.og_role.add_form title: 'Add role' appears_on: - - og_ui.roles_overview + - entity.og_role.collection diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 63ae150c4..5a58b3c4b 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -25,18 +25,19 @@ og_ui.roles_permissions_overview: _permission: 'administer group' type: '^(roles|permissions)$' -og_ui.roles_overview: +entity.og_role.collection: path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' defaults: _entity_list: 'og_role' + _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' requirements: _permission: 'administer group' -og_ui.role_add: +entity.og_role.add_form: path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' defaults: - _controller: '\Drupal\og_ui\Controller\OgRoleController::addGroupTypeRole' - _title_callback: '\Drupal\og_ui\Form\OgRoleForm::addRoleTitleCallback' + _entity_form: og_role.default + _title: 'Add role' requirements: _permission: 'administer group' diff --git a/og_ui/src/Controller/OgRoleController.php b/og_ui/src/Controller/OgRoleController.php deleted file mode 100644 index a4de5304a..000000000 --- a/og_ui/src/Controller/OgRoleController.php +++ /dev/null @@ -1,40 +0,0 @@ -t('Create New Role'); - - // Show the actual reply box. - $og_role = $this->entityTypeManager()->getStorage('og_role')->create([ - 'group_type' => $entity_type_id, - 'group_bundle' => $bundle_id, - ]); - $build['og_role_form'] = $this->entityFormBuilder()->getForm($og_role); - - return $build; - } - -} diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 9731ce370..414582a99 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -124,20 +124,4 @@ public function editRoleTitleCallback(OgRole $og_role) { ]); } - /** - * The role creation page title callback. - * - * @param string $bundle_id - * Entity type bundle. - * - * @return \Drupal\Core\StringTranslation\TranslatableMarkup - * An object that, when cast to a string, returns the translated title - * callback. - */ - public function addRoleTitleCallback($bundle_id) { - return $this->t('Create %bundle OG role', [ - '%bundle' => $bundle_id, - ]); - } - } diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 7a60712dd..7cad54f2e 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -29,9 +29,6 @@ * "delete" = "Drupal\og_ui\Form\OgRoleDeleteForm", * "edit" = "Drupal\og_ui\Form\OgRoleForm", * }, - * "route_provider" = { - * "html" = "Drupal\og\Entity\OgRoleRouteProvider", - * }, * "list_builder" = "Drupal\og\Entity\OgRoleListBuilder", * }, * admin_permission = "administer group", From 2697c8c6d4e61a2744b3859397d778f96532962e Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 02:53:09 +0100 Subject: [PATCH 43/88] Fix redirects and role add machine name form --- og_ui/og_ui.routing.yml | 1 - og_ui/src/Form/OgRoleDeleteForm.php | 9 +++++---- og_ui/src/Form/OgRoleForm.php | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 5a58b3c4b..88815848c 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -53,7 +53,6 @@ entity.og_role.delete_form: path: 'admin/config/group/role/{og_role}/delete' defaults: _entity_form: og_role.delete - _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' requirements: _entity_access: 'og_role.delete' diff --git a/og_ui/src/Form/OgRoleDeleteForm.php b/og_ui/src/Form/OgRoleDeleteForm.php index 7d7dda2ed..ce60ce74c 100644 --- a/og_ui/src/Form/OgRoleDeleteForm.php +++ b/og_ui/src/Form/OgRoleDeleteForm.php @@ -14,11 +14,12 @@ class OgRoleDeleteForm extends EntityDeleteForm { * {@inheritdoc} */ public function getCancelUrl() { - $entity = $this->getEntity(); + /** @var \Drupal\og\Entity\OgRole $role */ + $role = $this->getEntity(); - return Url::fromRoute('og_ui.roles_overview', [ - 'entity_type_id' => $entity->group_type, - 'bundle_id' => $entity->group_bundle, + return Url::fromRoute('entity.og_role.collection', [ + 'entity_type_id' => $role->getGroupType(), + 'bundle_id' => $role->getGroupBundle(), ]); } diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 414582a99..296969456 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -5,7 +5,9 @@ use Drupal\Core\Entity\EntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\og\Entity\OgRole; +use Drupal\og\Og; use Drupal\og\OgRoleInterface; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Form to add or edit an OG role. @@ -22,8 +24,16 @@ class OgRoleForm extends EntityForm { /** * {@inheritdoc} */ - public function form(array $form, FormStateInterface $form_state) { + public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = '', $bundle_id = '') { + // Return a 404 error when this is not a group. + if (!Og::isGroup($entity_type_id, $bundle_id)) { + throw new NotFoundHttpException(); + } + $og_role = $this->entity; + $og_role->setGroupType($entity_type_id); + $og_role->setGroupBundle($bundle_id); + $form['label'] = [ '#type' => 'textfield', '#title' => $this->t('Role name'), @@ -56,7 +66,7 @@ public function form(array $form, FormStateInterface $form_state) { '#value' => OgRoleInterface::ROLE_TYPE_STANDARD, ]; - return parent::form($form, $form_state, $og_role); + return parent::buildForm($form, $form_state, $og_role); } /** @@ -102,7 +112,8 @@ public function save(array $form, FormStateInterface $form_state) { drupal_set_message($this->t('OG role %label has been added.', ['%label' => $og_role->label()])); $this->logger('user')->notice('OG role %label has been added.', ['%label' => $og_role->label(), 'link' => $edit_link]); } - $form_state->setRedirect('og_ui.roles_overview', [ + // Cannot use $og_role->url() because we need to pass mandatory parameters. + $form_state->setRedirect('entity.og_role.collection', [ 'entity_type_id' => $og_role->getGroupType(), 'bundle_id' => $og_role->getGroupBundle(), ]); From e7408e71e0f78b790443c55b1a1e8e72149e2d62 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 02:54:48 +0100 Subject: [PATCH 44/88] Code style --- og_ui/src/Form/OgRoleForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 296969456..cda905ec7 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -78,7 +78,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t * @param string $role_name * The role name. * - * @return OgRole|NULL + * @return \Drupal\og\Entity\OgRole|null * The OG role if it exists. NULL otherwise. */ public function exists($role_name) { From 09d41ebf8c887df2c8cfa963a836457e3b550db4 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 03:07:14 +0100 Subject: [PATCH 45/88] Improve permissions page when no group content permissions available --- og_ui/src/Form/OgPermissionsForm.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 831eb1f8c..170f103ed 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -179,9 +179,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $permissions_by_provider = [ 'Group' => $group_permissions, - 'Group content' => $group_content_permissions, ]; + if (!empty($group_content_permissions)) { + $permissions_by_provider['Group content'] = $group_content_permissions; + } + foreach ($permissions_by_provider as $provider => $permissions) { // Provider. $form['permissions'][$provider] = [ From d3e628b7f92a43f45b7983eae6e88ada97896f5f Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Sat, 29 Apr 2017 03:11:09 +0100 Subject: [PATCH 46/88] Fix role edit form returning 404 post-tweaks --- og_ui/src/Form/OgRoleForm.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index cda905ec7..0af6ca3f8 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -25,14 +25,18 @@ class OgRoleForm extends EntityForm { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = '', $bundle_id = '') { - // Return a 404 error when this is not a group. - if (!Og::isGroup($entity_type_id, $bundle_id)) { - throw new NotFoundHttpException(); + $og_role = $this->entity; + + if ($og_role->isNew()) { + // Return a 404 error when this is not a group. + if (!Og::isGroup($entity_type_id, $bundle_id)) { + throw new NotFoundHttpException(); + } + + $og_role->setGroupType($entity_type_id); + $og_role->setGroupBundle($bundle_id); } - $og_role = $this->entity; - $og_role->setGroupType($entity_type_id); - $og_role->setGroupBundle($bundle_id); $form['label'] = [ '#type' => 'textfield', From 90833eb6baf8461d4d0133cccf62ff6a90a43691 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 2 May 2017 21:56:49 +0100 Subject: [PATCH 47/88] Use better OgRole fetching method --- og_ui/src/Form/OgRoleForm.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 0af6ca3f8..fa5e16261 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -37,7 +37,6 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $og_role->setGroupBundle($bundle_id); } - $form['label'] = [ '#type' => 'textfield', '#title' => $this->t('Role name'), @@ -87,13 +86,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t */ public function exists($role_name) { $og_role = $this->entity; - $role_id = implode('-', [ - $og_role->getGroupType(), - $og_role->getGroupBundle(), - $role_name, - ]); - - return OgRole::load($role_id); + return OgRole::getRole($og_role->getGroupType(), $og_role->getGroupBundle(), $role_name); } /** From ff1aaf27ed2ff4e2856e2ea454ac4adb5f3c207e Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 12 May 2017 13:09:52 +0100 Subject: [PATCH 48/88] Fix roles overview menu link --- og_ui/og_ui.links.menu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/og_ui.links.menu.yml b/og_ui/og_ui.links.menu.yml index 41b603b64..4ad455538 100644 --- a/og_ui/og_ui.links.menu.yml +++ b/og_ui/og_ui.links.menu.yml @@ -12,7 +12,7 @@ og_ui.settings: description: 'Administer OG settings.' route_name: og_ui.settings -og_ui.roles_overview: +og_ui.roles_permissions_overview: title: 'OG roles' parent: og_ui.admin_index description: 'Administer OG roles.' From add6c3a1fc43f95c7ee455265b648279ff9cd591 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Fri, 12 May 2017 14:04:22 +0100 Subject: [PATCH 49/88] Fix route on roles permissions overview page --- og_ui/src/Controller/OgUiController.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index ca9673cfb..51f0e1c15 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -72,6 +72,7 @@ public static function create(ContainerInterface $container) { * The overview as a render array. */ public function rolesPermissionsOverviewPage($type) { + $route = $type === 'roles' ? 'entity.og_role.collection' : 'og_ui.permissions_overview'; $action = $type === 'roles' ? t('Edit roles') : t('Edit permissions'); $header = [t('Group type'), t('Operations')]; $rows = []; @@ -86,7 +87,7 @@ public function rolesPermissionsOverviewPage($type) { 'data' => $definition->getLabel() . ' - ' . $bundle_info[$bundle]['label'], ], [ - 'data' => Link::createFromRoute($action, 'og_ui.' . $type . '_overview', [ + 'data' => Link::createFromRoute($action, $route, [ 'entity_type_id' => $entity_type, 'bundle_id' => $bundle, ]), From 70611e57898fb1b004117164ee462f96ae76b172 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Mon, 27 Nov 2017 23:49:37 +0000 Subject: [PATCH 50/88] Fix docblock --- src/OgRoleInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OgRoleInterface.php b/src/OgRoleInterface.php index fccc07f16..0eefab66e 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -126,7 +126,7 @@ public function getRoleType(); */ public function setRoleType($role_type); - /* + /** * Returns whether or not a role can be changed. * * This will return FALSE for all roles except the default roles 'non-member' From 1c91e5efaeba78395d5ecaaeee91179f62f8fe94 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 28 Nov 2017 00:19:58 +0000 Subject: [PATCH 51/88] Allow permission grouping by provider Custom modules can group their permissions in a separate group --- og_ui/src/Form/OgPermissionsForm.php | 30 ++++++++++++++++++++++++---- src/Permission.php | 25 +++++++++++++++++++++++ src/PermissionInterface.php | 17 ++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 170f103ed..abf31d941 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -2,6 +2,7 @@ namespace Drupal\og_ui\Form; +use Drupal\Component\Utility\Html; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -178,21 +179,41 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $group_content_permissions = $this->permissionManager->getDefaultEntityOperationPermissions($entity_type_id, $bundle_id, $bundles); $permissions_by_provider = [ - 'Group' => $group_permissions, + 'Group' => [], + 'Group content' => [], ]; - if (!empty($group_content_permissions)) { - $permissions_by_provider['Group content'] = $group_content_permissions; + foreach ($group_permissions as $permission) { + if (!empty($permission->getProvider())) { + $permissions_by_provider[$permission->getProvider()][$permission->getName()] = $permission; + } + else { + $permissions_by_provider['Group'][$permission->getName()] = $permission; + } + } + + foreach ($group_content_permissions as $permission) { + if (!empty($permission->getProvider())) { + $permissions_by_provider[$permission->getProvider()][$permission->getName()] = $permission; + } + else { + $permissions_by_provider['Group content'][$permission->getName()] = $permission; + } } foreach ($permissions_by_provider as $provider => $permissions) { + // Skip empty permission provider groups. + if (empty($permissions)) { + continue; + } + // Provider. $form['permissions'][$provider] = [ [ '#wrapper_attributes' => [ 'colspan' => count($roles) + 1, 'class' => ['module'], - 'id' => 'provider-' . $provider, + 'id' => 'provider-' . Html::getId($provider), ], '#markup' => $provider, ], @@ -221,6 +242,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description']; $form['permissions'][$perm]['description']['#context']['warning'] = $perm_item['warning']; } + foreach ($roles as $rid => $role) { list(,, $rid_simple) = explode('-', $rid, 3); diff --git a/src/Permission.php b/src/Permission.php index eb06ffc64..825f09fe3 100644 --- a/src/Permission.php +++ b/src/Permission.php @@ -35,6 +35,16 @@ abstract class Permission implements PermissionInterface { */ protected $defaultRoles = []; + /** + * Permission provider. + * + * Defaults to 'Group' for GroupPermission and + * 'Group content' for GroupContentOperationPermission. + * + * @var string + */ + protected $provider = ''; + /** * If the permission is security sensitive and should be limited to admins. * @@ -149,6 +159,21 @@ public function setRestrictAccess($access) { return $this; } + /** + * {@inheritdoc} + */ + public function getProvider() { + return $this->get('provider'); + } + + /** + * {@inheritdoc} + */ + public function setProvider($provider) { + $this->set('provider', $provider); + return $this; + } + /** * Validates the given property and value. * diff --git a/src/PermissionInterface.php b/src/PermissionInterface.php index f1abbf7c2..b58f0533b 100644 --- a/src/PermissionInterface.php +++ b/src/PermissionInterface.php @@ -119,4 +119,21 @@ public function getRestrictAccess(); */ public function setRestrictAccess($access); + /** + * Returns the provider. + * + * @return string + * The provider. + */ + public function getProvider(); + + /** + * Sets the provider. + * + * @param string $description + * The provider. + * + * @return $this + */ + public function setProvider($description); } From 1b1c8cbf6b999288ab1217a03bfef2e2a1d0131c Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 28 Nov 2017 00:20:32 +0000 Subject: [PATCH 52/88] Reflect the roles weight on the permissions page --- og_ui/src/Form/OgPermissionsForm.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index abf31d941..3df68e300 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -166,6 +166,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $roles = $this->getGroupRoles($entity_type_id, $bundle_id); + uasort($roles, function ($a, $b) { + if ($a->getWeight() == $b->getWeight()) { + return 0; + } + return ($a->getWeight() < $b->getWeight()) ? -1 : 1; + }); + /** @var \Drupal\og\Entity\OgRole $role */ foreach ($roles as $role) { $form['permissions']['#header'][] = [ From 3132b2b9fbe7b5d43622fc9c66579414330b8af1 Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Tue, 28 Nov 2017 00:34:34 +0000 Subject: [PATCH 53/88] Lint --- src/PermissionInterface.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PermissionInterface.php b/src/PermissionInterface.php index b58f0533b..dca800a48 100644 --- a/src/PermissionInterface.php +++ b/src/PermissionInterface.php @@ -130,10 +130,11 @@ public function getProvider(); /** * Sets the provider. * - * @param string $description + * @param string $provider * The provider. * * @return $this */ - public function setProvider($description); + public function setProvider($provider); + } From 15e9536ffe67eaf3d696388362f20de8e3c9555d Mon Sep 17 00:00:00 2001 From: Dan Braghis Date: Wed, 25 Apr 2018 09:23:24 +0100 Subject: [PATCH 54/88] Add message on save --- og_ui/src/Form/OgPermissionsForm.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 3df68e300..dedbcfc43 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -330,6 +330,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $role->save(); } + + drupal_set_message($this->t('The changes have been saved.')); } } From 79cbd4e61cb14c9a50b44f544b80fd5707cdf813 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Tue, 10 Jul 2018 10:41:15 +0200 Subject: [PATCH 55/88] Instead of crashing when a entity definition doesn't exist, log an error and skip the missing entity type. --- og_ui/src/Controller/OgUiController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 51f0e1c15..742346b4b 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -2,6 +2,7 @@ namespace Drupal\og_ui\Controller; +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; @@ -79,7 +80,20 @@ public function rolesPermissionsOverviewPage($type) { $build = []; foreach ($this->groupTypeManager->getAllGroupBundles() as $entity_type => $bundles) { - $definition = $this->entityTypeManager->getDefinition($entity_type); + try { + $definition = $this->entityTypeManager->getDefinition($entity_type); + } + catch (PluginNotFoundException $e) { + // The entity type manager might throw this exception if the entity type + // is not defined. If this happens it means there is a discrepancy + // between the group types in config, and the modules that providing + // these entity types. This is not something we can rectify here but it + // does not block the rendering of the page. In the rare case that this + // occurs, let's log an error and exclude the entity type from the page. + $this->getLogger('og')->error('Error: the %entity_type entity type is not defined but is supposed to have group bundles.', ['%entity_type' => $entity_type]); + continue; + } + $bundle_info = $this->entityTypeBundleInfo->getBundleInfo($entity_type); foreach ($bundles as $bundle) { $rows[] = [ From 8c21354a809460b8ea7742e294054d2b5170eb76 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Tue, 10 Jul 2018 10:41:38 +0200 Subject: [PATCH 56/88] This table doesn't only represent roles, but also permissions. --- og_ui/src/Controller/OgUiController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 742346b4b..191e28bdc 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -110,7 +110,7 @@ public function rolesPermissionsOverviewPage($type) { } } - $build['roles_table'] = [ + $build['roles_permissions_table'] = [ '#theme' => 'table', '#header' => $header, '#rows' => $rows, From 8de6aa8a9dbfa2a69c5b10c58a3bd3cd7d3ea3f4 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 12 Jul 2018 21:45:37 +0200 Subject: [PATCH 57/88] Update documentation. --- og_ui/src/Controller/OgUiController.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index 191e28bdc..2c6db2c9d 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -137,12 +137,15 @@ public function rolesPermissionsOverviewTitleCallback($type) { * Title callback for the roles overview page. * * @param string $entity_type_id - * The group entity type. + * The group entity type ID. * @param string $bundle_id - * The group bundle. + * The group bundle ID. * * @return \Drupal\Core\StringTranslation\TranslatableMarkup * The roles overview page title. + * + * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException + * Thrown when the entity type with the given ID is not defined. */ public function rolesOverviewPageTitleCallback($entity_type_id, $bundle_id) { return $this->t('OG @type - @bundle roles', [ From 3f3516bc32ee1860246e46d87f8cb15e05a0bd20 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 12 Jul 2018 21:46:04 +0200 Subject: [PATCH 58/88] Add type hints to closure arguments. --- og_ui/src/Form/OgPermissionsForm.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index dedbcfc43..e2cfbdb3e 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -10,6 +10,7 @@ use Drupal\og\Og; use Drupal\og\OgRoleManagerInterface; use Drupal\og\PermissionManagerInterface; +use Drupal\user\RoleInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -166,7 +167,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t $roles = $this->getGroupRoles($entity_type_id, $bundle_id); - uasort($roles, function ($a, $b) { + uasort($roles, function (RoleInterface $a, RoleInterface $b) { if ($a->getWeight() == $b->getWeight()) { return 0; } From 2c40084e72a758507e1bb122906347ae311ac54a Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 21 Dec 2018 17:09:39 +0100 Subject: [PATCH 59/88] Move og_role routes to og module. --- og.routing.yml | 31 +++++++++++++++++++++++++++++++ og_ui/og_ui.routing.yml | 31 ------------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/og.routing.yml b/og.routing.yml index 06a78558e..67611f0ff 100644 --- a/og.routing.yml +++ b/og.routing.yml @@ -43,3 +43,34 @@ og.remove_multiple_roles_confirm: _form: '\Drupal\og\Form\OgRemoveMultipleRolesForm' requirements: _custom_access: '\Drupal\og\Form\OgRemoveMultipleRolesForm::access' + +entity.og_role.collection: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' + defaults: + _entity_list: 'og_role' + _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' + requirements: + _permission: 'administer group' + +entity.og_role.add_form: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' + defaults: + _entity_form: og_role.default + _title: 'Add role' + requirements: + _permission: 'administer group' + +entity.og_role.edit_form: + path: 'admin/config/group/role/{og_role}/edit' + defaults: + _entity_form: og_role.default + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' + requirements: + _entity_access: 'og_role.update' + +entity.og_role.delete_form: + path: 'admin/config/group/role/{og_role}/delete' + defaults: + _entity_form: og_role.delete + requirements: + _entity_access: 'og_role.delete' diff --git a/og_ui/og_ui.routing.yml b/og_ui/og_ui.routing.yml index 88815848c..8090aaaaa 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -25,37 +25,6 @@ og_ui.roles_permissions_overview: _permission: 'administer group' type: '^(roles|permissions)$' -entity.og_role.collection: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' - defaults: - _entity_list: 'og_role' - _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' - requirements: - _permission: 'administer group' - -entity.og_role.add_form: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' - defaults: - _entity_form: og_role.default - _title: 'Add role' - requirements: - _permission: 'administer group' - -entity.og_role.edit_form: - path: 'admin/config/group/role/{og_role}/edit' - defaults: - _entity_form: og_role.default - _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' - requirements: - _entity_access: 'og_role.update' - -entity.og_role.delete_form: - path: 'admin/config/group/role/{og_role}/delete' - defaults: - _entity_form: og_role.delete - requirements: - _entity_access: 'og_role.delete' - og_ui.permissions_overview: path: 'admin/config/group/permissions/{entity_type_id}/{bundle_id}' defaults: From a0379dad2bf8124f5903d145a526c20cd0e1b9ac Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 21 Dec 2018 17:46:43 +0100 Subject: [PATCH 60/88] Move og entity routes to top of file. --- og.routing.yml | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/og.routing.yml b/og.routing.yml index 67611f0ff..10e8ab6e4 100644 --- a/og.routing.yml +++ b/og.routing.yml @@ -1,5 +1,36 @@ # Routes for Organic groups. +entity.og_role.collection: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' + defaults: + _entity_list: 'og_role' + _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' + requirements: + _permission: 'administer group' + +entity.og_role.add_form: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' + defaults: + _entity_form: og_role.default + _title: 'Add role' + requirements: + _permission: 'administer group' + +entity.og_role.edit_form: + path: 'admin/config/group/role/{og_role}/edit' + defaults: + _entity_form: og_role.default + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' + requirements: + _entity_access: 'og_role.update' + +entity.og_role.delete_form: + path: 'admin/config/group/role/{og_role}/delete' + defaults: + _entity_form: og_role.delete + requirements: + _entity_access: 'og_role.delete' + og.subscribe: path: 'group/{entity_type_id}/{group}/subscribe/{membership_type}' defaults: @@ -44,33 +75,3 @@ og.remove_multiple_roles_confirm: requirements: _custom_access: '\Drupal\og\Form\OgRemoveMultipleRolesForm::access' -entity.og_role.collection: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' - defaults: - _entity_list: 'og_role' - _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' - requirements: - _permission: 'administer group' - -entity.og_role.add_form: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' - defaults: - _entity_form: og_role.default - _title: 'Add role' - requirements: - _permission: 'administer group' - -entity.og_role.edit_form: - path: 'admin/config/group/role/{og_role}/edit' - defaults: - _entity_form: og_role.default - _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' - requirements: - _entity_access: 'og_role.update' - -entity.og_role.delete_form: - path: 'admin/config/group/role/{og_role}/delete' - defaults: - _entity_form: og_role.delete - requirements: - _entity_access: 'og_role.delete' From 7d17371eaeb4ba06a608cac2846f6a43e02c834e Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 21 Dec 2018 18:10:19 +0100 Subject: [PATCH 61/88] Revert last commit. --- og.routing.yml | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/og.routing.yml b/og.routing.yml index 10e8ab6e4..67611f0ff 100644 --- a/og.routing.yml +++ b/og.routing.yml @@ -1,36 +1,5 @@ # Routes for Organic groups. -entity.og_role.collection: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' - defaults: - _entity_list: 'og_role' - _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' - requirements: - _permission: 'administer group' - -entity.og_role.add_form: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' - defaults: - _entity_form: og_role.default - _title: 'Add role' - requirements: - _permission: 'administer group' - -entity.og_role.edit_form: - path: 'admin/config/group/role/{og_role}/edit' - defaults: - _entity_form: og_role.default - _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' - requirements: - _entity_access: 'og_role.update' - -entity.og_role.delete_form: - path: 'admin/config/group/role/{og_role}/delete' - defaults: - _entity_form: og_role.delete - requirements: - _entity_access: 'og_role.delete' - og.subscribe: path: 'group/{entity_type_id}/{group}/subscribe/{membership_type}' defaults: @@ -75,3 +44,33 @@ og.remove_multiple_roles_confirm: requirements: _custom_access: '\Drupal\og\Form\OgRemoveMultipleRolesForm::access' +entity.og_role.collection: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' + defaults: + _entity_list: 'og_role' + _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' + requirements: + _permission: 'administer group' + +entity.og_role.add_form: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' + defaults: + _entity_form: og_role.default + _title: 'Add role' + requirements: + _permission: 'administer group' + +entity.og_role.edit_form: + path: 'admin/config/group/role/{og_role}/edit' + defaults: + _entity_form: og_role.default + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' + requirements: + _entity_access: 'og_role.update' + +entity.og_role.delete_form: + path: 'admin/config/group/role/{og_role}/delete' + defaults: + _entity_form: og_role.delete + requirements: + _entity_access: 'og_role.delete' From e55d9eec5c65d345230b414a9318a914c3ed6a30 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:30:12 +0200 Subject: [PATCH 62/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index e2cfbdb3e..1415bf32b 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -50,7 +50,7 @@ class OgPermissionsForm extends FormBase { /** * The group roles. * - * @var array + * @var \Drupal\og\OgRoleInterface[]|\Drupal\user\RoleInterface[] */ protected $roles; From 04c804033077e4460fcece58dab2a96f878acb29 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:32:10 +0200 Subject: [PATCH 63/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 1415bf32b..a48c8501f 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -55,7 +55,7 @@ class OgPermissionsForm extends FormBase { protected $roles; /** - * Constructs a new UserPermissionsForm. + * Constructs a new OgPermissionsForm. * * @param \Drupal\og\PermissionManagerInterface $permission_manager * The OG permission handler. From 38b3558861e35025dd27e1b165fc58cc52f03375 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:32:51 +0200 Subject: [PATCH 64/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index a48c8501f..30436e350 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -120,7 +120,7 @@ public function titleCallback($entity_type_id, $bundle_id) { * @return array * The group roles. */ - public function getGroupRoles($entity_type_id, $bundle_id) { + protected function getGroupRoles($entity_type_id, $bundle_id) { if (empty($this->roles)) { $this->roles = $this->roleManager->getRolesByBundle($entity_type_id, $bundle_id); } From 4eb68c2d8578599277ea9df9f11261cb11ca66a3 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:34:25 +0200 Subject: [PATCH 65/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 30436e350..13f8822f5 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -16,6 +16,8 @@ /** * Provide the group permissions form. + * + * @see \Drupal\user\Form\UserPermissionsForm */ class OgPermissionsForm extends FormBase { From 4cdcfb5a1aaf03377ee75dcf5e30b8f49efafec7 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:35:36 +0200 Subject: [PATCH 66/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 13f8822f5..1d51bb9d7 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -217,7 +217,6 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t continue; } - // Provider. $form['permissions'][$provider] = [ [ '#wrapper_attributes' => [ From 22b9e0e72853370e74881da8528f2b7a1b0d9f23 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:38:04 +0200 Subject: [PATCH 67/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 1d51bb9d7..2a5efbc6e 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -253,7 +253,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t } foreach ($roles as $rid => $role) { - list(,, $rid_simple) = explode('-', $rid, 3); + $rid_simple = $role->getName(); // The roles property indicates which roles the permission applies to. $permission_applies = TRUE; From 35759728314b1e5fa1f5c0f399f40553f7deb612 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:43:07 +0200 Subject: [PATCH 68/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 2a5efbc6e..43a0f19e1 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -314,7 +314,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t */ public function submitForm(array &$form, FormStateInterface $form_state) { - /** @var \Drupal\og\Entity\OgRole $role */ + /** + * The group roles. + * + * @var \Drupal\og\Entity\OgRole + */ + protected $roles; foreach ($this->roles as $rid => $role) { if (!$form_state->hasValue($rid)) { continue; From be6d20c2d3f656f45577b3f7c9ee1742889a7955 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 08:49:08 +0200 Subject: [PATCH 69/88] Apply suggestions from code review --- og_ui/src/Form/OgPermissionsForm.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 43a0f19e1..2ac2ffcc3 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -314,12 +314,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t */ public function submitForm(array &$form, FormStateInterface $form_state) { - /** - * The group roles. - * - * @var \Drupal\og\Entity\OgRole - */ - protected $roles; + /** @var \Drupal\og\Entity\OgRole $roles */ foreach ($this->roles as $rid => $role) { if (!$form_state->hasValue($rid)) { continue; From 11b12ea980c64b42c65aad68fa3d550fb1872ff0 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 09:00:15 +0200 Subject: [PATCH 70/88] Apply suggestions from code review --- og_ui/src/Form/OgPermissionsForm.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 2ac2ffcc3..d1de6054c 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -229,7 +229,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t ]; /** @var \Drupal\og\Permission $permission */ - foreach ($permissions as $perm => $permission) { + foreach ($permissions as $permission_name => $permission) { // Fill in default values for the permission. $perm_item = [ 'title' => $permission->getTitle(), @@ -238,7 +238,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t 'warning' => $permission->getRestrictAccess() ? $this->t('Warning: Give to trusted roles only; this permission has security implications.') : '', ]; - $form['permissions'][$perm]['description'] = [ + $form['permissions'][$permission_name]['description'] = [ '#type' => 'inline_template', '#template' => '
{{ title }}{% if description or warning %}
{% if warning %}{{ warning }} {% endif %}{{ description }}
{% endif %}
', '#context' => [ @@ -248,8 +248,8 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t // Show the permission description. if (!$hide_descriptions) { - $form['permissions'][$perm]['description']['#context']['description'] = $perm_item['description']; - $form['permissions'][$perm]['description']['#context']['warning'] = $perm_item['warning']; + $form['permissions'][$permission_name]['description']['#context']['description'] = $perm_item['description']; + $form['permissions'][$permission_name]['description']['#context']['warning'] = $perm_item['warning']; } foreach ($roles as $rid => $role) { @@ -263,28 +263,28 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t } if ($permission_applies) { - $form['permissions'][$perm][$rid] = [ + $form['permissions'][$permission_name][$rid] = [ '#title' => $role->getName() . ': ' . $perm_item['title'], '#title_display' => 'invisible', '#wrapper_attributes' => [ 'class' => ['checkbox'], ], '#type' => 'checkbox', - '#default_value' => $role->hasPermission($perm) ? 1 : 0, + '#default_value' => $role->hasPermission($permission_name) ? 1 : 0, '#attributes' => ['class' => ['rid-' . $rid, 'js-rid-' . $rid]], - '#parents' => [$rid, $perm], + '#parents' => [$rid, $permission_name], ]; // Show a column of disabled but checked checkboxes. // Only applies to admins or default roles. if ($roles[$rid]->get('is_admin') || in_array($rid_simple, $permission->getDefaultRoles())) { - $form['permissions'][$perm][$rid]['#disabled'] = TRUE; - $form['permissions'][$perm][$rid]['#default_value'] = TRUE; + $form['permissions'][$permission_name][$rid]['#disabled'] = TRUE; + $form['permissions'][$permission_name][$rid]['#default_value'] = TRUE; } } else { - $form['permissions'][$perm][$rid] = [ + $form['permissions'][$permission_name][$rid] = [ '#title' => $role->getName() . ': ' . $perm_item['title'], '#title_display' => 'invisible', '#wrapper_attributes' => [ From b9f4821c97f007b8d9e78ec0d2629771da4a717f Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 24 Apr 2019 10:06:43 +0200 Subject: [PATCH 71/88] Apply suggestions from code review --- og_ui/src/Form/OgPermissionsForm.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index d1de6054c..a3eff25e5 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -6,6 +6,7 @@ use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\og\GroupPermission; use Drupal\og\GroupTypeManager; use Drupal\og\Og; use Drupal\og\OgRoleManagerInterface; @@ -257,8 +258,8 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t // The roles property indicates which roles the permission applies to. $permission_applies = TRUE; - if (property_exists($permission, 'roles')) { - $target_roles = $permission->get('roles'); + if ($permission instanceof GroupPermission) { + $target_roles = $permission->getApplicableRoles(); $permission_applies = empty($target_roles) || in_array($rid_simple, $target_roles); } From 7398389ae66882d140a81073ba30333ddaba7c55 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Sun, 12 May 2019 23:41:52 +0200 Subject: [PATCH 72/88] Update og.routing.yml moved entity routes to the top of og.routing.yml --- og.routing.yml | 64 ++++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/og.routing.yml b/og.routing.yml index 67611f0ff..1b6d5b8ae 100644 --- a/og.routing.yml +++ b/og.routing.yml @@ -1,5 +1,38 @@ # Routes for Organic groups. +# OgRole entity routes. + +entity.og_role.collection: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' + defaults: + _entity_list: 'og_role' + _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' + requirements: + _permission: 'administer group' + +entity.og_role.add_form: + path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' + defaults: + _entity_form: og_role.default + _title: 'Add role' + requirements: + _permission: 'administer group' + +entity.og_role.edit_form: + path: 'admin/config/group/role/{og_role}/edit' + defaults: + _entity_form: og_role.default + _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' + requirements: + _entity_access: 'og_role.update' + +entity.og_role.delete_form: + path: 'admin/config/group/role/{og_role}/delete' + defaults: + _entity_form: og_role.delete + requirements: + _entity_access: 'og_role.delete' + og.subscribe: path: 'group/{entity_type_id}/{group}/subscribe/{membership_type}' defaults: @@ -43,34 +76,3 @@ og.remove_multiple_roles_confirm: _form: '\Drupal\og\Form\OgRemoveMultipleRolesForm' requirements: _custom_access: '\Drupal\og\Form\OgRemoveMultipleRolesForm::access' - -entity.og_role.collection: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}' - defaults: - _entity_list: 'og_role' - _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' - requirements: - _permission: 'administer group' - -entity.og_role.add_form: - path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' - defaults: - _entity_form: og_role.default - _title: 'Add role' - requirements: - _permission: 'administer group' - -entity.og_role.edit_form: - path: 'admin/config/group/role/{og_role}/edit' - defaults: - _entity_form: og_role.default - _title_callback: '\Drupal\og_ui\Form\OgRoleForm::editRoleTitleCallback' - requirements: - _entity_access: 'og_role.update' - -entity.og_role.delete_form: - path: 'admin/config/group/role/{og_role}/delete' - defaults: - _entity_form: og_role.delete - requirements: - _entity_access: 'og_role.delete' From f5ed38da662e068abe1e397aac512d2263a1ab46 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 14 Jun 2019 15:51:32 +0300 Subject: [PATCH 73/88] Test access to the roles and permissions UI. --- .../RolesAndPermissionsUiAccessTest.php | 324 ++++++++++++++++++ 1 file changed, 324 insertions(+) create mode 100644 tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php diff --git a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php new file mode 100644 index 000000000..13ce184f8 --- /dev/null +++ b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php @@ -0,0 +1,324 @@ +installEntitySchema('block_content'); + $this->installEntitySchema('og_membership'); + $this->installEntitySchema('user'); + $this->installSchema('system', 'sequences'); + + // Create a "group" bundle on the Custom Block entity type and turn it into + // a group. Note we're not using the Entity Test entity for this since it + // does not have real support for multiple bundles. + BlockContentType::create(['id' => 'group'])->save(); + Og::groupTypeManager()->addGroup('block_content', 'group'); + + // Create a custom 'moderator' role for our group type. + $this->role = OgRole::create(); + $this->role + ->setGroupType('block_content') + ->setGroupBundle('group') + ->setName('moderator') + ->save(); + + // Create an anonymous test user. + $this->users['anonymous'] = User::getAnonymousUser(); + + // Create the root user. Since this is the first user we create this user + // will get UID 1 which is reserved for the root user. + $this->users['root user'] = $this->createUser(); + $this->users['root user']->save(); + + // Create another global administrator. This is a user with a role which has + // the 'isAdmin' flag, indicating that this user has all possible + // permissions. + $this->users['global administrator'] = $this->createUser([], NULL, TRUE); + $this->users['global administrator']->save(); + + // Create a 'normal' authenticated user which is not part of the test group. + $this->users['non-member'] = $this->createUser(); + $this->users['non-member']->save(); + + // Create a user which has the global permission to administer groups. + $this->users['global group administrator'] = $this->createUser(['administer group']); + $this->users['global group administrator']->save(); + + // Create a test user for each membership type. + $membership_types = [ + // The group administrator. + 'administrator' => [ + 'state' => OgMembershipInterface::STATE_ACTIVE, + 'role_name' => OgRoleInterface::ADMINISTRATOR, + ], + // A regular member of the group. + 'member' => [ + 'state' => OgMembershipInterface::STATE_ACTIVE, + 'role_name' => OgRoleInterface::AUTHENTICATED, + ], + // A blocked user. + 'blocked' => [ + 'state' => OgMembershipInterface::STATE_BLOCKED, + 'role_name' => OgRoleInterface::AUTHENTICATED, + ], + // A pending user. + 'pending' => [ + 'state' => OgMembershipInterface::STATE_PENDING, + 'role_name' => OgRoleInterface::AUTHENTICATED, + ], + // A "moderator" (a custom role). + 'moderator' => [ + 'state' => OgMembershipInterface::STATE_ACTIVE, + 'role_name' => OgRoleInterface::AUTHENTICATED, + ], + ]; + foreach ($membership_types as $user_key => $membership_info) { + $user = $this->createUser(); + $this->users[$user_key] = $user; + + // The administrator is the first user to be created. In this case also + // create the group and set the administrator as the owner. The membership + // will be created automatically. + switch ($user_key) { + case 'administrator': + $this->group = BlockContent::create([ + 'title' => $this->randomString(), + 'type' => 'group', + 'uid' => $user->id(), + ]); + $this->group->save(); + break; + + // Create a normal membership for the other users. + default: + $this->createOgMembership($this->group, $user, [$membership_info['role_name']], $membership_info['state']); + break; + } + } + } + + /** + * Checks whether users have access to routes. + * + * @param array $routes + * An array of routes to test. Each value is an array with two keys: + * - A string containing the route machine name to check. + * - An array of route parameters to set. + * @param array $access_matrix + * An associative array, keyed by user key, with as value a boolean that + * represents whether or not the user is expected to have access to the + * route. + * + * @dataProvider routeAccessDataProvider + */ + public function testRouteAccess(array $routes, array $access_matrix): void { + foreach ($routes as $route_info) { + list($route, $parameters) = $route_info; + foreach ($access_matrix as $user_key => $should_have_access) { + $has_access = $this->container->get('access_manager')->checkNamedRoute($route, $parameters, $this->users[$user_key], FALSE); + $message = "The '$user_key' user is " . ($should_have_access ? '' : 'not ') . "expected to have access to the '$route' route."; + $this->assertEquals($should_have_access, $has_access, $message); + } + } + } + + /** + * Data provider for ::testRouteAccess(). + * + * @return array + * An array of test cases. Each test case is an indexed array with the + * following values: + * - An array of routes to test. Each value is an array with two keys: + * - A string containing the route machine name to check. + * - An array of route parameters for the route. + * - An associative array keyed by users, with the value a boolean + * representing whether or not the user is expected to have access to the + * routes. + */ + public function routeAccessDataProvider() { + return [ + [ + [ + // The main page of the Organic Groups configuration. + [ + 'og_ui.admin_index', + [], + ], + // The settings form. + [ + 'og_ui.settings', + [], + ], + // The roles overview table for all group types. + [ + 'og_ui.roles_permissions_overview', + ['type' => 'roles'], + ], + // The permissions overview table for all group types. + [ + 'og_ui.roles_permissions_overview', + ['type' => 'permissions'], + ], + // The permissions table for all roles of a specific group type. + [ + 'og_ui.permissions_overview', + [ + 'entity_type_id' => 'block_content', + 'bundle_id' => 'group', + ], + ], + // The permissions form for administrators of a single group type. + [ + 'og_ui.permissions_edit_form', + [ + 'entity_type_id' => 'block_content', + 'bundle_id' => 'group', + 'role_name' => OgRoleInterface::ADMINISTRATOR, + ], + ], + // The permissions form for non-members of a single group type. + [ + 'og_ui.permissions_edit_form', + [ + 'entity_type_id' => 'block_content', + 'bundle_id' => 'group', + 'role_name' => OgRoleInterface::ANONYMOUS, + ], + ], + // The permissions form for members of a single group type. + [ + 'og_ui.permissions_edit_form', + [ + 'entity_type_id' => 'block_content', + 'bundle_id' => 'group', + 'role_name' => OgRoleInterface::AUTHENTICATED, + ], + ], + // The permissions form for "moderators" (a custom role) of a single + // group type. + [ + 'og_ui.permissions_edit_form', + [ + 'entity_type_id' => 'block_content', + 'bundle_id' => 'group', + 'role_name' => 'moderator', + ], + ], + // The overview of available roles for a group type. + [ + 'entity.og_role.collection', + [ + 'entity_type_id' => 'block_content', + 'bundle_id' => 'group', + ], + ], + // The form to add a new role to a group type. + [ + 'entity.og_role.add_form', + [ + 'entity_type_id' => 'block_content', + 'bundle_id' => 'group', + ], + ], + // The form to edit a custom role belonging to a group type. + [ + 'entity.og_role.edit_form', + [ + 'og_role' => 'block_content-group-moderator', + ], + ], + // The form to delete a custom role belonging to a group type. + [ + 'entity.og_role.delete_form', + [ + 'og_role' => 'block_content-group-moderator', + ], + ], + ], + [ + // Since these routes are for managing the roles and permissions of + // all groups of the tested entity type and bundle, the forms should + // only be accessible to the root user, global administrators that + // have all permissions, and people with the 'administer group' + // permission. Group administrators should not have access to these + // pages, but they will have access to the forms that deal with + // group-specific roles and permissions. These are not tested here. + 'root user' => TRUE, + 'global administrator' => TRUE, + 'global group administrator' => TRUE, + 'anonymous' => FALSE, + 'non-member' => FALSE, + 'administrator' => FALSE, + 'member' => FALSE, + 'blocked' => FALSE, + 'pending' => FALSE, + ], + ], + ]; + } + +} From d423ec09efc9514643757ff91c64e69c8316adc1 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Sat, 4 Jul 2020 14:39:23 +0200 Subject: [PATCH 74/88] Remove calls to t() --- src/Entity/OgRoleListBuilder.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Entity/OgRoleListBuilder.php b/src/Entity/OgRoleListBuilder.php index cfd46d04e..b1d4f9227 100644 --- a/src/Entity/OgRoleListBuilder.php +++ b/src/Entity/OgRoleListBuilder.php @@ -100,7 +100,7 @@ public function getFormId() { * {@inheritdoc} */ public function buildHeader() { - $header['label'] = t('Name'); + $header['label'] = $this->t('Name'); return $header + parent::buildHeader(); } @@ -120,7 +120,7 @@ public function getDefaultOperations(EntityInterface $role) { // @TODO if ($entity->hasLinkTemplate('edit-permissions-form')). $operations['permissions'] = [ - 'title' => t('Edit permissions'), + 'title' => $this->t('Edit permissions'), 'weight' => 20, 'url' => Url::fromRoute('og_ui.permissions_edit_form', [ 'entity_type_id' => $this->groupType, From 2e9e4653de7dcb7bce98d3ea910178e62c396275 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 20 Jul 2020 12:52:02 +0200 Subject: [PATCH 75/88] Renamed permission --- og.routing.yml | 4 ++-- src/Entity/OgRole.php | 2 +- tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/og.routing.yml b/og.routing.yml index 1b6d5b8ae..989a0bb3a 100644 --- a/og.routing.yml +++ b/og.routing.yml @@ -8,7 +8,7 @@ entity.og_role.collection: _entity_list: 'og_role' _title_callback: '\Drupal\og_ui\Controller\OgUiController::rolesOverviewPageTitleCallback' requirements: - _permission: 'administer group' + _permission: 'administer organic groups' entity.og_role.add_form: path: 'admin/config/group/roles/{entity_type_id}/{bundle_id}/add' @@ -16,7 +16,7 @@ entity.og_role.add_form: _entity_form: og_role.default _title: 'Add role' requirements: - _permission: 'administer group' + _permission: 'administer organic groups' entity.og_role.edit_form: path: 'admin/config/group/role/{og_role}/edit' diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index 0d9fa166b..7fae45450 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -31,7 +31,7 @@ * }, * "list_builder" = "Drupal\og\Entity\OgRoleListBuilder", * }, - * admin_permission = "administer group", + * admin_permission = "administer organic groups", * static_cache = TRUE, * entity_keys = { * "id" = "id", diff --git a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php index 13ce184f8..ddfc78886 100644 --- a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php +++ b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php @@ -104,8 +104,8 @@ public function setUp() { $this->users['non-member'] = $this->createUser(); $this->users['non-member']->save(); - // Create a user which has the global permission to administer groups. - $this->users['global group administrator'] = $this->createUser(['administer group']); + // Create a user which has the global permission to administer organic groups. + $this->users['global group administrator'] = $this->createUser(['administer organic groups']); $this->users['global group administrator']->save(); // Create a test user for each membership type. @@ -303,7 +303,7 @@ public function routeAccessDataProvider() { // Since these routes are for managing the roles and permissions of // all groups of the tested entity type and bundle, the forms should // only be accessible to the root user, global administrators that - // have all permissions, and people with the 'administer group' + // have all permissions, and people with the 'administer organic groups' // permission. Group administrators should not have access to these // pages, but they will have access to the forms that deal with // group-specific roles and permissions. These are not tested here. From 202908ef92e4d68c621fec6fefde98a18bdc52de Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 20 Jul 2020 13:11:52 +0200 Subject: [PATCH 76/88] Fix lines that exceed 80 characters --- .../src/Kernel/Access/RolesAndPermissionsUiAccessTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php index ddfc78886..49b3bb4e1 100644 --- a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php +++ b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php @@ -104,7 +104,8 @@ public function setUp() { $this->users['non-member'] = $this->createUser(); $this->users['non-member']->save(); - // Create a user which has the global permission to administer organic groups. + // Create a user which has the global permission to administer organic + // groups. $this->users['global group administrator'] = $this->createUser(['administer organic groups']); $this->users['global group administrator']->save(); @@ -303,8 +304,9 @@ public function routeAccessDataProvider() { // Since these routes are for managing the roles and permissions of // all groups of the tested entity type and bundle, the forms should // only be accessible to the root user, global administrators that - // have all permissions, and people with the 'administer organic groups' - // permission. Group administrators should not have access to these + // have all permissions, and users that have the permission + // 'administer organic groups'. + // Group administrators should not have access to these // pages, but they will have access to the forms that deal with // group-specific roles and permissions. These are not tested here. 'root user' => TRUE, From 046f8b2ca683b2914ef874ef389d08da1e6946d2 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Mon, 10 Aug 2020 10:41:29 +0200 Subject: [PATCH 77/88] Add strict types --- og_ui/src/Form/OgPermissionsForm.php | 2 ++ og_ui/src/Form/OgRoleDeleteForm.php | 2 ++ og_ui/src/Form/OgRoleForm.php | 2 ++ og_ui/src/Form/OgRolePermissionsForm.php | 2 ++ src/Entity/OgRoleListBuilder.php | 2 ++ src/Entity/OgRoleRouteProvider.php | 2 ++ src/OgRoleAccessControlHandler.php | 2 ++ 7 files changed, 14 insertions(+) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index a3eff25e5..2285fd2e7 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -1,5 +1,7 @@ Date: Tue, 19 Jan 2021 13:32:29 +0100 Subject: [PATCH 78/88] Apply suggestions from code review --- og_ui/src/Form/OgRoleForm.php | 10 ++++++++-- src/Entity/OgRoleListBuilder.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index c7a518ef6..e2a19acc8 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -105,11 +105,17 @@ public function save(array $form, FormStateInterface $form_state) { $edit_link = $this->entity->link($this->t('Edit')); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); - $this->logger('user')->notice('OG role %label has been updated.', ['%label' => $og_role->label(), 'link' => $edit_link]); + $this->logger('user')->notice('OG role %label has been updated.', [ + '%label' => $og_role->label(), + 'link' => $edit_link, + ]); } else { drupal_set_message($this->t('OG role %label has been added.', ['%label' => $og_role->label()])); - $this->logger('user')->notice('OG role %label has been added.', ['%label' => $og_role->label(), 'link' => $edit_link]); + $this->logger('user')->notice('OG role %label has been added.', [ + '%label' => $og_role->label(), + 'link' => $edit_link, + ]); } // Cannot use $og_role->url() because we need to pass mandatory parameters. $form_state->setRedirect('entity.og_role.collection', [ diff --git a/src/Entity/OgRoleListBuilder.php b/src/Entity/OgRoleListBuilder.php index 742503316..987cb5bfb 100644 --- a/src/Entity/OgRoleListBuilder.php +++ b/src/Entity/OgRoleListBuilder.php @@ -120,7 +120,7 @@ public function buildRow(EntityInterface $entity) { public function getDefaultOperations(EntityInterface $role) { $operations = parent::getDefaultOperations($role); - // @TODO if ($entity->hasLinkTemplate('edit-permissions-form')). + // @todo If ($entity->hasLinkTemplate('edit-permissions-form')). $operations['permissions'] = [ 'title' => $this->t('Edit permissions'), 'weight' => 20, From 5599a5b133c355c9cc27ad4e1e199988091365c6 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 28 Apr 2021 10:26:12 +0200 Subject: [PATCH 79/88] Use RouteProviderInterface --- src/Plugin/Derivative/OgLocalTask.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugin/Derivative/OgLocalTask.php b/src/Plugin/Derivative/OgLocalTask.php index f815f9110..f03b64863 100644 --- a/src/Plugin/Derivative/OgLocalTask.php +++ b/src/Plugin/Derivative/OgLocalTask.php @@ -6,7 +6,7 @@ use Drupal\Component\Plugin\Derivative\DeriverBase; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; -use Drupal\Core\Routing\RouteProvider; +use Drupal\Core\Routing\RouteProviderInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\og\GroupTypeManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -28,7 +28,7 @@ class OgLocalTask extends DeriverBase implements ContainerDeriverInterface { /** * Route provider object. * - * @var \Drupal\Core\Routing\RouteProvider + * @var \Drupal\Core\Routing\RouteProviderInterface */ protected $routeProvider; @@ -37,10 +37,10 @@ class OgLocalTask extends DeriverBase implements ContainerDeriverInterface { * * @param \Drupal\og\GroupTypeManagerInterface $group_type_manager * The group type manager. - * @param \Drupal\Core\Routing\RouteProvider $route_provider + * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider * The route provider services. */ - public function __construct(GroupTypeManagerInterface $group_type_manager, RouteProvider $route_provider) { + public function __construct(GroupTypeManagerInterface $group_type_manager, RouteProviderInterface $route_provider) { $this->groupTypeManager = $group_type_manager; $this->routeProvider = $route_provider; } From ee2d98a9e96a99ae9dde2bdc0358e4141431c577 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Wed, 28 Apr 2021 14:20:59 +0200 Subject: [PATCH 80/88] Use EntityTypeInterface See https://www.drupal.org/node/2549139 Co-authored-by: lennartvava --- src/Entity/OgRoleListBuilder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entity/OgRoleListBuilder.php b/src/Entity/OgRoleListBuilder.php index 987cb5bfb..7bac7b5b5 100644 --- a/src/Entity/OgRoleListBuilder.php +++ b/src/Entity/OgRoleListBuilder.php @@ -41,7 +41,7 @@ class OgRoleListBuilder extends DraggableListBuilder { public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), + $container->get('entity_type.manager')->getStorage($entity_type->id()), $container->get('current_route_match') ); } From e8b65f30a080df66d4c32a7414ba49522d03874d Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 30 Apr 2021 14:35:57 +0200 Subject: [PATCH 81/88] Change deprecated link() to toLink() --- og_ui/src/Form/OgRoleForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index e2a19acc8..1cf7f4bdb 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -102,7 +102,7 @@ public function save(array $form, FormStateInterface $form_state) { $og_role->set('name', trim($og_role->get('name'))); $status = $og_role->save(); - $edit_link = $this->entity->link($this->t('Edit')); + $edit_link = $this->entity->toLink($this->t('Edit')); if ($status == SAVED_UPDATED) { drupal_set_message($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); $this->logger('user')->notice('OG role %label has been updated.', [ From 1518ff5f56cc858f603774a3c5a15ff37a07cfcb Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 30 Apr 2021 14:42:12 +0200 Subject: [PATCH 82/88] Remove deprecated drupal_set_message --- og_ui/src/Form/OgPermissionsForm.php | 2 +- og_ui/src/Form/OgRoleForm.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 2285fd2e7..745cd7b81 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -336,7 +336,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $role->save(); } - drupal_set_message($this->t('The changes have been saved.')); + \Drupal::messenger()->addMessage($this->t('The changes have been saved.')); } } diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 1cf7f4bdb..8a15be5b9 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -104,14 +104,14 @@ public function save(array $form, FormStateInterface $form_state) { $edit_link = $this->entity->toLink($this->t('Edit')); if ($status == SAVED_UPDATED) { - drupal_set_message($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); + \Drupal::messenger()->addMessage($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); $this->logger('user')->notice('OG role %label has been updated.', [ '%label' => $og_role->label(), 'link' => $edit_link, ]); } else { - drupal_set_message($this->t('OG role %label has been added.', ['%label' => $og_role->label()])); + \Drupal::messenger()->addMessage($this->t('OG role %label has been added.', ['%label' => $og_role->label()])); $this->logger('user')->notice('OG role %label has been added.', [ '%label' => $og_role->label(), 'link' => $edit_link, From cde56f616029c1af9ac59b8511668a54df481cc3 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 30 Apr 2021 14:44:38 +0200 Subject: [PATCH 83/88] Apply suggestions from code review --- og_ui/src/Form/OgRoleForm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 8a15be5b9..87853ca01 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -104,14 +104,14 @@ public function save(array $form, FormStateInterface $form_state) { $edit_link = $this->entity->toLink($this->t('Edit')); if ($status == SAVED_UPDATED) { - \Drupal::messenger()->addMessage($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); + $this->messenger()->addMessage($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); $this->logger('user')->notice('OG role %label has been updated.', [ '%label' => $og_role->label(), 'link' => $edit_link, ]); } else { - \Drupal::messenger()->addMessage($this->t('OG role %label has been added.', ['%label' => $og_role->label()])); + $this->messenger()->addMessage($this->t('OG role %label has been added.', ['%label' => $og_role->label()])); $this->logger('user')->notice('OG role %label has been added.', [ '%label' => $og_role->label(), 'link' => $edit_link, From 361378d475352a7c264147acc1e13272e795b538 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 30 Apr 2021 14:46:31 +0200 Subject: [PATCH 84/88] Update og_ui/src/Form/OgPermissionsForm.php --- og_ui/src/Form/OgPermissionsForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 745cd7b81..69a82f0c9 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -336,7 +336,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $role->save(); } - \Drupal::messenger()->addMessage($this->t('The changes have been saved.')); + $this->messenger()->addMessage($this->t('The changes have been saved.')); } } From b4f00c911769155ed89aa86410ac16f0d739ceff Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 30 Apr 2021 15:58:40 +0200 Subject: [PATCH 85/88] Update og_ui/src/Form/OgRoleForm.php --- og_ui/src/Form/OgRoleForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/og_ui/src/Form/OgRoleForm.php b/og_ui/src/Form/OgRoleForm.php index 87853ca01..e1c3d854b 100644 --- a/og_ui/src/Form/OgRoleForm.php +++ b/og_ui/src/Form/OgRoleForm.php @@ -102,7 +102,7 @@ public function save(array $form, FormStateInterface $form_state) { $og_role->set('name', trim($og_role->get('name'))); $status = $og_role->save(); - $edit_link = $this->entity->toLink($this->t('Edit')); + $edit_link = $this->entity->toLink($this->t('Edit'))->toString(); if ($status == SAVED_UPDATED) { $this->messenger()->addMessage($this->t('OG role %label has been updated.', ['%label' => $og_role->label()])); $this->logger('user')->notice('OG role %label has been updated.', [ From b8cd389ac0c5b81b73d33bfad7b37905c111c1b3 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Tue, 28 Sep 2021 21:30:51 +0200 Subject: [PATCH 86/88] Remove extra blank line Co-authored-by: Damien McKenna --- og_ui/src/Form/OgPermissionsForm.php | 1 - 1 file changed, 1 deletion(-) diff --git a/og_ui/src/Form/OgPermissionsForm.php b/og_ui/src/Form/OgPermissionsForm.php index 69a82f0c9..2d7f3d110 100644 --- a/og_ui/src/Form/OgPermissionsForm.php +++ b/og_ui/src/Form/OgPermissionsForm.php @@ -316,7 +316,6 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { - /** @var \Drupal\og\Entity\OgRole $roles */ foreach ($this->roles as $rid => $role) { if (!$form_state->hasValue($rid)) { From 15c1b7aa6bdc51f91544eb3b49490144843e84bd Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Thu, 25 Aug 2022 10:02:08 +0200 Subject: [PATCH 87/88] Add required options module for Kernel test --- tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php index 49b3bb4e1..e96170b5f 100644 --- a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php +++ b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php @@ -36,6 +36,7 @@ class RolesAndPermissionsUiAccessTest extends KernelTestBase { 'block_content', 'og', 'og_ui', + 'options', 'system', 'user', ]; From b9fa416309ef8775e204a2e8e5a69c0d41c3c6b4 Mon Sep 17 00:00:00 2001 From: Maarten Segers Date: Fri, 26 Aug 2022 14:55:43 +0200 Subject: [PATCH 88/88] Fix phpcs issues list(...) is forbidden, use [...] instead. --- src/OgRoleAccessControlHandler.php | 2 +- tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OgRoleAccessControlHandler.php b/src/OgRoleAccessControlHandler.php index aa5354877..9336c4eee 100644 --- a/src/OgRoleAccessControlHandler.php +++ b/src/OgRoleAccessControlHandler.php @@ -21,7 +21,7 @@ class OgRoleAccessControlHandler extends EntityAccessControlHandler { */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { if ($operation == 'delete') { - list(, , $id) = explode('-', $entity->id(), 3); + [, , $id] = explode('-', $entity->id(), 3); $roles = [ OgRoleInterface::ANONYMOUS, OgRoleInterface::AUTHENTICATED, diff --git a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php index e96170b5f..03bf5203f 100644 --- a/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php +++ b/tests/src/Kernel/Access/RolesAndPermissionsUiAccessTest.php @@ -179,7 +179,7 @@ public function setUp() { */ public function testRouteAccess(array $routes, array $access_matrix): void { foreach ($routes as $route_info) { - list($route, $parameters) = $route_info; + [$route, $parameters] = $route_info; foreach ($access_matrix as $user_key => $should_have_access) { $has_access = $this->container->get('access_manager')->checkNamedRoute($route, $parameters, $this->users[$user_key], FALSE); $message = "The '$user_key' user is " . ($should_have_access ? '' : 'not ') . "expected to have access to the '$route' route.";