public function EntityProcessorBase::mappingFormValidate in Feeds 8.3
Validate handler for the mapping form.
Parameters
array $form: The mapping form definition.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the mapping form.
Overrides MappingPluginFormInterface::mappingFormValidate
File
- src/
Feeds/ Processor/ EntityProcessorBase.php, line 941
Class
- EntityProcessorBase
- Defines a base entity processor.
Namespace
Drupal\feeds\Feeds\ProcessorCode
public function mappingFormValidate(array &$form, FormStateInterface $form_state) {
// Display a warning when mapping to entity ID and having that one not set
// as unique.
$id_key = $this->entityType
->getKey('id');
foreach ($this->feedType
->getMappings() as $delta => $mapping) {
try {
$target_definition = $this->feedType
->getTargetPlugin($delta)
->getTargetDefinition();
if (!$target_definition instanceof FieldTargetDefinition) {
continue;
}
/** @var \Drupal\Core\Field\FieldDefinitionInterface $field_definition */
$field_definition = $target_definition
->getFieldDefinition();
if ($field_definition
->getName() != $id_key) {
continue;
}
$is_unique = $form_state
->getValue([
'mappings',
$delta,
'unique',
$field_definition
->getMainPropertyName(),
]);
if (!$is_unique) {
// Entity ID not set as unique. Display warning.
$this
->messenger()
->addWarning($this
->t('When mapping to the entity ID (@name), it is recommended to set it as unique.', [
'@name' => $target_definition
->getLabel(),
]));
}
} catch (MissingTargetException $e) {
// Ignore missing targets.
}
}
}