Commit d6ff7103 authored by Wanderson Reis's avatar Wanderson Reis
Browse files

Issue #3218518 by MegaKeegMan: Ignore entity limitations placed on admin role...

Issue #3218518 by MegaKeegMan: Ignore entity limitations placed on admin role and users with admin role.
parent 56aa2ef7
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -80,12 +80,25 @@ class RoleLimit extends EntityLimitPluginBase implements ContainerFactoryPluginI
      $allowed_roles[$role->id()] = $role->label();
    }

    // Administrator role can not be limited.
    unset($allowed_roles['administrator']);

    $form['limits'] = [
      '#type' => 'table',
      '#caption' => $this->t('Add limits'),
      '#header' => [$this->t('Role'), $this->t('Limit'), $this->t('Operations')],
      '#prefix' => '<div id="limits-table">',
      '#suffix' => '</div>',
      '#footer' => [
        'data' => [
          [
            'data' => $this->t(
              'You can not select the Administrator role because administrators always has full access.'
            ),
            'colspan' => 3,
          ],
        ],
      ],
    ];

    for ($i = 0; $i < $count; $i++) {
+25 −0
Original line number Diff line number Diff line
@@ -74,12 +74,31 @@ class UserLimit extends EntityLimitPluginBase implements ContainerFactoryPluginI
      $count = $form_state->get('num_rows');
    }

    $roles = user_roles(TRUE);
    $allowed_roles = [];
    foreach ($roles as $role) {
      // Users with Administrator role can not be limited.
      if ($role->id() != 'administrator') {
        $allowed_roles[] = $role->id();
      }
    }

    $form['limits'] = [
      '#type' => 'table',
      '#caption' => $this->t('Add limits'),
      '#header' => [$this->t('User'), $this->t('Limit'), $this->t('Operations')],
      '#prefix' => '<div id="limits-table">',
      '#suffix' => '</div>',
      '#footer' => [
        'data' => [
          [
            'data' => $this->t(
              'You can not select users with Administrator role because administrators always has full access.'
            ),
            'colspan' => 3,
          ],
        ],
      ],
    ];

    for ($i = 0; $i < $count; $i++) {
@@ -90,6 +109,12 @@ class UserLimit extends EntityLimitPluginBase implements ContainerFactoryPluginI
        '#description' => $this->t('Limit will be applied to these users. Seperate multiple users by comma'),
        '#required' => TRUE,
        '#default_value' => isset($limits[$i]['id']) ? User::load($limits[$i]['id']) : '',
        '#selection_settings' => [
          'include_anonymous' => FALSE,
          'filter' => [
            'role' => $allowed_roles,
          ],
        ],
      ];

      $form['limits'][$i]['limit'] = [