Add feed import support

Created on 19 February 2021, almost 4 years ago
Updated 4 April 2023, over 1 year ago

How do I add feeds importer support for the image caption.

Here is how feeds add support for Alt and Title text.

<?php

namespace Drupal\feeds\Feeds\Target;

use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\feeds\FieldTargetDefinition;

/**
 * Defines a file field mapper.
 *
 * @FeedsTarget(
 *   id = "image",
 *   field_types = {"image"}
 * )
 */
class Image extends File {

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

  /**
   * {@inheritdoc}
   */
  protected function prepareValue($delta, array &$values) {
    foreach ($values as $column => $value) {
      switch ($column) {
        case 'target_id':
          $values[$column] = $this->getFile($value);
          break;

        default:
          $values[$column] = (string) $value;
          break;
      }
    }
  }

}

what is the ->addProperty();

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΏπŸ‡¦South Africa vlooi vlerke

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024