diff --git a/src/Plugin/Field/FieldType/PluginReferenceItem.php b/src/Plugin/Field/FieldType/PluginReferenceItem.php index 87aa0e9d7e5792719dabe072f1405aff7b65d6be..09d9b04e22f0d75df318d334b8efb27ac4a0c2b8 100644 --- a/src/Plugin/Field/FieldType/PluginReferenceItem.php +++ b/src/Plugin/Field/FieldType/PluginReferenceItem.php @@ -2,7 +2,9 @@ namespace Drupal\pluginreference\Plugin\Field\FieldType; +use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\PluginBase; +use Drupal\Component\Plugin\PluginInspectionInterface; use Drupal\Component\Plugin\PluginManagerInterface; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; @@ -429,6 +431,12 @@ class PluginReferenceItem extends FieldItemBase implements OptionsProviderInterf * {@inheritdoc} */ public function setValue($values, $notify = TRUE): void { + if ($values instanceof PluginInspectionInterface) { + $values = [ + static::mainPropertyName() => $values->getPluginId(), + 'configuration' => $values instanceof ConfigurableInterface ? $values->getConfiguration() : [], + ]; + } // Treat the values as property value of the main property, if no array is // given. if (!is_array($values)) {