Skip to content

Commit

Permalink
Merge pull request #142 from aleevas/DS-1403
Browse files Browse the repository at this point in the history
fix: [DS-1403] Add a fix for better processing alerts on the home page
  • Loading branch information
podarok authored May 30, 2024
2 parents 6150b4e + 993e8b8 commit a88489d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion openy_node_alert.services.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
openy_node_alert.alert_manager:
class: 'Drupal\openy_node_alert\Service\AlertManager'
arguments: ['@entity_type.manager', '@current_user', '@path_alias.manager', '@path.matcher']
arguments: ['@entity_type.manager', '@current_user', '@path_alias.manager', '@path.matcher', '@config.factory']
tags:
- { name: service_collector, tag: alert_builder, call: addBuilder }
13 changes: 12 additions & 1 deletion src/Service/AlertManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\openy_node_alert\Service;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
Expand Down Expand Up @@ -68,6 +69,13 @@ class AlertManager {
*/
protected $connection;

/**
* The alias of the homepage.
*
* @var string
*/
protected $homePageAlias;

/**
* Constructs the Alert manager.
*
Expand All @@ -78,12 +86,15 @@ public function __construct(
AccountProxyInterface $current_user,
AliasManagerInterface $alias_manager,
PathMatcherInterface $path_matcher,
ConfigFactoryInterface $config_factory
) {
$this->nodeStorage = $entity_type_manager->getStorage('node');
$this->currentUser = $current_user;
$this->aliasManager = $alias_manager;
$this->pathMatcher = $path_matcher;
$this->connection = Database::getConnection();
$page_front = $config_factory->get('system.site')->get('page.front');
$this->homePageAlias = $alias_manager->getAliasByPath($page_front);
}

/**
Expand Down Expand Up @@ -303,7 +314,7 @@ private function checkVisibility(NodeInterface $alert, NodeInterface $node) {
$current_path = $current_path ? mb_strtolower($current_path) : $current_path;
// Check all values from the field "alert_visibility_pages".
foreach ($pages as $page) {
$page_path = ($page === '<front>' || $page === '/') ? '<front>' : '/' . ltrim($page, '/');
$page_path = ($page === '<front>' || $page === '/') ? $this->homePageAlias : '/' . ltrim($page, '/');
$is_path_match = $this->pathMatcher->matchPath($current_path, $page_path);
if ($is_path_match) {
// If this path matches at least one of the visibility pages,
Expand Down

0 comments on commit a88489d

Please sign in to comment.