diff --git a/config/install/ucb_site_configuration.settings.yml b/config/install/ucb_site_configuration.settings.yml index ce626af..3617d94 100644 --- a/config/install/ucb_site_configuration.settings.yml +++ b/config/install/ucb_site_configuration.settings.yml @@ -1,5 +1,6 @@ # Editable site settings (non-theme) will go here +# Settings in "General" site_type: '' site_affiliation: '' site_affiliation_label: '' @@ -8,7 +9,13 @@ site_search_enabled: - default site_search_label: '' site_search_url: '' +gtm_account: '' +# Settings in "Content types" +article_date_format: '0' related_articles_enabled_by_default: FALSE related_articles_exclude_categories: [] related_articles_exclude_tags: [] +people_list_filter_1_label: '' +people_list_filter_2_label: '' +people_list_filter_3_label: '' diff --git a/src/Form/ContentTypesForm.php b/src/Form/ContentTypesForm.php new file mode 100644 index 0000000..3690213 --- /dev/null +++ b/src/Form/ContentTypesForm.php @@ -0,0 +1,183 @@ +entityTypeManager = $entityTypeManager; + $this->service = $service; + } + + /** + * {@inheritdoc} + * + * @param \Symfony\Component\DependencyInjection\ContainerInterface $container + * The container that allows getting any needed services. + * + * @link https://www.drupal.org/node/2133171 For more on dependency injection + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('config.factory'), + $container->get('entity_type.manager'), + $container->get('ucb_site_configuration') + ); + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['ucb_site_configuration.settings']; + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'ucb_site_configuration_pages_form'; + } + + /** + * {@inheritdoc} + * + * @see \Drupal\system\Form\SiteInformationForm::buildForm + * Contains the definition of a home page field. + */ + public function buildForm(array $form, FormStateInterface $form_state) { + $settings = $this->service->getSettings(); + $entityStorage = $this->entityTypeManager->getStorage('taxonomy_term'); + $categoryTerms = $entityStorage->loadByProperties(['vid' => 'category']); + $categoryOptions = []; + $tagTerms = $entityStorage->loadByProperties(['vid' => 'tags']); + $tagOptions = []; + foreach ($categoryTerms as $categoryTerm) { + $categoryOptions[$categoryTerm->id()] = $categoryTerm->label(); + } + foreach ($tagTerms as $tagTerm) { + $tagOptions[$tagTerm->id()] = $tagTerm->label(); + } + $form['article'] = [ + '#type' => 'details', + '#title' => $this->t('Article'), + '#open' => TRUE, + 'article_date_format' => [ + '#type' => 'select', + '#title' => $this->t('Article date format'), + '#default_value' => $settings->get('article_date_format') ?? '0', + '#options' => [ + $this->t('Short Date'), + $this->t('Medium Date'), + $this->t('Long Date'), + $this->t('Short Date with Time'), + $this->t('Medium Date with Time'), + $this->t('Long Date with Time'), + $this->t('None - Hide'), + ], + '#description' => $this->t('Select the date/time format for dates on articles.'), + ], + 'related_articles' => [ + '#type' => 'fieldset', + '#title' => $this->t('Related articles'), + 'related_articles_enabled_by_default' => [ + '#type' => 'checkbox', + '#title' => $this->t('Enable related articles by default for new articles'), + '#description' => $this->t('If enabled, related articles will default to on when creating a new article. A content author may still turn on or off related articles manually for an individual article.'), + '#default_value' => $settings->get('related_articles_enabled_by_default') ?? FALSE, + '#required' => FALSE, + ], + 'related_articles_exclude_categories' => [ + '#type' => 'checkboxes', + '#title' => $this->t('Exclude categories'), + '#default_value' => $settings->get('related_articles_exclude_categories') ?? [], + '#options' => $categoryOptions, + '#required' => FALSE, + ], + 'related_articles_exclude_tags' => [ + '#type' => 'checkboxes', + '#title' => $this->t('Exclude tags'), + '#default_value' => $settings->get('related_articles_exclude_tags') ?? [], + '#options' => $tagOptions, + '#required' => FALSE, + ], + ], + ]; + $form['people_list'] = [ + '#type' => 'details', + '#title' => $this->t('People List Page'), + '#open' => TRUE, + 'people_list_filter_1_label' => [ + '#type' => 'textfield', + '#title' => $this->t('Filter 1 label'), + '#default_value' => $settings->get('people_list_filter_1_label') ?? 'Filter 1', + '#description' => $this->t('Choose the label that will be used for "Filter 1" on People List Pages.'), + ], + 'people_list_filter_2_label' => [ + '#type' => 'textfield', + '#title' => $this->t('Filter 2 label'), + '#default_value' => $settings->get('people_list_filter_2_label') ?? 'Filter 2', + '#description' => $this->t('Choose the label that will be used for "Filter 2" on People List Pages.'), + ], + 'people_list_filter_3_label' => [ + '#type' => 'textfield', + '#title' => $this->t('Filter 3 label'), + '#default_value' => $settings->get('people_list_filter_3_label') ?? 'Filter 3', + '#description' => $this->t('Choose the label that will be used for "Filter 3" on People List Pages.'), + ], + ]; + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, FormStateInterface $form_state) { + $this->config('ucb_site_configuration.settings') + ->set('article_date_format', $form_state->getValue('article_date_format')) + ->set('related_articles_enabled_by_default', $form_state->getValue('related_articles_enabled_by_default')) + ->set('related_articles_exclude_categories', array_keys(array_filter($form_state->getValue('related_articles_exclude_categories')))) + ->set('related_articles_exclude_tags', array_keys(array_filter($form_state->getValue('related_articles_exclude_tags')))) + ->set('people_list_filter_1_label', $form_state->getValue('people_list_filter_1_label')) + ->set('people_list_filter_2_label', $form_state->getValue('people_list_filter_2_label')) + ->set('people_list_filter_3_label', $form_state->getValue('people_list_filter_3_label')) + ->save(); + parent::submitForm($form, $form_state); + } + +} diff --git a/src/Form/GeneralForm.php b/src/Form/GeneralForm.php index e5c6e20..c27789c 100644 --- a/src/Form/GeneralForm.php +++ b/src/Form/GeneralForm.php @@ -5,7 +5,10 @@ use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Path\PathValidatorInterface; +use Drupal\Core\Routing\RequestContext; use Drupal\Core\Session\AccountInterface; +use Drupal\path_alias\AliasManagerInterface; use Drupal\ucb_site_configuration\SiteConfiguration; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -14,6 +17,27 @@ */ class GeneralForm extends ConfigFormBase { + /** + * The path alias manager. + * + * @var \Drupal\path_alias\AliasManagerInterface + */ + protected $aliasManager; + + /** + * The path validator. + * + * @var \Drupal\Core\Path\PathValidatorInterface + */ + protected $pathValidator; + + /** + * The request context. + * + * @var \Drupal\Core\Routing\RequestContext + */ + protected $requestContext; + /** * The current user. * @@ -33,13 +57,22 @@ class GeneralForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. + * @param \Drupal\path_alias\AliasManagerInterface $alias_manager + * The path alias manager. + * @param \Drupal\Core\Path\PathValidatorInterface $path_validator + * The path validator. + * @param \Drupal\Core\Routing\RequestContext $request_context + * The request context. * @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, AccountInterface $user, SiteConfiguration $service) { + public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager, PathValidatorInterface $path_validator, RequestContext $request_context, AccountInterface $user, SiteConfiguration $service) { parent::__construct($config_factory); + $this->aliasManager = $alias_manager; + $this->pathValidator = $path_validator; + $this->requestContext = $request_context; $this->user = $user; $this->service = $service; } @@ -55,6 +88,9 @@ public function __construct(ConfigFactoryInterface $config_factory, AccountInter public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), + $container->get('path_alias.manager'), + $container->get('path.validator'), + $container->get('router.request_context'), $container->get('current_user'), $container->get('ucb_site_configuration') ); @@ -91,6 +127,15 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#default_value' => $systemSiteSettings->get('name'), '#required' => TRUE, ]; + $form['site_frontpage'] = [ + '#type' => 'textfield', + '#title' => $this->t('Home page'), + '#default_value' => $this->aliasManager->getAliasByPath($systemSiteSettings->get('page.front')), + '#required' => TRUE, + '#size' => 40, + '#description' => $this->t('Specify a relative URL to display as the site home page.'), + '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), + ]; if ($this->user->hasPermission('edit ucb site advanced')) { $advanced = [ '#type' => 'details', @@ -128,6 +173,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { ], 'site_affiliation_custom' => [ '#type' => 'fieldset', + '#title' => $this->t('Custom affiliation'), '#description' => $this->t('Define a title and optional URL for the custom affiliation.'), '#states' => [ 'visible' => [[':input[name="site_affiliation"]' => ['value' => 'custom']]], @@ -148,29 +194,125 @@ public function buildForm(array $form, FormStateInterface $form_state) { ], ], ]; + $siteSearchOptions = $configuration->get('site_search_options'); + $siteSearchEnabled = $settings->get('site_search_enabled'); + $advanced['site_search_enabled'] = [ + '#type' => 'fieldset', + '#title' => $this->t('Enable searching'), + ]; + foreach ($siteSearchOptions as $key => $value) { + $advanced['site_search_enabled']['site_search_enabled_' . $key] = [ + '#type' => 'checkbox', + '#title' => $value['label'], + '#default_value' => in_array($key, $siteSearchEnabled), + ]; + } + $advanced['site_search'] = [ + '#type' => 'fieldset', + '#title' => $this->t('Site search'), + '#states' => [ + 'visible' => [[':input[name="site_search_enabled_custom"]' => ['checked' => TRUE]]], + ], + ]; + $advanced['site_search']['site_search_label'] = [ + '#type' => 'textfield', + '#title' => $this->t('Label'), + '#default_value' => $settings->get('site_search_label'), + '#placeholder' => $siteSearchOptions['custom']['label'], + '#required' => FALSE, + '#size' => 32, + '#description' => $this->t('Leave blank to use the default label.'), + ]; + $advanced['site_search']['site_search_placeholder'] = [ + '#type' => 'textfield', + '#title' => $this->t('Placeholder'), + '#default_value' => $settings->get('site_search_placeholder'), + '#placeholder' => $siteSearchOptions['custom']['placeholder'], + '#required' => FALSE, + '#size' => 32, + '#description' => $this->t('Leave blank to use the default placeholder.'), + ]; + $advanced['site_search']['site_search_url'] = [ + '#type' => 'textfield', + '#title' => $this->t('Search page'), + '#default_value' => $settings->get('site_search_url') ? $this->aliasManager->getAliasByPath($settings->get('site_search_url')) : '', + '#states' => [ + 'required' => [[':input[name="site_search_enabled_custom"]' => ['checked' => TRUE]]], + ], + '#size' => 40, + '#description' => $this->t('Specify a relative URL to use as the site search page.'), + '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), + ]; + $advanced['gtm_account'] = [ + '#type' => 'textfield', + '#title' => $this->t('GTM Account Number'), + '#default_value' => $settings->get('gtm_account'), + '#description' => $this->t('Google Tag Manager account number e.g. GTM-123456.'), + ]; $form['advanced'] = $advanced; } return parent::buildForm($form, $form_state); } + /** + * {@inheritdoc} + * + * @see \Drupal\system\Form\SiteInformationForm::validateForm + * Contains the validation of a home page path. + */ + public function validateForm(array &$form, FormStateInterface $form_state) { + if (($value = $form_state->getValue('site_frontpage')) && $value[0] !== '/') { + $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_frontpage')])); + } + if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) { + $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is invalid.", ['%path' => $form_state->getValue('site_frontpage')])); + } + if ($this->user->hasPermission('edit ucb site advanced') && $form_state->getValues('site_search_enabled')['site_search_enabled_custom']) { + if (($value = $form_state->getValue('site_search_url')) && $value[0] !== '/') { + $form_state->setErrorByName('site_search_url', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_search_url')])); + } + if (!$this->pathValidator->isValid($form_state->getValue('site_search_url'))) { + $form_state->setErrorByName('site_search_url', $this->t("The path '%path' is invalid.", ['%path' => $form_state->getValue('site_search_url')])); + } + } + } + /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $configuration = $this->service->getConfiguration(); $siteTypeOptions = $configuration->get('site_type_options'); - $this->config('system.site')->set('name', $form_state->getValue('site_name'))->save(); - $siteTypeId = $form_state->getValue('site_type'); - $siteAffiliationId = $form_state->getValue('site_affiliation'); - if ($siteTypeId && isset($siteTypeOptions[$siteTypeId]) && isset($siteTypeOptions[$siteTypeId]['affiliation'])) { - $siteAffiliationId = $siteTypeOptions[$siteTypeId]['affiliation']; - } - $this->config('ucb_site_configuration.settings') - ->set('site_type', $siteTypeId) - ->set('site_affiliation', $siteAffiliationId) - ->set('site_affiliation_label', $form_state->getValue('site_affiliation_label')) - ->set('site_affiliation_url', $form_state->getValue('site_affiliation_url')) + $this->config('system.site') + ->set('name', $form_state->getValue('site_name')) + ->set('page.front', $form_state->getValue('site_frontpage')) ->save(); + if ($this->user->hasPermission('edit ucb site advanced')) { + $siteTypeId = $form_state->getValue('site_type'); + $siteAffiliationId = $form_state->getValue('site_affiliation'); + if ($siteTypeId && isset($siteTypeOptions[$siteTypeId]) && isset($siteTypeOptions[$siteTypeId]['affiliation'])) { + $siteAffiliationId = $siteTypeOptions[$siteTypeId]['affiliation']; + } + $siteSearchEnabled = []; + $siteSearchEnabledFormValues = $form_state->getValues('site_search_enabled'); + $siteSearchFormValues = $form_state->getValues('site_search'); + foreach ($configuration->get('site_search_options') as $key => $value) { + if ($siteSearchEnabledFormValues['site_search_enabled_' . $key]) { + $siteSearchEnabled[] = $key; + } + } + $this->config('ucb_site_configuration.settings') + ->set('site_type', $siteTypeId) + ->set('site_affiliation', $siteAffiliationId) + ->set('site_affiliation_label', $form_state->getValue('site_affiliation_label')) + ->set('site_affiliation_url', $form_state->getValue('site_affiliation_url')) + ->set('site_search_enabled', $siteSearchEnabled) + ->set('site_search_label', $siteSearchFormValues['site_search_label']) + ->set('site_search_placeholder', $siteSearchFormValues['site_search_placeholder']) + ->set('site_search_url', $siteSearchFormValues['site_search_url']) + ->set('gtm_account', $form_state->getValue('gtm_account')) + ->save(); + } parent::submitForm($form, $form_state); } diff --git a/src/Form/PagesForm.php b/src/Form/PagesForm.php deleted file mode 100644 index ae1ca34..0000000 --- a/src/Form/PagesForm.php +++ /dev/null @@ -1,218 +0,0 @@ -aliasManager = $alias_manager; - $this->pathValidator = $path_validator; - $this->requestContext = $request_context; - $this->service = $service; - } - - /** - * {@inheritdoc} - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * The container that allows getting any needed services. - * - * @link https://www.drupal.org/node/2133171 For more on dependency injection - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('path_alias.manager'), - $container->get('path.validator'), - $container->get('router.request_context'), - $container->get('ucb_site_configuration') - ); - } - - /** - * {@inheritdoc} - */ - protected function getEditableConfigNames() { - return ['system.site', 'ucb_site_configuration.settings']; - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'ucb_site_configuration_pages_form'; - } - - /** - * {@inheritdoc} - * - * @see \Drupal\system\Form\SiteInformationForm::buildForm - * Contains the definition of a home page field. - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $configuration = $this->service->getConfiguration(); - $settings = $this->service->getSettings(); - $systemSiteSettings = $this->config('system.site'); - $siteSearchOptions = $configuration->get('site_search_options'); - $siteSearchEnabled = $settings->get('site_search_enabled'); - $form['site_frontpage'] = [ - '#type' => 'textfield', - '#title' => $this->t('Home page'), - '#default_value' => $this->aliasManager->getAliasByPath($systemSiteSettings->get('page.front')), - '#required' => TRUE, - '#size' => 40, - '#description' => $this->t('Specify a relative URL to display as the site home page.'), - '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), - ]; - $form['site_search_enabled'] = [ - '#type' => 'fieldset', - '#title' => $this->t('Enable searching'), - ]; - foreach ($siteSearchOptions as $key => $value) { - $form['site_search_enabled']['site_search_enabled_' . $key] = [ - '#type' => 'checkbox', - '#title' => $value['label'], - '#default_value' => in_array($key, $siteSearchEnabled), - ]; - } - $form['site_search'] = [ - '#type' => 'fieldset', - '#title' => $this->t('Site search'), - '#states' => [ - 'visible' => [[':input[name="site_search_enabled_custom"]' => ['checked' => TRUE]]], - ], - ]; - $form['site_search']['site_search_label'] = [ - '#type' => 'textfield', - '#title' => $this->t('Label'), - '#default_value' => $settings->get('site_search_label'), - '#placeholder' => $siteSearchOptions['custom']['label'], - '#required' => FALSE, - '#size' => 32, - '#description' => $this->t('Leave blank to use the default label.'), - ]; - $form['site_search']['site_search_placeholder'] = [ - '#type' => 'textfield', - '#title' => $this->t('Placeholder'), - '#default_value' => $settings->get('site_search_placeholder'), - '#placeholder' => $siteSearchOptions['custom']['placeholder'], - '#required' => FALSE, - '#size' => 32, - '#description' => $this->t('Leave blank to use the default placeholder.'), - ]; - $form['site_search']['site_search_url'] = [ - '#type' => 'textfield', - '#title' => $this->t('Search page'), - '#default_value' => $settings->get('site_search_url') ? $this->aliasManager->getAliasByPath($settings->get('site_search_url')) : '', - '#states' => [ - 'required' => [[':input[name="site_search_enabled_custom"]' => ['checked' => TRUE]]], - ], - '#size' => 40, - '#description' => $this->t('Specify a relative URL to use as the site search page.'), - '#field_prefix' => $this->requestContext->getCompleteBaseUrl(), - ]; - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - * - * @see \Drupal\system\Form\SiteInformationForm::validateForm - * Contains the validation of a home page path. - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - if (($value = $form_state->getValue('site_frontpage')) && $value[0] !== '/') { - $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_frontpage')])); - } - if (!$this->pathValidator->isValid($form_state->getValue('site_frontpage'))) { - $form_state->setErrorByName('site_frontpage', $this->t("The path '%path' is invalid.", ['%path' => $form_state->getValue('site_frontpage')])); - } - if ($form_state->getValues('site_search_enabled')['site_search_enabled_custom']) { - if (($value = $form_state->getValue('site_search_url')) && $value[0] !== '/') { - $form_state->setErrorByName('site_search_url', $this->t("The path '%path' has to start with a slash.", ['%path' => $form_state->getValue('site_search_url')])); - } - if (!$this->pathValidator->isValid($form_state->getValue('site_search_url'))) { - $form_state->setErrorByName('site_search_url', $this->t("The path '%path' is invalid.", ['%path' => $form_state->getValue('site_search_url')])); - } - } - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $configuration = $this->service->getConfiguration(); - $siteSearchEnabled = []; - $siteSearchEnabledFormValues = $form_state->getValues('site_search_enabled'); - $siteSearchFormValues = $form_state->getValues('site_search'); - foreach ($configuration->get('site_search_options') as $key => $value) { - if ($siteSearchEnabledFormValues['site_search_enabled_' . $key]) { - $siteSearchEnabled[] = $key; - } - } - $this->config('ucb_site_configuration.settings') - ->set('site_search_enabled', $siteSearchEnabled) - ->set('site_search_label', $siteSearchFormValues['site_search_label']) - ->set('site_search_placeholder', $siteSearchFormValues['site_search_placeholder']) - ->set('site_search_url', $siteSearchFormValues['site_search_url']) - ->save(); - $this->config('system.site')->set('page.front', $form_state->getValue('site_frontpage'))->save(); - parent::submitForm($form, $form_state); - } - -} diff --git a/src/Form/RelatedArticlesForm.php b/src/Form/RelatedArticlesForm.php deleted file mode 100644 index 637647c..0000000 --- a/src/Form/RelatedArticlesForm.php +++ /dev/null @@ -1,124 +0,0 @@ -entityTypeManager = $entityTypeManager; - $this->service = $service; - } - - /** - * {@inheritdoc} - * - * @param \Symfony\Component\DependencyInjection\ContainerInterface $container - * The container that allows getting any needed services. - * - * @link https://www.drupal.org/node/2133171 For more on dependency injection - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity_type.manager'), - $container->get('ucb_site_configuration') - ); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'ucb_site_configuration_related_articles_form'; - } - - /** - * {@inheritdoc} - */ - protected function getEditableConfigNames() { - return ['ucb_site_configuration.settings']; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $settings = $this->service->getSettings(); - $entityStorage = $this->entityTypeManager->getStorage('taxonomy_term'); - $categoryTerms = $entityStorage->loadByProperties(['vid' => 'category']); - $categoryOptions = []; - $tagTerms = $entityStorage->loadByProperties(['vid' => 'tags']); - $tagOptions = []; - foreach ($categoryTerms as $categoryTerm) { - $categoryOptions[$categoryTerm->id()] = $categoryTerm->label(); - } - foreach ($tagTerms as $tagTerm) { - $tagOptions[$tagTerm->id()] = $tagTerm->label(); - } - $form['enabled_by_default'] = [ - '#type' => 'checkbox', - '#title' => $this->t('Enable related articles by default for new articles'), - '#description' => $this->t('If enabled, related articles will default to on when creating a new article. A content author may still turn on or off related articles manually for an individual article.'), - '#default_value' => $settings->get('related_articles_enabled_by_default') ?? FALSE, - '#required' => FALSE, - ]; - $form['exclude_categories'] = [ - '#type' => 'checkboxes', - '#title' => $this->t('Exclude categories'), - '#default_value' => $settings->get('related_articles_exclude_categories') ?? [], - '#options' => $categoryOptions, - '#required' => FALSE, - ]; - $form['exclude_tags'] = [ - '#type' => 'checkboxes', - '#title' => $this->t('Exclude tags'), - '#default_value' => $settings->get('related_articles_exclude_tags') ?? [], - '#options' => $tagOptions, - '#required' => FALSE, - ]; - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->config('ucb_site_configuration.settings') - ->set('related_articles_enabled_by_default', $form_state->getValue('enabled_by_default')) - ->set('related_articles_exclude_categories', array_keys(array_filter($form_state->getValue('exclude_categories')))) - ->set('related_articles_exclude_tags', array_keys(array_filter($form_state->getValue('exclude_tags')))) - ->save(); - parent::submitForm($form, $form_state); - } - -} diff --git a/src/SiteConfiguration.php b/src/SiteConfiguration.php index e73f50d..5b17ad5 100644 --- a/src/SiteConfiguration.php +++ b/src/SiteConfiguration.php @@ -157,8 +157,8 @@ public function buildThemeSettingsForm(array &$form, FormStateInterface &$form_s '#options' => [ $this->t('Black'), $this->t('White'), - $this->t('Light'), - $this->t('Dark'), + $this->t('Light Gray'), + $this->t('Dark Gray'), ], '#description' => $this->t('Select the color for the header background for the site information at the top of the page.'), ]; @@ -209,13 +209,6 @@ public function buildThemeSettingsForm(array &$form, FormStateInterface &$form_s '#description' => $this->t('The sticky menu appears at the top of the page when scrolling on large-screen devices, allowing for quick access to links.'), ]; - $form['ucb_gtm_account'] = [ - '#type' => 'textfield', - '#title' => $this->t('GTM Account Number'), - '#default_value' => theme_get_setting('ucb_gtm_account', $themeName), - '#description' => $this->t('Google Tag Manager account number e.g. GTM-123456.'), - ]; - $form['ucb_secondary_menu_position'] = [ '#type' => 'select', '#title' => $this->t('Position of the secondary menu'), @@ -248,42 +241,6 @@ public function buildThemeSettingsForm(array &$form, FormStateInterface &$form_s ], '#description' => $this->t('Select the location for social sharing links (Facebook, Twitter, etc) to appear on your pages.'), ]; - // Choose date/time format sitewide. - $form['ucb_date_format'] = [ - '#type' => 'select', - '#title' => $this->t('Display settings for Date formats on Articles'), - '#default_value' => theme_get_setting('ucb_date_format', $themeName), - '#options' => [ - $this->t('Short Date'), - $this->t('Medium Date'), - $this->t('Long Date'), - $this->t('Short Date with Time'), - $this->t('Medium Date with Time'), - $this->t('Long Date with Time'), - $this->t('None - Hide'), - ], - '#description' => $this->t('Select the preferred Global Date/Time format for dates on your site.'), - ]; - // Custom labels for filters 1-3 on People List Pages - $form['ucb_filter_1_label'] = [ - '#type' => 'textfield', - '#title' => $this->t('Filter 1 Label'), - '#default_value' => theme_get_setting('ucb_filter_1_label', $themeName), - '#description' => $this->t('Choose the label that will be used for "Filter 1" on People List Pages'), - ]; - $form['ucb_filter_2_label'] = [ - '#type' => 'textfield', - '#title' => $this->t('Filter 2 Label'), - '#default_value' => theme_get_setting('ucb_filter_2_label', $themeName), - '#description' => $this->t('Choose the label that will be used for "Filter 2" on People List Pages'), - ]; - $form['ucb_filter_3_label'] = [ - '#type' => 'textfield', - '#title' => $this->t('Filter 3 Label'), - '#default_value' => theme_get_setting('ucb_filter_3_label', $themeName), - '#description' => $this->t('Choose the label that will be used for "Filter 3" on People List Pages'), - ]; - if ($this->user->hasPermission('edit ucb site advanced')) { $form['advanced'] = [ '#type' => 'details', @@ -391,17 +348,31 @@ public function attachSiteInformation(array &$variables) { } /** - * Attaches related articles configuration to Articles. + * Attaches configuration to Articles. * * @param array &$variables * The array to add the site information to. */ - public function attachRelatedArticlesConfiguration(array &$variables) { + public function attachArticlesConfiguration(array &$variables) { $settings = $this->getSettings(); + $variables['article_date_format'] = $settings->get('article_date_format') ?? '0'; $variables['related_articles_exclude_categories'] = $settings->get('related_articles_exclude_categories') ?? []; $variables['related_articles_exclude_tags'] = $settings->get('related_articles_exclude_tags') ?? []; } + /** + * Attaches configuration to People Lists. + * + * @param array &$variables + * The array to add the site information to. + */ + public function attachPeopleListConfiguration(array &$variables) { + $settings = $this->getSettings(); + $variables['people_list_filter_1_label'] = $settings->get('people_list_filter_1_label') ?? 'Filter 1'; + $variables['people_list_filter_2_label'] = $settings->get('people_list_filter_1_label') ?? 'Filter 2'; + $variables['people_list_filter_3_label'] = $settings->get('people_list_filter_1_label') ?? 'Filter 3'; + } + /** * Attaches external service includes. * diff --git a/ucb_site_configuration.info.yml b/ucb_site_configuration.info.yml index 56ab752..2160931 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.2' +version: '2.6' package: CU Boulder dependencies: - block diff --git a/ucb_site_configuration.links.menu.yml b/ucb_site_configuration.links.menu.yml index 396286d..213cb0c 100644 --- a/ucb_site_configuration.links.menu.yml +++ b/ucb_site_configuration.links.menu.yml @@ -17,10 +17,10 @@ ucb_site_configuration.appearance_form: route_name: ucb_site_configuration.appearance_form parent: ucb_site_configuration weight: 1 -ucb_site_configuration.pages_form: - title: Pages and search - description: 'Change the site home page or search options.' - route_name: ucb_site_configuration.pages_form +ucb_site_configuration.content_types_form: + title: Content types + description: 'Change settings for specific content types.' + route_name: ucb_site_configuration.content_types_form parent: ucb_site_configuration weight: 2 ucb_site_configuration.contact_info_form: @@ -29,15 +29,9 @@ ucb_site_configuration.contact_info_form: route_name: ucb_site_configuration.contact_info_form parent: ucb_site_configuration weight: 3 -ucb_site_configuration.related_articles_form: - title: Related articles - description: 'Exclude categories or tags from related articles.' - route_name: ucb_site_configuration.related_articles_form - parent: ucb_site_configuration - weight: 4 ucb_site_configuration.external_services: title: Third-party services description: 'Configure third-party services to be used on the site.' route_name: entity.ucb_external_service_include.collection parent: ucb_site_configuration - weight: 5 + weight: 4 diff --git a/ucb_site_configuration.links.task.yml b/ucb_site_configuration.links.task.yml index e643296..37d100b 100644 --- a/ucb_site_configuration.links.task.yml +++ b/ucb_site_configuration.links.task.yml @@ -8,9 +8,9 @@ ucb_site_configuration.appearance_form: title: 'Appearance and layout' base_route: ucb_site_configuration weight: 1 -ucb_site_configuration.pages_form: - route_name: ucb_site_configuration.pages_form - title: 'Pages and search' +ucb_site_configuration.content_types_form: + route_name: ucb_site_configuration.content_types_form + title: 'Content types' base_route: ucb_site_configuration weight: 2 ucb_site_configuration.contact_info_form: @@ -18,13 +18,8 @@ ucb_site_configuration.contact_info_form: title: 'Contact info' base_route: ucb_site_configuration weight: 3 -ucb_site_configuration.related_articles_form: - route_name: ucb_site_configuration.related_articles_form - title: 'Related articles' - base_route: ucb_site_configuration - weight: 4 ucb_site_configuration.external_services: route_name: entity.ucb_external_service_include.collection title: 'Third-party services' base_route: ucb_site_configuration - weight: 5 + weight: 4 diff --git a/ucb_site_configuration.module b/ucb_site_configuration.module index 0525934..f1c4715 100644 --- a/ucb_site_configuration.module +++ b/ucb_site_configuration.module @@ -36,7 +36,11 @@ function ucb_site_configuration_preprocess_node(array &$variables) { /** @var \Drupal\node\NodeInterface */ $node = $variables['node']; if ($node->getType() === 'ucb_article') { - \Drupal::service('ucb_site_configuration')->attachRelatedArticlesConfiguration($variables); + \Drupal::service('ucb_site_configuration')->attachArticlesConfiguration($variables); + $variables['#cache']['tags'][] = 'config:ucb_site_configuration.settings'; + } + elseif ($node->getType() === 'ucb_people_list_page') { + \Drupal::service('ucb_site_configuration')->attachPeopleListConfiguration($variables); $variables['#cache']['tags'][] = 'config:ucb_site_configuration.settings'; } } diff --git a/ucb_site_configuration.permissions.yml b/ucb_site_configuration.permissions.yml index 5f4af86..7a6c3d2 100644 --- a/ucb_site_configuration.permissions.yml +++ b/ucb_site_configuration.permissions.yml @@ -2,22 +2,18 @@ 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.' -edit ucb site pages: - title: Change the site homepage - description: 'Enables changing the site homepage.' - edit ucb site appearance: title: Edit the site appearance description: 'Enables editing of the CU Boulder site appearance.' +edit ucb site content types: + title: Configure content types + description: 'Enables configuring CU Boulder-provided content types.' + edit ucb site contact info: title: Edit the site contact info description: 'Enables editing of the CU Boulder site contact info.' -configure ucb related articles: - title: Configure related articles - description: 'Exclude categories or tags from related articles.' - administer ucb external services: title: Administer third-party services description: 'Enables adding, editing, and deleting supported third-party services.' diff --git a/ucb_site_configuration.routing.yml b/ucb_site_configuration.routing.yml index 3b233cc..e69d4a7 100644 --- a/ucb_site_configuration.routing.yml +++ b/ucb_site_configuration.routing.yml @@ -30,13 +30,13 @@ ucb_site_configuration.appearance_form: options: _admin_route: true -ucb_site_configuration.pages_form: - path: '/admin/config/cu-boulder/pages' +ucb_site_configuration.content_types_form: + path: '/admin/config/cu-boulder/content-types' defaults: - _form: '\Drupal\ucb_site_configuration\Form\PagesForm' - _title: Pages and search + _form: '\Drupal\ucb_site_configuration\Form\ContentTypesForm' + _title: Content types requirements: - _permission: edit ucb site pages + _permission: edit ucb site content types options: _admin_route: true @@ -50,16 +50,6 @@ ucb_site_configuration.contact_info_form: options: _admin_route: true -ucb_site_configuration.related_articles_form: - path: '/admin/config/cu-boulder/related-articles' - defaults: - _form: '\Drupal\ucb_site_configuration\Form\RelatedArticlesForm' - _title: Related articles - requirements: - _permission: configure ucb related articles - options: - _admin_route: true - entity.ucb_external_service_include.collection: path: '/admin/config/cu-boulder/services' defaults: