if ($match !== NULL
) { $value[] =
[ 'target_id' =>
$match,
];
} elseif ($autocreate) { /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface $handler */
// Auto-create item. See an example of how this is handled in
// \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
$value[] =
[ 'entity' =>
$handler->
createNewEntity($element['#target_type'
],
$element['#autocreate'
]['bundle'
],
$input,
$element['#autocreate'
]['uid'
]),
];
} } } // Check that the referenced entities are valid, if needed.
if ($element['#validate_reference'
] && !
empty($value)) { // Validate existing entities.
$ids =
array_reduce($value,
function D
$return,
$item) { if (isset($item['target_id'
])) { $return[] =
$item['target_id'
];
}