Skip to content
Snippets Groups Projects

Allow passing plugin instances to field

Merged Nick Vanpraet requested to merge issue/pluginreference-3464721:3464721-can-not-pass into 3.0.x
1 file
+ 8
0
Compare changes
  • Side-by-side
  • Inline
@@ -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)) {
Loading