From 04c999274829ed759f0532ba60973bce59fb3b32 Mon Sep 17 00:00:00 2001 From: Timur Tripp Date: Mon, 27 Nov 2023 11:23:30 -0700 Subject: [PATCH 1/3] CuBoulder/ucb_site_configuration#33 moves site type and affiliation into an "Advanced" section --- src/Form/GeneralForm.php | 105 ++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 46 deletions(-) diff --git a/src/Form/GeneralForm.php b/src/Form/GeneralForm.php index 1e1e3b0..e5c6e20 100644 --- a/src/Form/GeneralForm.php +++ b/src/Form/GeneralForm.php @@ -5,6 +5,7 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Session\AccountInterface; use Drupal\ucb_site_configuration\SiteConfiguration; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -14,11 +15,11 @@ class GeneralForm extends ConfigFormBase { /** - * The request context. + * The current user. * - * @var \Drupal\Core\Routing\RequestContext + * @var \Drupal\Core\Session\AccountInterface */ - protected $requestContext; + protected $user; /** * The site configuration service defined in this module. @@ -32,11 +33,14 @@ class GeneralForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. + * @param \Drupal\Core\Session\AccountInterface $user + * The current user. * @param \Drupal\ucb_site_configuration\SiteConfiguration $service * The site configuration service defined in this module. */ - public function __construct(ConfigFactoryInterface $config_factory, SiteConfiguration $service) { + public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $user, SiteConfiguration $service) { parent::__construct($config_factory); + $this->user = $user; $this->service = $service; } @@ -51,6 +55,7 @@ public function __construct(ConfigFactoryInterface $config_factory, SiteConfigur public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), + $container->get('current_user'), $container->get('ucb_site_configuration') ); } @@ -86,57 +91,65 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $systemSiteSettings->get('name'), '#required' => TRUE, ]; - $form['site_type'] = [ - '#type' => 'select', - '#title' => $this->t('Type'), - '#default_value' => $settings->get('site_type'), - '#options' => array_merge(['' => $this->t('- None -')], array_map(function ($value) { - return $value['label']; - }, $siteTypeOptions)), - '#required' => FALSE, - ]; - $affiliationHidesOn = []; - foreach ($siteTypeOptions as $siteTypeId => $siteType) { - if (isset($siteType['affiliation'])) { - array_push($affiliationHidesOn, [':input[name="site_type"]' => ['value' => $siteTypeId]]); - } - } - $form['site_affiliation_container'] = [ - '#type' => 'container', - '#states' => [ - 'invisible' => $affiliationHidesOn, - ], - 'site_affiliation' => [ + if ($this->user->hasPermission('edit ucb site advanced')) { + $advanced = [ + '#type' => 'details', + '#title' => $this->t('Advanced'), + '#open' => FALSE, + ]; + $advanced['site_type'] = [ '#type' => 'select', - '#title' => $this->t('Affiliation'), - '#default_value' => $settings->get('site_affiliation'), + '#title' => $this->t('Type'), + '#default_value' => $settings->get('site_type'), '#options' => array_merge(['' => $this->t('- None -')], array_map(function ($value) { return $value['label']; - }, $siteAffiliationOptions), ['custom' => $this->t('Custom')]), + }, $siteTypeOptions)), '#required' => FALSE, - ], - 'site_affiliation_custom' => [ - '#type' => 'fieldset', - '#description' => $this->t('Define a title and optional URL for the custom affiliation.'), + ]; + $affiliationHidesOn = []; + foreach ($siteTypeOptions as $siteTypeId => $siteType) { + if (isset($siteType['affiliation'])) { + array_push($affiliationHidesOn, [':input[name="site_type"]' => ['value' => $siteTypeId]]); + } + } + $advanced['site_affiliation_container'] = [ + '#type' => 'container', '#states' => [ - 'visible' => [[':input[name="site_affiliation"]' => ['value' => 'custom']]], + 'invisible' => $affiliationHidesOn, ], - 'site_affiliation_label' => [ - '#type' => 'textfield', - '#title' => $this->t('Title'), - '#default_value' => $settings->get('site_affiliation_label'), + 'site_affiliation' => [ + '#type' => 'select', + '#title' => $this->t('Affiliation'), + '#default_value' => $settings->get('site_affiliation'), + '#options' => array_merge(['' => $this->t('- None -')], array_map(function ($value) { + return $value['label']; + }, $siteAffiliationOptions), ['custom' => $this->t('Custom')]), '#required' => FALSE, - '#maxlength' => 255, ], - 'site_affiliation_url' => [ - '#type' => 'textfield', - '#title' => $this->t('URL'), - '#default_value' => $settings->get('site_affiliation_url'), - '#required' => FALSE, - '#maxlength' => 255, + 'site_affiliation_custom' => [ + '#type' => 'fieldset', + '#description' => $this->t('Define a title and optional URL for the custom affiliation.'), + '#states' => [ + 'visible' => [[':input[name="site_affiliation"]' => ['value' => 'custom']]], + ], + 'site_affiliation_label' => [ + '#type' => 'textfield', + '#title' => $this->t('Title'), + '#default_value' => $settings->get('site_affiliation_label'), + '#required' => FALSE, + '#maxlength' => 255, + ], + 'site_affiliation_url' => [ + '#type' => 'textfield', + '#title' => $this->t('URL'), + '#default_value' => $settings->get('site_affiliation_url'), + '#required' => FALSE, + '#maxlength' => 255, + ], ], - ], - ]; + ]; + $form['advanced'] = $advanced; + } return parent::buildForm($form, $form_state); } From e3441579d9e10037d971c16a4ff62cc9c25c6f44 Mon Sep 17 00:00:00 2001 From: Timur Tripp Date: Mon, 27 Nov 2023 11:36:05 -0700 Subject: [PATCH 2/3] CuBoulder/ucb_site_configuration#33 modifies "General" menu item description --- ucb_site_configuration.links.menu.yml | 2 +- ucb_site_configuration.permissions.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ucb_site_configuration.links.menu.yml b/ucb_site_configuration.links.menu.yml index 485fdff..396286d 100644 --- a/ucb_site_configuration.links.menu.yml +++ b/ucb_site_configuration.links.menu.yml @@ -7,7 +7,7 @@ ucb_site_configuration: ucb_site_configuration.general_form: title: General - description: 'Modify the site name, type, or affiliation.' + description: 'Modify general site information.' route_name: ucb_site_configuration.general_form parent: ucb_site_configuration weight: 0 diff --git a/ucb_site_configuration.permissions.yml b/ucb_site_configuration.permissions.yml index 1223a36..5f4af86 100644 --- a/ucb_site_configuration.permissions.yml +++ b/ucb_site_configuration.permissions.yml @@ -1,6 +1,6 @@ edit ucb site general: title: Edit the site general settings - description: 'Enables editing of the CU Boulder general site settings and information such as the site name, type, and affiliation.' + description: 'Enables editing of the CU Boulder general site settings and information such as the site name.' edit ucb site pages: title: Change the site homepage From 1b61bdd084f24b6c433ed0d57bb4a09bfa2874bc Mon Sep 17 00:00:00 2001 From: Timur Tripp Date: Mon, 27 Nov 2023 11:37:52 -0700 Subject: [PATCH 3/3] Bumps version --- ucb_site_configuration.info.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucb_site_configuration.info.yml b/ucb_site_configuration.info.yml index 5b5c2a1..56ab752 100644 --- a/ucb_site_configuration.info.yml +++ b/ucb_site_configuration.info.yml @@ -2,7 +2,7 @@ name: CU Boulder Site Configuration description: 'Allows CU Boulder site administrators to configure site-specific settings.' core_version_requirement: ^9 || ^10 type: module -version: '2.5.1' +version: '2.5.2' package: CU Boulder dependencies: - block