diff --git a/changelogs/DP-35159.yml b/changelogs/DP-35159.yml new file mode 100644 index 0000000000..736c88ddc8 --- /dev/null +++ b/changelogs/DP-35159.yml @@ -0,0 +1,41 @@ +# +# Write your changelog entry here. Every pull request must have a changelog yml file. +# +# Change types: +# ############################################################################# +# You can use one of the following types: +# - Added: For new features. +# - Changed: For changes to existing functionality. +# - Deprecated: For soon-to-be removed features. +# - Removed: For removed features. +# - Fixed: For any bug fixes. +# - Security: In case of vulnerabilities. +# +# Format +# ############################################################################# +# The format is crucial. Please follow the examples below. For reference, the requirements are: +# - All 3 parts are required and you must include "Type", "description" and "issue". +# - "Type" must be left aligned and followed by a colon. +# - "description" must be indented with 2 spaces followed by a colon +# - "issue" must be indented with 4 spaces followed by a colon. +# - "issue" is for the Jira ticket number only e.g. DP-1234 +# - No extra spaces, indents, or blank lines are allowed. +# +# Example: +# ############################################################################# +# Fixed: +# - description: Fixes scrolling on edit pages in Safari. +# issue: DP-13314 +# +# You may add more than 1 description & issue for each type using the following format: +# Changed: +# - description: Automating the release branch. +# issue: DP-10166 +# - description: Second change item that needs a description. +# issue: DP-19875 +# - description: Third change item that needs a description along with an issue. +# issue: DP-19843 +# +Changed: + - description: Empty Location Page Appearing in Search. + issue: DP-35150 diff --git a/docroot/modules/custom/mass_views/mass_views.module b/docroot/modules/custom/mass_views/mass_views.module index 764dec13d8..fbc7f75419 100644 --- a/docroot/modules/custom/mass_views/mass_views.module +++ b/docroot/modules/custom/mass_views/mass_views.module @@ -11,6 +11,7 @@ use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views\ViewExecutable; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Implements hook_form_FORM_ID_alter(). @@ -291,3 +292,27 @@ function mass_views_views_pre_render(ViewExecutable $view) { } } } + +/** + * Implements hook_views_post_execute(). + * + * This function checks if the 'locations' view has no results on the front-end. + * If no results are found, it triggers a 404 "Page not found" error + * by throwing a NotFoundHttpException. + * + * @param \Drupal\views\ViewExecutable $view + * The view executable object. + * + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * Throws an exception to trigger a 404 response. + */ +function mass_views_views_post_execute(ViewExecutable $view) { + if ($view->id() == 'locations' && empty($view->result)) { + // Check if the current page is an admin page. + if (\Drupal::service('router.admin_context')->isAdminRoute()) { + // If we are on an admin page, do not trigger a 404. + return; + } + throw new NotFoundHttpException(); + } +}