Skip to content
Snippets Groups Projects
Commit 81f54de6 authored by Viktor Holovachek's avatar Viktor Holovachek
Browse files

Issue #3424843 - Add alter hook

parent bd55ea7d
No related branches found
No related tags found
1 merge request!8Issue #3424843 - Add alter hook
Pipeline #107801 passed with warnings
<?php
/**
* @file
* Hooks for the browscap module.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Alter the browser properties value.
*
* @param array $properties
* Browser properties.
* @param string $user_agent
* User agent.
*/
function hook_browscap_properties_alter(&$properties, $user_agent) {
$properties['comment'] = t('My comment...');
}
/**
* @} End of "addtogroup hooks".
*/
services:
browscap:
class: Drupal\browscap\BrowscapService
arguments: ['@config.factory', '@cache.browscap', '@datetime.time']
arguments: ['@config.factory', '@cache.browscap', '@datetime.time', '@module_handler']
browscap.importer:
class: Drupal\browscap\BrowscapImporter
arguments: ['@config.factory', '@cache.browscap', '@datetime.time', '@messenger', '@database']
......
......@@ -7,6 +7,7 @@ use Drupal\Component\Utility\Html;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\Extension\ModuleHandlerInterface;
/**
* Class BrowscapService. Provides base class for the module service.
......@@ -36,6 +37,13 @@ class BrowscapService {
*/
protected $time;
/**
* Returns the module_handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Constructs a BrowscapService object.
*
......@@ -45,11 +53,14 @@ class BrowscapService {
* Defines an interface for cache implementations.
* @param \Drupal\Component\Datetime\TimeInterface $time
* Defines an interface for obtaining system time.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* Interface for classes that manage a set of enabled modules.
*/
public function __construct(ConfigFactoryInterface $config, CacheBackendInterface $cache, TimeInterface $time) {
public function __construct(ConfigFactoryInterface $config, CacheBackendInterface $cache, TimeInterface $time, ModuleHandlerInterface $module_handler) {
$this->config = $config;
$this->cache = $cache;
$this->time = $time;
$this->moduleHandler = $module_handler;
}
/**
......@@ -115,6 +126,9 @@ class BrowscapService {
$properties['browser_name_pattern'] = strtr('unrecognized', '%_', '*?');
}
// Alter the response.
$this->moduleHandler->alter('browscap_properties', $properties, $user_agent);
return $properties;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment