Commit 88699835 authored by Nikolay Lobachev's avatar Nikolay Lobachev
Browse files

Issue #3321278 by LOBsTerr: View revision call to removed method

parent 2f7e0ad7
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -82,7 +82,14 @@ class GroupPermissionsController extends ControllerBase implements ContainerInje
   * @param \Drupal\group\Access\GroupPermissionHandlerInterface $permission_handler
   *   The permission handler.
   */
  public function __construct(DateFormatter $date_formatter, Renderer $renderer, FormBuilderInterface $form_builder, GroupPermissionStorageInterface $group_permission_storage, GroupPermissionsManagerInterface $group_permission_manager, GroupPermissionHandlerInterface $permission_handler) {
  public function __construct(
    DateFormatter $date_formatter,
    Renderer $renderer,
    FormBuilderInterface $form_builder,
    GroupPermissionStorageInterface $group_permission_storage,
    GroupPermissionsManagerInterface $group_permission_manager,
    GroupPermissionHandlerInterface $permission_handler
  ) {
    $this->dateFormatter = $date_formatter;
    $this->renderer = $renderer;
    $this->formBuilder = $form_builder;
@@ -130,7 +137,7 @@ class GroupPermissionsController extends ControllerBase implements ContainerInje
    $revision = $this->groupPermissionStorage->loadRevision($group_permission_revision);
    $revision_custom_permissions = $revision->getPermissions();

    $group_roles = $this->groupPermissionsManager->getGroupRoles($group);
    $group_roles = $this->groupPermissionsManager->getNonAdminRoles($group);

    // Retrieve information for every role to user further down. We do this to
    // prevent the same methods from being fired (rows * permissions) times.
@@ -144,9 +151,6 @@ class GroupPermissionsController extends ControllerBase implements ContainerInje
      }

      $role_label = $group_role->label();
      if ($group_role->isOutsider() && !$group_role->inPermissionsUI()) {
        $role_label .= ' ' . $this->t('(Outsider)');
      }

      $role_info[$role_name] = [
        'label' => $role_label,
@@ -219,18 +223,22 @@ class GroupPermissionsController extends ControllerBase implements ContainerInje
            }
            else {

              $group_permission_has_permission = !empty($custom_permissions[$role_name]) && in_array($perm, $custom_permissions[$role_name]);
              $group_permissions_has_permission = !empty($custom_permissions[$role_name]) && in_array($perm, $custom_permissions[$role_name]);
              $revision_has_permission = !empty($revision_custom_permissions[$role_name]) && in_array($perm, $revision_custom_permissions[$role_name]);
              $sign = $group_permission_has_permission ? '✓' : '×';

              $color = $group_permission_has_permission == $revision_has_permission ? '#008000' : '#ff0000';
              $sign = $group_permissions_has_permission ? '✓' : '×';

              if (!$group_permissions_has_permission) {
                $color = '#000000';
              }
              else {
                $color = $group_permissions_has_permission == $revision_has_permission ? '#008000' : '#ff0000';
              }
              $row[] = [
                'data' => [
                  '#type' => 'markup',
                  '#markup' => $sign,
                ],
                'style' => "color: {$color};",
                'style' => "color: {$color}; font-size: 30px;",
                'class' => 'checkbox module',
              ];
            }
@@ -259,10 +267,13 @@ class GroupPermissionsController extends ControllerBase implements ContainerInje
  }

  /**
   * Gets the permissions to display in this form.
   * Gets the permissions to display.
   *
   * @param \Drupal\group\Entity\GroupInterface $group
   *   Group.
   *
   * @return array
   *   An multidimensional associative array of permissions, keyed by the
   *   A multidimensional associative array of permissions, keyed by the
   *   providing module first and then by permission name.
   */
  protected function getPermissions(GroupInterface $group) {
@@ -270,15 +281,13 @@ class GroupPermissionsController extends ControllerBase implements ContainerInje

    // Create a list of group permissions ordered by their provider and section.
    foreach ($this->groupPermissionHandler->getPermissionsByGroupType($group->getGroupType()) as $permission_name => $permission) {
      if (empty($permission['gid']) || !empty($permission['gid']) && $permission['gid'] == $group->id()) {
        $by_provider_and_section[$permission['provider']][$permission['section']][$permission_name] = $permission;
      }
      $by_provider_and_section[$permission['provider']][$permission['section_id']][$permission_name] = $permission;
    }

    // Always put the 'General' section at the top if provided.
    // Always put the 'general' section at the top if provided.
    foreach ($by_provider_and_section as $provider => $sections) {
      if (isset($sections['General'])) {
        $by_provider_and_section[$provider] = ['General' => $sections['General']] + $sections;
      if (isset($sections['general'])) {
        $by_provider_and_section[$provider] = ['general' => $sections['general']] + $sections;
      }
    }

+2 −4
Original line number Diff line number Diff line
@@ -373,7 +373,7 @@ class GroupPermissionsForm extends BasePermissionForm {

    $violations = $this->groupPermission->validate();
    if (count($violations) == 0) {
      // Set new Revision.
      // Set a new Revision.
      $this->groupPermission->setNewRevision();
      $this->groupPermission->setRevisionUserId($this->currentUser->id());
      $this->groupPermission->setRevisionCreationTime($this->time->getRequestTime());
@@ -393,9 +393,7 @@ class GroupPermissionsForm extends BasePermissionForm {
   * {@inheritdoc}
   */
  protected function getGroupRoles() {
    return $this->entityTypeManager
      ->getStorage('group_role')
      ->loadByProperties(['group_type' => $this->getGroupType()->id()]);
    return $this->groupPermissionsManager->getNonAdminRoles($this->group);
  }

}
+21 −7
Original line number Diff line number Diff line
@@ -25,13 +25,6 @@ class GroupPermissionsManager implements GroupPermissionsManagerInterface {
   */
  protected $groupPermissions = [];

  /**
   * The array of the group roles.
   *
   * @var array
   */
  protected $groupRoles = [];

  /**
   * The cache backend to use.
   *
@@ -53,13 +46,22 @@ class GroupPermissionsManager implements GroupPermissionsManagerInterface {
   */
  protected $groupPermissionStorage;

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(CacheBackendInterface $cache_backend, EntityTypeManagerInterface $entity_type_manager) {
    $this->cacheBackend = $cache_backend;
    $this->entityTypeManager = $entity_type_manager;
    $this->groupRoleStorage = $entity_type_manager->getStorage('group_role');
    $this->groupPermissionStorage = $entity_type_manager->getStorage('group_permission');
    $this->groupPermissionStorage = $entity_type_manager->getStorage('group_permission');
  }

  /**
@@ -118,4 +120,16 @@ class GroupPermissionsManager implements GroupPermissionsManagerInterface {
    return $this->groupPermissionStorage->loadByGroup($group);
  }

  /**
   * {@inheritdoc}
   */
  public function getNonAdminRoles($group) {
    return $this->entityTypeManager
      ->getStorage('group_role')
      ->loadByProperties([
        'group_type' => $group->getGroupType()->id(),
        'admin' => 0,
      ]);
  }

}
+11 −0
Original line number Diff line number Diff line
@@ -55,4 +55,15 @@ interface GroupPermissionsManagerInterface {
   */
  public function loadByGroup(GroupInterface $group);

  /**
   * Retrieves group non admin permissions.
   *
   * @param \Drupal\group\Entity\GroupInterface $group
   *   The group entity to load the group content entities for.
   *
   * @return \Drupal\group\Entity\GroupRoleInterface[]|null
   *   List of non admin group roles.
   */
  public function getNonAdminRoles(GroupInterface $group);

}