public function TamperListForm::buildForm in Feeds Tamper 8.2
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
\Drupal\feeds\FeedTypeInterface $feeds_feed_type: The feed that we are adding a tamper plugin to.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ TamperListForm.php, line 79
Class
- TamperListForm
- Provides a form to manage tamper plugins for a feed type.
Namespace
Drupal\feeds_tamper\FormCode
public function buildForm(array $form, FormStateInterface $form_state, FeedTypeInterface $feeds_feed_type = NULL) {
$this->feedsFeedType = $feeds_feed_type;
$tamper_meta = $this->feedTypeTamperManager
->getTamperMeta($this->feedsFeedType);
$this->tampers = $tamper_meta
->getTampersGroupedBySource();
$this->sources = $this->feedsFeedType
->getMappingSources();
$this->targets = $this->feedsFeedType
->getMappingTargets();
$mappings = $this->feedsFeedType
->getMappings();
$args = [
'@url' => Url::fromRoute('entity.feeds_feed_type.mapping', [
'feeds_feed_type' => $this->feedsFeedType
->id(),
])
->toString(),
];
if (!$mappings) {
$this
->messenger()
->addWarning($this
->t('There are no <a href="@url">mappings</a> defined for this importer.', $args));
return $form;
}
// Help message at the top. I have a seceret, I added the link back to the
// mappings because it makes my life a lot easier while testing this.
$message = $this
->t('Configure plugins to modify Feeds data before it gets saved. Each <a href="@url">mapping</a> can be manipulated individually.', $args);
$form['help'] = [
'#type' => 'item',
'#markup' => '<div class="help"><p>' . $message . '</p></div>',
];
// Build mapping grouped by source>targets>columns.
foreach ($mappings as $mapping) {
foreach ($mapping['map'] as $column => $source) {
if ($source == '') {
continue;
}
$this->groupedMappings[$source][$mapping['target']][$column] = $mapping;
}
}
$i = 0;
$form['#tree'] = TRUE;
foreach ($this->groupedMappings as $source => $targets) {
$form[$source] = $this
->buildTampersTable($form, $form_state, $source, $targets);
$i++;
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save'),
];
return $form;
}