SmartDate.php in Smart Date 3.2.x
File
src/Feeds/Target/SmartDate.php
View source
<?php
namespace Drupal\smart_date\Feeds\Target;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\feeds\FieldTargetDefinition;
use Drupal\feeds\Exception\EmptyFeedException;
use Drupal\feeds\Exception\TargetValidationException;
use Drupal\feeds\Plugin\Type\Target\FieldTargetBase;
class SmartDate extends FieldTargetBase {
protected static function prepareTarget(FieldDefinitionInterface $field_definition) {
return FieldTargetDefinition::createFromFieldDefinition($field_definition)
->addProperty('value')
->addProperty('end_value');
}
protected function prepareValue($delta, array &$values) {
if (isset($values)) {
if (isset($values['value']) && !isset($values['end_value'])) {
$values['end_value'] = $values['value'];
}
return $values;
}
else {
throw new EmptyFeedException();
}
}
protected function prepareValues(array $values) {
$return = [];
foreach ($values as $delta => $columns) {
try {
$this
->prepareValue($delta, $columns);
$return[] = $columns;
} catch (EmptyFeedException $e) {
} catch (TargetValidationException $e) {
\Drupal::messenger()
->addError($e
->getMessage());
}
}
return $return;
}
}