BasicFieldSource.php in Feeds 8.3
File
src/Feeds/Source/BasicFieldSource.php
View source
<?php
namespace Drupal\feeds\Feeds\Source;
use Drupal\feeds\FeedInterface;
use Drupal\feeds\Feeds\Item\ItemInterface;
use Drupal\feeds\FeedTypeInterface;
use Drupal\feeds\Plugin\Type\Source\SourceBase;
class BasicFieldSource extends SourceBase {
public static function sources(array &$sources, FeedTypeInterface $feed_type, array $definition) {
$field_definitions = \Drupal::service('entity_field.manager')
->getFieldDefinitions('feeds_feed', $feed_type
->id());
foreach ($field_definitions as $field => $field_definition) {
if (!$field_definition
->getFieldStorageDefinition()
->getMainPropertyName()) {
continue;
}
$sources['parent:' . $field] = [
'label' => t('Feed: @label', [
'@label' => $field_definition
->getLabel(),
]),
'description' => $field_definition
->getDescription(),
'id' => $definition['id'],
];
}
}
public function getSourceElement(FeedInterface $feed, ItemInterface $item) {
list(, $field_name) = explode(':', $this->configuration['source']);
$return = [];
if ($field_list = $feed
->get($field_name)) {
foreach ($field_list as $field) {
$main_property_name = $field
->getFieldDefinition()
->getFieldStorageDefinition()
->getMainPropertyName();
if ($main_property_name) {
$return[] = $field->{$main_property_name};
}
}
}
return $return;
}
}
Classes
Name |
Description |
BasicFieldSource |
A source plugin that provides feed type fields as mapping sources. |