Skip to content
Snippets Groups Projects
Commit 251e8b96 authored by Eirik Morland's avatar Eirik Morland
Browse files

Issue #3440544 by eiriksm: Remove team settings controller and use access service instead

parent 81d69619
No related branches found
No related tags found
1 merge request!49clean up
Pipeline #145141 passed with warnings
<?php
namespace Drupal\violinist_teams\Controller;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\violinist_teams\TeamNode;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Controller that currently only controls the access.
*/
class TeamSettingsController extends ControllerBase {
/**
* Construct this controller.
*/
public function __construct(AccountProxyInterface $currentUser) {
$this->currentUser = $currentUser;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_user')
);
}
/**
* Access callback for a couple things.
*/
public function accessTeamSettings(TeamNode $team) {
// Admins on the site should be able to access it.
if ($team->access('update', $this->currentUser)) {
return AccessResult::allowed();
}
return AccessResult::allowedIf(in_array($this->currentUser->id(), $team->getAdministratorIds()));
}
}
......@@ -32,7 +32,7 @@ violinist_teams.team_settings:
team:
type: entity:node
requirements:
_custom_access: '\Drupal\violinist_teams\Controller\TeamSettingsController::accessTeamSettings'
_violinist_teams_access: 'admin_or_member'
violinist_teams.team_members:
path: '/teams/{team}/members'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment