Skip to content

Commit

Permalink
DP-35150: Empty Location Page Appearing in Search (#2716)
Browse files Browse the repository at this point in the history
* DP-35150: Empty Location Page Appearing in Search

* DP-35150: Empty Location Page Appearing in Search
  • Loading branch information
arthurbaghdas authored Oct 17, 2024
1 parent f8e3b3f commit d52cdc1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
41 changes: 41 additions & 0 deletions changelogs/DP-35159.yml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions docroot/modules/custom/mass_views/mass_views.module
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down Expand Up @@ -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();
}
}

0 comments on commit d52cdc1

Please sign in to comment.