From 7155de5eb36112bea747f1f81085ba3d9957d3c8 Mon Sep 17 00:00:00 2001 From: Timur Tripp Date: Thu, 26 Oct 2023 15:21:27 -0600 Subject: [PATCH] CuBoulder/tiamat-theme#266 exposes `site_search` to theme; adds minor cleanup --- src/Form/GeneralForm.php | 14 +------------- src/Form/PagesForm.php | 14 +------------- src/SiteConfiguration.php | 22 ++++++++++++++++++++++ ucb_site_configuration.links.menu.yml | 8 ++++---- ucb_site_configuration.links.task.yml | 4 ++-- ucb_site_configuration.routing.yml | 4 ++-- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/Form/GeneralForm.php b/src/Form/GeneralForm.php index f1512b1..1e1e3b0 100644 --- a/src/Form/GeneralForm.php +++ b/src/Form/GeneralForm.php @@ -5,7 +5,6 @@ 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,13 +13,6 @@ */ class GeneralForm extends ConfigFormBase { - /** - * The current user. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $user; - /** * The request context. * @@ -40,14 +32,11 @@ 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, AccountInterface $user, SiteConfiguration $service) { + public function __construct(ConfigFactoryInterface $config_factory, SiteConfiguration $service) { parent::__construct($config_factory); - $this->user = $user; $this->service = $service; } @@ -62,7 +51,6 @@ public function __construct(ConfigFactoryInterface $config_factory, AccountInter public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('current_user'), $container->get('ucb_site_configuration') ); } diff --git a/src/Form/PagesForm.php b/src/Form/PagesForm.php index 29192ad..ae1ca34 100644 --- a/src/Form/PagesForm.php +++ b/src/Form/PagesForm.php @@ -7,7 +7,6 @@ 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; @@ -17,13 +16,6 @@ */ class PagesForm extends ConfigFormBase { - /** - * The current user. - * - * @var \Drupal\Core\Session\AccountInterface - */ - protected $user; - /** * The path alias manager. * @@ -57,8 +49,6 @@ class PagesForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. - * @param \Drupal\Core\Session\AccountInterface $user - * The current user. * @param \Drupal\path_alias\AliasManagerInterface $alias_manager * The path alias manager. * @param \Drupal\Core\Path\PathValidatorInterface $path_validator @@ -68,9 +58,8 @@ class PagesForm extends ConfigFormBase { * @param \Drupal\ucb_site_configuration\SiteConfiguration $service * The site configuration service defined in this module. */ - public function __construct(ConfigFactoryInterface $config_factory, AccountInterface $user, AliasManagerInterface $alias_manager, PathValidatorInterface $path_validator, RequestContext $request_context, SiteConfiguration $service) { + public function __construct(ConfigFactoryInterface $config_factory, AliasManagerInterface $alias_manager, PathValidatorInterface $path_validator, RequestContext $request_context, SiteConfiguration $service) { parent::__construct($config_factory); - $this->user = $user; $this->aliasManager = $alias_manager; $this->pathValidator = $path_validator; $this->requestContext = $request_context; @@ -88,7 +77,6 @@ public function __construct(ConfigFactoryInterface $config_factory, AccountInter public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), - $container->get('current_user'), $container->get('path_alias.manager'), $container->get('path.validator'), $container->get('router.request_context'), diff --git a/src/SiteConfiguration.php b/src/SiteConfiguration.php index 7b9b45b..0fd67a1 100644 --- a/src/SiteConfiguration.php +++ b/src/SiteConfiguration.php @@ -348,6 +348,28 @@ public function attachSiteInformation(array &$variables) { 'url' => '', ]); $variables['site_affiliation'] = array_merge(['id' => $siteAffiliationId], $siteAffiliationAttribs); + $siteSearchOptions = $configuration->get('site_search_options'); + $siteSearchEnabled = $settings->get('site_search_enabled'); + $variables['site_search'] = []; + foreach ($siteSearchEnabled as $name) { + $siteSearchOption = $siteSearchOptions[$name]; + $siteSearchOption['name'] = $name; + if ('custom' == $name) { + $searchLabel = $settings->get('site_search_label'); + if ($searchLabel) { + $siteSearchOption['label'] = $searchLabel; + } + $searchPlaceholder = $settings->get('site_search_placeholder'); + if ($searchPlaceholder) { + $siteSearchOption['placeholder'] = $searchPlaceholder; + } + $searchUrl = $settings->get('site_search_url'); + if ($searchUrl) { + $siteSearchOption['url'] = $searchUrl; + } + } + $variables['site_search'][] = $siteSearchOption; + } } /** diff --git a/ucb_site_configuration.links.menu.yml b/ucb_site_configuration.links.menu.yml index a7e8454..485fdff 100644 --- a/ucb_site_configuration.links.menu.yml +++ b/ucb_site_configuration.links.menu.yml @@ -7,18 +7,18 @@ ucb_site_configuration: ucb_site_configuration.general_form: title: General - description: 'Modify general settings or information about the site.' + description: 'Modify the site name, type, or affiliation.' route_name: ucb_site_configuration.general_form parent: ucb_site_configuration weight: 0 ucb_site_configuration.appearance_form: - title: Appearance - description: 'Change the appearance, layout, and formatting of the site theme.' + title: Appearance and layout + description: 'Change the appearance, layout, or formatting options of the site.' route_name: ucb_site_configuration.appearance_form parent: ucb_site_configuration weight: 1 ucb_site_configuration.pages_form: - title: Pages & search + title: Pages and search description: 'Change the site home page or search options.' route_name: ucb_site_configuration.pages_form parent: ucb_site_configuration diff --git a/ucb_site_configuration.links.task.yml b/ucb_site_configuration.links.task.yml index b3a6ecd..e643296 100644 --- a/ucb_site_configuration.links.task.yml +++ b/ucb_site_configuration.links.task.yml @@ -5,12 +5,12 @@ ucb_site_configuration.general_form: weight: 0 ucb_site_configuration.appearance_form: route_name: ucb_site_configuration.appearance_form - title: 'Appearance' + 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 & search' + title: 'Pages and search' base_route: ucb_site_configuration weight: 2 ucb_site_configuration.contact_info_form: diff --git a/ucb_site_configuration.routing.yml b/ucb_site_configuration.routing.yml index fb9a54e..3b233cc 100644 --- a/ucb_site_configuration.routing.yml +++ b/ucb_site_configuration.routing.yml @@ -24,7 +24,7 @@ ucb_site_configuration.appearance_form: path: '/admin/config/cu-boulder/appearance' defaults: _form: '\Drupal\ucb_site_configuration\Form\AppearanceForm' - _title: Appearance + _title: Appearance and layout requirements: _permission: edit ucb site appearance options: @@ -34,7 +34,7 @@ ucb_site_configuration.pages_form: path: '/admin/config/cu-boulder/pages' defaults: _form: '\Drupal\ucb_site_configuration\Form\PagesForm' - _title: Pages & search + _title: Pages and search requirements: _permission: edit ucb site pages options: