Unverified Commit 384f184f authored by alexpott's avatar alexpott

Issue #2991055 by Erik Frèrejean, Xano: Add hook_aggregator_*_info_alter() to...

Issue #2991055 by Erik Frèrejean, Xano: Add hook_aggregator_*_info_alter() to alter Aggregator plugin definitions
parent 2be3c894
<?php
/**
* @file
* Aggregator API documentation.
*/
/**
* @addtogroup hooks
* @{
*/
/**
* Perform alterations on the available fetchers.
*
* @param array[] $info
* Array of fetcher plugins
*/
function hook_aggregator_fetcher_info_alter(array &$info) {
if (empty($info['foo_fetcher'])) {
return;
}
$info['foo_fetcher']['class'] = Drupal\foo\Plugin\aggregator\fetcher\FooDefaultFetcher::class;
}
/**
* Perform alterations on the available parsers.
*
* @param array[] $info
* Array of parser plugins
*/
function hook_aggregator_parser_info_alter(array &$info) {
if (empty($info['foo_parser'])) {
return;
}
$info['foo_parser']['class'] = Drupal\foo\Plugin\aggregator\parser\FooDefaultParser::class;
}
/**
* Perform alterations on the available processors.
*
* @param array[] $info
* Array of processor plugins
*/
function hook_aggregator_processor_info_alter(array &$info) {
if (empty($info['foo_processor'])) {
return;
}
$info['foo_processor']['class'] = Drupal\foo\Plugin\aggregator\processor\FooDefaultProcessor::class;
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -46,6 +46,7 @@ public function __construct($type, \Traversable $namespaces, CacheBackendInterfa
];
parent::__construct("Plugin/aggregator/$type", $namespaces, $module_handler, $plugin_interfaces[$type], $type_annotations[$type]);
$this->alterInfo('aggregator_' . $type . '_info');
$this->setCacheBackend($cache_backend, 'aggregator_' . $type . '_plugins');
}
......
<?php
/**
* @file
* Helper module for the Aggregator tests.
*/
/**
* Implements hook_aggregator_fetcher_info_alter().
*/
function aggregator_test_aggregator_fetcher_info_alter(array &$info) {
$info['aggregator_test_fetcher']['definition_altered'] = TRUE;
}
/**
* Implements hook_aggregator_parser_info_alter().
*/
function aggregator_test_aggregator_parser_info_alter(array &$info) {
$info['aggregator_test_parser']['definition_altered'] = TRUE;
}
/**
* Implements hook_aggregator_processor_info_alter().
*/
function aggregator_test_aggregator_processor_info_alter(array &$info) {
$info['aggregator_test_processor']['definition_altered'] = TRUE;
}
<?php
namespace Drupal\Tests\aggregator\Kernel;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the aggregator plugin manager.
*
* @group aggregator
*/
class AggregatorPluginManagerTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['aggregator', 'aggregator_test'];
/**
* Tests that the fetcher info alter hook works.
*/
public function testFetcherInfoAlter() {
$widget_definition = \Drupal::service('plugin.manager.aggregator.fetcher')->getDefinition('aggregator_test_fetcher');
// Test if hook_aggregator_fetcher_info_alter is being called.
$this->assertTrue($widget_definition['definition_altered'], "The 'aggregator_test_fetcher' plugin definition was updated in `hook_aggregator_fetcher_info_alter()`");
}
/**
* Tests that the fetcher info alter hook works.
*/
public function testParserInfoAlter() {
$widget_definition = \Drupal::service('plugin.manager.aggregator.parser')->getDefinition('aggregator_test_parser');
// Test if hook_aggregator_parser_info_alter is being called.
$this->assertTrue($widget_definition['definition_altered'], "The 'aggregator_test_parser' plugin definition was updated in in `hook_aggregator_parser_info_alter()`");
}
/**
* Tests that the fetcher info alter hook works.
*/
public function testProcessorInfoAlter() {
$widget_definition = \Drupal::service('plugin.manager.aggregator.processor')->getDefinition('aggregator_test_processor');
// Test if hook_aggregator_processor_info_alter is being called.
$this->assertTrue($widget_definition['definition_altered'], "The 'aggregator_test_processor' plugin definition was updated in in `hook_aggregator_processor_info_alter()`");
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment