Skip to content

Commit

Permalink
Merge pull request #34 from CuBoulder/issue/33
Browse files Browse the repository at this point in the history
CU Boulder Site Configuration 2.5.2
  • Loading branch information
jcsparks authored Nov 27, 2023
2 parents 626db18 + 1b61bdd commit 2467b3c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 49 deletions.
105 changes: 59 additions & 46 deletions src/Form/GeneralForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
Expand All @@ -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;
}

Expand All @@ -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')
);
}
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion ucb_site_configuration.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ucb_site_configuration.links.menu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ucb_site_configuration.permissions.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2467b3c

Please sign in to comment.