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

Issue #3442988 by eiriksm: Make it possible to edit team name

parent f2bf481f
No related branches found
No related tags found
1 merge request!52Expose team name but only for admins
Pipeline #154702 passed with warnings
......@@ -27,7 +27,7 @@ final class InviteController extends ControllerBase {
EntityTypeManagerInterface $entityTypeManager,
AccountProxyInterface $currentUser,
ModuleHandlerInterface $moduleHandler,
private SessionInterface $session
private SessionInterface $session,
) {
$this->entityTypeManager = $entityTypeManager;
$this->currentUser = $currentUser;
......
......@@ -31,9 +31,10 @@ final class InviteMembersForm extends FormBase {
/**
* The constructor.
*/
public function __construct(CurrentRouteMatch $routeMatch,
public function __construct(
CurrentRouteMatch $routeMatch,
private TeamManager $teamManager,
private AccountProxyInterface $currentUser
private AccountProxyInterface $currentUser,
) {
$this->routeMatch = $routeMatch;
$team = $this->routeMatch->getParameter('team');
......
......@@ -7,6 +7,7 @@ namespace Drupal\violinist_teams\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\CurrentRouteMatch;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\violinist_teams\TeamNode;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -16,6 +17,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
final class TeamSettingsForm extends FormBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected AccountProxyInterface $currentUser;
/**
* Team node.
*
......@@ -26,8 +34,9 @@ final class TeamSettingsForm extends FormBase {
/**
* The constructor.
*/
public function __construct(CurrentRouteMatch $current_route_match) {
public function __construct(CurrentRouteMatch $current_route_match, AccountProxyInterface $current_user) {
$this->routeMatch = $current_route_match;
$this->currentUser = $current_user;
$team = $this->routeMatch->getParameter('team');
if ($team instanceof TeamNode) {
$this->team = $team;
......@@ -39,7 +48,8 @@ final class TeamSettingsForm extends FormBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('current_route_match')
$container->get('current_route_match'),
$container->get('current_user')
);
}
......@@ -58,6 +68,32 @@ final class TeamSettingsForm extends FormBase {
if (!$team instanceof TeamNode) {
return $form;
}
$form['title'] = [
'#type' => 'textfield',
'#title' => $this->t('Team Name'),
'#required' => TRUE,
'#default_value' => $team->getTitle(),
];
if (!$team->isAdmin($this->currentUser)) {
$form['title']['#description'] = $this->t('Only administrators can change the team name.');
$form['title']['#disabled'] = TRUE;
$form['title']['#attributes']['readonly'] = 'readonly';
$form['title']['#attributes']['disabled'] = 'disabled';
}
$form['slack'] = [
'#type' => 'details',
'#title' => $this->t('Slack settings'),
'#open' => TRUE,
];
$form['slack']['enable_slack_notifications'] = [
'#type' => 'checkbox',
'#default_value' => $team->isNotificationsEnabledForSlack(),
'#title' => $this->t('Enable Slack notifications'),
];
if (!$team->getTeamSlackWebhook()) {
$form['slack']['enable_slack_notifications']['#disabled'] = TRUE;
$form['slack']['enable_slack_notifications']['#description'] = $this->getSlackDescription();
}
$form['slack'] = [
'#type' => 'details',
'#title' => $this->t('Slack settings'),
......@@ -109,6 +145,9 @@ final class TeamSettingsForm extends FormBase {
if (!$team instanceof TeamNode) {
return;
}
if ($this->team->isAdmin($this->currentUser)) {
$team->setTitle($form_state->getValue('title'));
}
$team
->set(TeamNode::SLACK_NOTIFICATION_ENABLED_FIELD, $form_state->getValue('enable_slack_notifications'))
->save();
......
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