class TestProcessor in Drupal 9
Same name and namespace in other branches
- 8 core/modules/aggregator/tests/modules/aggregator_test/src/Plugin/aggregator/processor/TestProcessor.php \Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor
Defines a default processor implementation.
Creates lightweight records from feed items.
Plugin annotation
@AggregatorProcessor(
id = "aggregator_test_processor",
title = @Translation("Test processor"),
description = @Translation("Test generic processor functionality.")
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\aggregator\Plugin\AggregatorPluginSettingsBase implements ConfigurableInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor implements ProcessorInterface, ContainerFactoryPluginInterface uses ConfigFormBaseTrait
- class \Drupal\aggregator\Plugin\AggregatorPluginSettingsBase implements ConfigurableInterface, DependentPluginInterface, PluginFormInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TestProcessor
File
- core/
modules/ aggregator/ tests/ modules/ aggregator_test/ src/ Plugin/ aggregator/ processor/ TestProcessor.php, line 25
Namespace
Drupal\aggregator_test\Plugin\aggregator\processorView source
class TestProcessor extends AggregatorPluginSettingsBase implements ProcessorInterface, ContainerFactoryPluginInterface {
use ConfigFormBaseTrait;
/**
* Contains the configuration object factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('config.factory'));
}
/**
* Constructs a TestProcessor object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The configuration factory object.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config) {
$this->configFactory = $config;
parent::__construct($configuration + $this
->getConfiguration(), $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'aggregator_test.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$processors = $this
->config('aggregator.settings')
->get('processors');
$info = $this
->getPluginDefinition();
$form['processors'][$info['id']] = [
'#type' => 'details',
'#title' => t('Test processor settings'),
'#description' => $info['description'],
'#open' => in_array($info['id'], $processors),
];
// Add some dummy settings to verify settingsForm is called.
$form['processors'][$info['id']]['dummy_length'] = [
'#title' => t('Dummy length setting'),
'#type' => 'number',
'#min' => 1,
'#max' => 1000,
'#default_value' => $this->configuration['items']['dummy_length'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['items']['dummy_length'] = $form_state
->getValue('dummy_length');
$this
->setConfiguration($this->configuration);
}
/**
* {@inheritdoc}
*/
public function process(FeedInterface $feed) {
foreach ($feed->items as &$item) {
// Prepend our test string.
$item['title'] = 'testProcessor' . $item['title'];
}
}
/**
* {@inheritdoc}
*/
public function delete(FeedInterface $feed) {
// Append a random number, just to change the feed description.
$feed->description->value .= rand(0, 10);
}
/**
* {@inheritdoc}
*/
public function postProcess(FeedInterface $feed) {
// Double the refresh rate.
$feed->refresh->value *= 2;
$feed
->save();
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configFactory
->get('aggregator_test.settings')
->get();
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$config = $this
->config('aggregator_test.settings');
foreach ($configuration as $key => $value) {
$config
->set($key, $value);
}
$config
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AggregatorPluginSettingsBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
AggregatorPluginSettingsBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
AggregatorPluginSettingsBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TestProcessor:: |
protected | property | Contains the configuration object factory. | |
TestProcessor:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
TestProcessor:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
TestProcessor:: |
public | function |
Deletes stored feed data. Overrides ProcessorInterface:: |
|
TestProcessor:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
TestProcessor:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
TestProcessor:: |
public | function |
Refreshes feed information. Overrides ProcessorInterface:: |
|
TestProcessor:: |
public | function |
Processes feed data. Overrides ProcessorInterface:: |
|
TestProcessor:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
TestProcessor:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
TestProcessor:: |
public | function |
Constructs a TestProcessor object. Overrides PluginBase:: |