Commit e4242c47 authored by alexpott's avatar alexpott

Issue #2346105 by olli: Fixed Use 1+2+3 for OR, 1,2,3 for AND.

parent 42024826
......@@ -17,7 +17,7 @@
*
* You can specify the '_role' key on route requirements. If you specify a
* single role, users with that role with have access. If you specify multiple
* ones you can conjunct them with AND by using a "+" and with OR by using ",".
* ones you can conjunct them with AND by using a "," and with OR by using "+".
*/
class RoleAccessCheck implements AccessInterface {
......@@ -36,7 +36,7 @@ public function access(Route $route, AccountInterface $account) {
// Requirements just allow strings, so this might be a comma separated list.
$rid_string = $route->getRequirement('_role');
$explode_and = array_filter(array_map('trim', explode('+', $rid_string)));
$explode_and = array_filter(array_map('trim', explode(',', $rid_string)));
if (count($explode_and) > 1) {
$diff = array_diff($explode_and, $account->getRoles());
if (empty($diff)) {
......@@ -44,7 +44,7 @@ public function access(Route $route, AccountInterface $account) {
}
}
else {
$explode_or = array_filter(array_map('trim', explode(',', $rid_string)));
$explode_or = array_filter(array_map('trim', explode('+', $rid_string)));
$intersection = array_intersect($explode_or, $account->getRoles());
if (!empty($intersection)) {
return AccessResult::allowed()->cachePerRole();
......
......@@ -50,7 +50,7 @@ protected function getTestRouteCollection() {
'_controller' => '\Drupal\router_test\TestControllers::test1',
),
array(
'_role' => 'role_test_1+role_test_2',
'_role' => 'role_test_1,role_test_2',
)
));
// Ensure that trimming the values works on "OR" conjunctions.
......@@ -59,7 +59,7 @@ protected function getTestRouteCollection() {
'_controller' => '\Drupal\router_test\TestControllers::test1',
),
array(
'_role' => 'role_test_1 + role_test_2',
'_role' => 'role_test_1 , role_test_2',
)
));
$route_collection->add('role_test_5', new Route('/role_test_5',
......@@ -67,7 +67,7 @@ protected function getTestRouteCollection() {
'_controller' => '\Drupal\router_test\TestControllers::test1',
),
array(
'_role' => 'role_test_1,role_test_2',
'_role' => 'role_test_1+role_test_2',
)
));
// Ensure that trimming the values works on "AND" conjunctions.
......@@ -76,7 +76,7 @@ protected function getTestRouteCollection() {
'_controller' => '\Drupal\router_test\TestControllers::test1',
),
array(
'_role' => 'role_test_1 , role_test_2',
'_role' => 'role_test_1 + role_test_2',
)
));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment