File tree 1 file changed +15
-4
lines changed
modules/custom/social_language/src
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 7
7
use Drupal \Core \Routing \Access \AccessInterface ;
8
8
use Drupal \Core \Routing \RouteMatchInterface ;
9
9
use Drupal \Core \Session \AccountInterface ;
10
+ use Symfony \Component \Routing \Route ;
10
11
11
12
/**
12
13
* Class Access.
@@ -49,12 +50,22 @@ public function __construct(LanguageManagerInterface $language_manager) {
49
50
*/
50
51
public function access (RouteMatchInterface $ route_match , AccountInterface $ account , $ permission = NULL ) {
51
52
if (count ($ this ->languageManager ->getLanguages ()) > 1 ) {
52
- if (!empty ($ permission )) {
53
- return AccessResult::allowedIfHasPermission ($ account , $ permission );
53
+ // If the permission is null the service was not called,
54
+ // and we should get it from the route object.
55
+ if (is_null ($ permission )) {
56
+ // Get route object.
57
+ $ route = $ route_match ->getRouteObject ();
58
+ assert ($ route instanceof Route);
59
+
60
+ // Get defined permission on _social_language_access.
61
+ $ permission = $ route ->getRequirements ()['_social_language_access ' ];
54
62
}
55
- else {
56
- return AccessResult::allowed ();
63
+
64
+ if (is_string ($ permission )) {
65
+ return AccessResult::allowedIfHasPermission ($ account , $ permission );
57
66
}
67
+
68
+ return AccessResult::neutral ();
58
69
}
59
70
60
71
return AccessResult::forbidden ();
You can’t perform that action at this time.
0 commit comments