ParserWithMappingForm.php in Feeds 8.3
File
tests/modules/feeds_test_plugin/src/Feeds/Parser/ParserWithMappingForm.php
View source
<?php
namespace Drupal\feeds_test_plugin\Feeds\Parser;
use Drupal\Core\Form\FormStateInterface;
use Drupal\feeds\FeedInterface;
use Drupal\feeds\Plugin\Type\MappingPluginFormInterface;
use Drupal\feeds\Plugin\Type\Parser\ParserInterface;
use Drupal\feeds\Plugin\Type\PluginBase;
use Drupal\feeds\Result\FetcherResultInterface;
use Drupal\feeds\Result\ParserResult;
use Drupal\feeds\StateInterface;
class ParserWithMappingForm extends PluginBase implements ParserInterface, MappingPluginFormInterface {
public function parse(FeedInterface $feed, FetcherResultInterface $fetcher_result, StateInterface $state) {
return new ParserResult();
}
public function defaultConfiguration() {
return [
'dummy' => '',
];
}
public function getMappingSources() {
return [];
}
public function mappingFormAlter(array &$form, FormStateInterface $form_state) {
$form['dummy'] = [
'#type' => 'textfield',
'#title' => $this
->t('Dummy'),
'#default_value' => $this->configuration['dummy'],
'#required' => TRUE,
'#weight' => -50,
];
}
public function mappingFormValidate(array &$form, FormStateInterface $form_state) {
if ($form_state
->getValue('dummy') == 'invalid') {
$form_state
->setErrorByName('dummy', 'Invalid value.');
}
}
public function mappingFormSubmit(array &$form, FormStateInterface $form_state) {
$this
->setConfiguration([
'dummy' => $form_state
->getValue('dummy'),
]);
}
}