class TestProcessor
Same name in other branches
- 9 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 \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
- class \Drupal\aggregator\Plugin\AggregatorPluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Plugin\PluginFormInterface, \Drupal\Component\Plugin\ConfigurableInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Component\Plugin\ConfigurablePluginInterface
- class \Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor extends \Drupal\aggregator\Plugin\AggregatorPluginSettingsBase implements \Drupal\aggregator\Plugin\ProcessorInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface uses \Drupal\Core\Form\ConfigFormBaseTrait
- class \Drupal\aggregator\Plugin\AggregatorPluginSettingsBase extends \Drupal\Core\Plugin\PluginBase implements \Drupal\Core\Plugin\PluginFormInterface, \Drupal\Component\Plugin\ConfigurableInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Component\Plugin\ConfigurablePluginInterface
- class \Drupal\Core\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of TestProcessor
2 string references to 'TestProcessor'
- FeedProcessorPluginTest::testProcess in core/
modules/ aggregator/ tests/ src/ Functional/ FeedProcessorPluginTest.php - Test processing functionality.
- TestProcessor::process in core/
modules/ aggregator/ tests/ modules/ aggregator_test/ src/ Plugin/ aggregator/ processor/ TestProcessor.php - Processes feed data.
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
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.