class 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

Expanded class hierarchy of TestProcessor

File

drupal/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Plugin/aggregator/processor/TestProcessor.php, line 27
Contains \Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor.

Namespace

Drupal\aggregator_test\Plugin\aggregator\processor
View source
class TestProcessor extends PluginBase implements ProcessorInterface {

  /**
   * Implements \Drupal\aggregator\Plugin\ProcessorInterface::settingsForm().
   */
  public function settingsForm(array $form, array &$form_state) {
    $config = config('aggregator.settings');
    $processors = $config
      ->get('processors');
    $info = $this
      ->getPluginDefinition();
    $form['processors'][$info['id']] = array(
      '#type' => 'details',
      '#title' => t('Test processor settings'),
      '#description' => $info['description'],
      '#collapsed' => !in_array($info['id'], $processors),
    );

    // Add some dummy settings to verify settingsForm is called.
    $form['processors'][$info['id']]['dummy_length'] = array(
      '#title' => t('Dummy length setting'),
      '#type' => 'number',
      '#min' => 1,
      '#max' => 1000,
      '#default_value' => config('aggregator_test.settings')
        ->get('items.dummy_length'),
    );
    return $form;
  }

  /**
   * Implements \Drupal\aggregator\Plugin\ProcessorInterface::settingsSubmit().
   */
  public function settingsSubmit(array $form, array &$form_state) {
    config('aggregator_test.settings')
      ->set('items.dummy_length', $form_state['values']['dummy_length'])
      ->save();
  }

  /**
   * Implements \Drupal\aggregator\Plugin\ProcessorInterface::process().
   */
  public function process(Feed $feed) {
    foreach ($feed->items as &$item) {

      // Prepend our test string.
      $item['title'] = 'testProcessor' . $item['title'];
    }
  }

  /**
   * Implements \Drupal\aggregator\Plugin\ProcessorInterface::remove().
   */
  public function remove(Feed $feed) {

    // Append a random number, just to change the feed description.
    $feed->description->value .= rand(0, 10);
  }

  /**
   * Implements \Drupal\aggregator\Plugin\ProcessorInterface::postProcess().
   */
  public function postProcess(Feed $feed) {

    // Double the refresh rate.
    $feed->refresh->value *= 2;
    $feed
      ->save();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. 17
TestProcessor::postProcess public function Implements \Drupal\aggregator\Plugin\ProcessorInterface::postProcess(). Overrides ProcessorInterface::postProcess
TestProcessor::process public function Implements \Drupal\aggregator\Plugin\ProcessorInterface::process(). Overrides ProcessorInterface::process
TestProcessor::remove public function Implements \Drupal\aggregator\Plugin\ProcessorInterface::remove(). Overrides ProcessorInterface::remove
TestProcessor::settingsForm public function Implements \Drupal\aggregator\Plugin\ProcessorInterface::settingsForm(). Overrides ProcessorInterface::settingsForm
TestProcessor::settingsSubmit public function Implements \Drupal\aggregator\Plugin\ProcessorInterface::settingsSubmit(). Overrides ProcessorInterface::settingsSubmit