From ab106fe4e714f60e689ce234c5215e1da0885159 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Fri, 13 May 2016 18:06:56 +0300 Subject: [PATCH 01/21] 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 167811774..ffd33107e 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -30,7 +30,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 5c3d85353f3bd46ab51649a615bed2d4c663a9c8 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 10:10:14 +0300 Subject: [PATCH 02/21] 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 ffd33107e..3cd1295c3 100644 --- a/og_ui/og_ui.routing.yml +++ b/og_ui/og_ui.routing.yml @@ -34,6 +34,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: @@ -41,3 +49,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 713d8eab5da6508ff0e45d9f5154cbefb2d1bfdc Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 10:10:50 +0300 Subject: [PATCH 03/21] 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 0f5157758..d41afea23 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -174,6 +174,13 @@ public function setRoleType($role_type) { return $this->set('role_type', $role_type); } + /** + * {@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 89857f8c0..e8bd510ae 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -48,4 +48,15 @@ interface OgRoleInterface { */ public function setId($id); + /** + * 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 0b0d53e54c5574be27a18c63030233e46affc91a Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 10:11:30 +0300 Subject: [PATCH 04/21] 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 3edfcd4423fdc40096e478b2050cbe821364aea5 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 12:53:20 +0300 Subject: [PATCH 05/21] Change the value of the administrator role name so it doesn't contain spaces. This ends up as a config key which typically doesn't have spaces. --- src/OgRoleInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OgRoleInterface.php b/src/OgRoleInterface.php index e8bd510ae..9e0e14cde 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -24,7 +24,7 @@ interface OgRoleInterface { /** * The role name of the group administrator. */ - const ADMINISTRATOR = 'administrator member'; + const ADMINISTRATOR = 'administrator'; /** * Role type for default roles which should not be changed. From 1eb0375c6417019dd1144a4751c4d2e8831bb354 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 16:04:42 +0300 Subject: [PATCH 06/21] Turn the roles overview from a form into a controller. --- og_ui/og_ui.routing.yml | 14 +-- og_ui/src/Controller/OgUiController.php | 77 ++++++++++++- og_ui/src/Form/OgRolesForm.php | 146 ------------------------ 3 files changed, 82 insertions(+), 155 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 3398b7320..4870d8c16 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -83,7 +83,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, ]), @@ -113,5 +113,78 @@ public function rolesPermissionsOverviewPage($type) { 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 2c69737e493c001f570594b4653ef5d8babfbc74 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 16:06:23 +0300 Subject: [PATCH 07/21] 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 39a086b36f3dfc232a8bff34d5a5b6e5f9d691e5 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 16:06:47 +0300 Subject: [PATCH 08/21] 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 4870d8c16..b6f506311 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -7,8 +7,10 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Link; use Drupal\og\GroupManager; +use Drupal\og\Og; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class OgUiController extends ControllerBase { @@ -126,6 +128,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 03597f4a7e7855293b58f3df482566bb9b3dfd36 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 14 May 2016 16:07:00 +0300 Subject: [PATCH 09/21] Clean up whitespace. --- og_ui/src/Controller/OgUiController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/og_ui/src/Controller/OgUiController.php b/og_ui/src/Controller/OgUiController.php index b6f506311..f3a9a2242 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -27,7 +27,7 @@ class OgUiController extends ControllerBase { * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; - + /** * The entity type bundle info service. * @@ -50,7 +50,7 @@ public function __construct(GroupManager $group_manager, EntityTypeManagerInterf $this->entityTypeManager = $entity_type_manager; $this->entityTypeBundleInfo = $entity_type_bundle_info; } - + /** * {@inheritdoc} */ @@ -61,7 +61,7 @@ public static function create(ContainerInterface $container) { $container->get('entity_type.bundle.info') ); } - + /** * Returns the overview of OG roles and permissions. * From be6b209016aa0f2364be067509ebd0801741ca80 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 09:13:06 +0200 Subject: [PATCH 10/21] 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 b5a8bdb51b406831e7431be97d873b717d79d467 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 10:53:48 +0200 Subject: [PATCH 11/21] 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 40ebb16d2..5aae64e6d 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -176,8 +176,8 @@ public function setRoleType($role_type) { /** * {@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 b5514c4db..a03045e53 100644 --- a/src/OgRoleInterface.php +++ b/src/OgRoleInterface.php @@ -54,12 +54,12 @@ public function setId($id); /** * 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 ecd3185b7ee1edac8a2deb359693954aed727050 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 11:44:57 +0200 Subject: [PATCH 12/21] 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 f3a9a2242..c977afa10 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -105,7 +105,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 683a190031149afc36230ab3c3b7da60df6e2e1f Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 1 Jun 2016 11:45:39 +0200 Subject: [PATCH 13/21] 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 5d193dbbc19a5414e4f320bfdea1056fec0919e0 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 11:40:58 +0200 Subject: [PATCH 14/21] 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 c977afa10..2e18a2a81 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -145,7 +145,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 91b8befcbb9101f98ba598e870db3cdb088b8617 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 11:41:43 +0200 Subject: [PATCH 15/21] 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 5aae64e6d..8908cb22b 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -21,6 +21,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 ca7cfc7cb2929efcda8abb4cde8de2fd749f3ce0 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 14:15:55 +0200 Subject: [PATCH 16/21] 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 8908cb22b..ec4effb3a 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -15,6 +15,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 bf11cbae2fc1508bf881e3234a7dae92aa1a1b81 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 14:31:59 +0200 Subject: [PATCH 17/21] 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 2e18a2a81..dc9eedc04 100644 --- a/og_ui/src/Controller/OgUiController.php +++ b/og_ui/src/Controller/OgUiController.php @@ -147,7 +147,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 73910d911cc4033bb63d0b45b9b3844638029c4f Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 14:32:23 +0200 Subject: [PATCH 18/21] 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 0c39dd72a488eed24e4bd791c436716ed079c073 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Thu, 2 Jun 2016 14:32:56 +0200 Subject: [PATCH 19/21] Actually check if a property gets changed before complaining. --- src/Entity/OgRole.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index ec4effb3a..c9327aec6 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -233,7 +233,7 @@ public function set($property_name, $value) { 'group_type', 'group_bundle', ]); - if ($is_locked_property && !$this->isNew()) { + if ($is_locked_property && !$this->isNew() && $value !== $this->get($property_name)) { throw new OgRoleException("The $property_name cannot be changed."); } return parent::set($property_name, $value); From 0ef056cf4abe78944406ab4ec9c549b707570641 Mon Sep 17 00:00:00 2001 From: Archie DOe Date: Wed, 1 Feb 2017 13:47:48 +0000 Subject: [PATCH 20/21] 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 +++++++++++++++++ src/Entity/OgRole.php | 1 - 4 files changed, 74 insertions(+), 3 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, + ]); + } + } diff --git a/src/Entity/OgRole.php b/src/Entity/OgRole.php index bff9470de..fa043b66d 100644 --- a/src/Entity/OgRole.php +++ b/src/Entity/OgRole.php @@ -234,7 +234,6 @@ public function setName($name) { public static function loadByGroupAndName(EntityInterface $group, $name) { $role_id = "{$group->getEntityTypeId()}-{$group->bundle()}-$name"; return self::load($role_id); ->>>>>>> 8.x-1.x } /** From dc2c6a408660172eadd7109d788b477feb9c5503 Mon Sep 17 00:00:00 2001 From: Archie DOe Date: Wed, 1 Feb 2017 15:03:53 +0000 Subject: [PATCH 21/21] 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