You are here

class SmartDate in Smart Date 3.1.x

Same name and namespace in other branches
  1. 8.2 src/Feeds/Target/SmartDate.php \Drupal\smart_date\Feeds\Target\SmartDate
  2. 3.x src/Feeds/Target/SmartDate.php \Drupal\smart_date\Feeds\Target\SmartDate
  3. 3.0.x src/Feeds/Target/SmartDate.php \Drupal\smart_date\Feeds\Target\SmartDate
  4. 3.2.x src/Feeds/Target/SmartDate.php \Drupal\smart_date\Feeds\Target\SmartDate
  5. 3.3.x src/Feeds/Target/SmartDate.php \Drupal\smart_date\Feeds\Target\SmartDate
  6. 3.4.x src/Feeds/Target/SmartDate.php \Drupal\smart_date\Feeds\Target\SmartDate

Defines a smartdate field mapper.

Plugin annotation


@FeedsTarget(
  id = "smart_date_feeds_target",
  field_types = {"smartdate"}
)

Hierarchy

  • class \Drupal\smart_date\Feeds\Target\SmartDate extends \Drupal\feeds\Plugin\Type\Target\FieldTargetBase

Expanded class hierarchy of SmartDate

File

src/Feeds/Target/SmartDate.php, line 19

Namespace

Drupal\smart_date\Feeds\Target
View source
class SmartDate extends FieldTargetBase {

  /**
   * {@inheritdoc}
   */
  protected static function prepareTarget(FieldDefinitionInterface $field_definition) {
    return FieldTargetDefinition::createFromFieldDefinition($field_definition)
      ->addProperty('value')
      ->addProperty('end_value');
  }

  /**
   * {@inheritdoc}
   */
  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();
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function prepareValues(array $values) {
    $return = [];
    foreach ($values as $delta => $columns) {
      try {
        $this
          ->prepareValue($delta, $columns);
        $return[] = $columns;
      } catch (EmptyFeedException $e) {

        // Nothing wrong here.
      } catch (TargetValidationException $e) {

        // Validation failed.
        \Drupal::messenger()
          ->addError($e
          ->getMessage());
      }
    }
    return $return;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SmartDate::prepareTarget protected static function
SmartDate::prepareValue protected function
SmartDate::prepareValues protected function