public static function MediaTarget::getSubFields in Media Feeds 8
Parameters
FieldDefinitionInterface $mediaField:
Return value
array
1 call to MediaTarget::getSubFields()
- MediaTarget::prepareTarget in src/
Feeds/ Target/ MediaTarget.php - @inheritdoc
File
- src/
Feeds/ Target/ MediaTarget.php, line 172
Class
- MediaTarget
- Defines a wrapper target around a paragraph bundle's target field.
Namespace
Drupal\media_feeds\Feeds\TargetCode
public static function getSubFields(FieldDefinitionInterface $mediaField) {
$settings = $mediaField
->getSetting('handler_settings');
$bundles = $settings['target_bundles'];
$fields = array();
if (!is_array($bundles)) {
return $fields;
}
$fieldManager = \Drupal::service('entity_field.manager');
$addInfo = function ($field, $host, $bundle, $plugin) {
$info = array(
'plugin' => $plugin,
'type' => $field
->getType(),
'host' => array(
'field' => $host,
'bundle' => $bundle,
),
);
if ($field instanceof BaseFieldDefinition) {
$field->media_feeds_info = $info;
}
else {
$field
->set('media_feeds_info', $info);
}
};
foreach ($bundles as $def_bundle) {
$sub_fields = $fieldManager
->getFieldDefinitions('media', $def_bundle);
foreach ($sub_fields as $fieldId => $sub_field) {
$plugin = self::getPlugin($sub_field);
if ($sub_field instanceof FieldConfigInterface) {
if (isset($plugin)) {
$type = $sub_field
->getType();
$correctPlugin = $plugin;
if (isset($sub_field->media_feeds_info) && $type === 'entity_reference') {
$old_info = $sub_field->media_feeds_info;
$correctPlugin = $old_info['plugin'];
$sub_field = clone $sub_field;
}
$addInfo($sub_field, $mediaField
->getName(), $def_bundle, $correctPlugin);
$id = $def_bundle . ':' . $sub_field
->getName();
$fields[$id] = $sub_field;
}
}
}
}
return $fields;
}