From 3a3edf88841f6c26b9b8f8362ff5319aea12fb7a Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 21 Aug 2013 09:50:32 +0200 Subject: [PATCH 1/3] Allow to set the page title for search pages. --- .../lib/Drupal/CultureFeedSearchPage.php | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php index 53582940..3b4dd7fb 100644 --- a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php +++ b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php @@ -65,11 +65,17 @@ class CultureFeedSearchPage { protected $result; /** - * Default page title. - * @var unknown + * Default page title. This is a fallback in case no other title is provided. + * @var string */ protected $defaultTitle = ''; + /** + * The page title to use. If empty this will be overridden by $defaultTitle. + * @var string + */ + protected $title = ''; + /** * Stores search facets with corresponding values for the active search. * @var \CultuurNet\Search\Component\Facet\FacetComponent @@ -114,13 +120,35 @@ public function setDefaultSort($sortKey) { } /** - * Set the default title. + * Set the default title. Used as a fallback when there is no page title. * @param string $title */ public function setDefaultTitle($title) { $this->defaultTitle = $title; } + /** + * Set the page title. + * + * @param string $title + * The text to set as page title. If this is not set the defaultTitle will + * be used instead. + */ + public function setTitle($title) { + $this->title = $title; + } + + /** + * Get the page title. + * + * @return string + * The currently set page title. If no page title has been set an empty + * string will be returned. + */ + public function getTitle() { + return $this->title; + } + /** * Sets the resultsPerPage property. */ @@ -380,6 +408,11 @@ protected function build() { * Get the title to show. */ public function getDrupalTitle() { + // Return the title that has been explicitly set with $this->setTitle(). + if (!empty($this->title)) { + return check_plain($this->title); + } + $active_filters = module_invoke_all('culturefeed_search_ui_active_filters', $this->facetComponent); if (!empty($active_filters)) { From 1c557bce514978624600092f1c782daf3a196957 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 21 Aug 2013 09:52:38 +0200 Subject: [PATCH 2/3] Updated documentation. --- .../lib/Drupal/CultureFeedSearchPage.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php index 3b4dd7fb..250474d3 100644 --- a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php +++ b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php @@ -405,7 +405,22 @@ protected function build() { } /** - * Get the title to show. + * Returns the title to show on the page. + * + * @see culturefeed_search_ui_search_page() + * + * @return string + * Returns the page title according to the following logic: + * 1. If a title has been set with $this->setTitle(), this will be returned. + * 2. If no title was set, and one or more search facets are active, a + * comma-separated list of active search facets are returned. + * 3. If no title was set, and no search facets are active, the default + * title is returned. This is usually defined in the 'page_title' key in + * hook_culturefeed_search_page_info(). + * If the query parameter 'page' is present and no title has been set with + * $this->setTitle(), the returned title will be appended with a comma + * and the Dutch word 'pagina' with the page parameter increased by one, + * surrounded by parentheses. */ public function getDrupalTitle() { // Return the title that has been explicitly set with $this->setTitle(). From 36474b4d87659012db6739ddac4c682deac7d342 Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Wed, 21 Aug 2013 09:57:06 +0200 Subject: [PATCH 3/3] Fixed double escaping of page title. --- culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php index 250474d3..818e638d 100644 --- a/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php +++ b/culturefeed_search_ui/lib/Drupal/CultureFeedSearchPage.php @@ -425,7 +425,7 @@ protected function build() { public function getDrupalTitle() { // Return the title that has been explicitly set with $this->setTitle(). if (!empty($this->title)) { - return check_plain($this->title); + return $this->title; } $active_filters = module_invoke_all('culturefeed_search_ui_active_filters', $this->facetComponent);