SelectionWithAutocreateInterface.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Drupal\Core\Entity\EntityReferenceSelection;
  3. /**
  4. * Interface for Selection plugins that support newly created entities.
  5. *
  6. * @see \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager
  7. * @see \Drupal\Core\Entity\Annotation\EntityReferenceSelection
  8. * @see plugin_api
  9. */
  10. interface SelectionWithAutocreateInterface {
  11. /**
  12. * Creates a new entity object that can be used as a valid reference.
  13. *
  14. * @param string $entity_type_id
  15. * The entity type ID.
  16. * @param string $bundle
  17. * The bundle name.
  18. * @param string $label
  19. * The entity label.
  20. * @param int $uid
  21. * The entity owner ID, if the entity type supports it.
  22. *
  23. * @return \Drupal\Core\Entity\EntityInterface
  24. * An unsaved entity object.
  25. */
  26. public function createNewEntity($entity_type_id, $bundle, $label, $uid);
  27. /**
  28. * Validates which newly created entities can be referenced.
  29. *
  30. * This method should replicate the logic implemented by
  31. * \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::validateReferenceableEntities(),
  32. * but applied to newly created entities that have not been saved yet.
  33. *
  34. * @param \Drupal\Core\Entity\EntityInterface[] $entities
  35. * An array of entities to check.
  36. *
  37. * @return \Drupal\Core\Entity\EntityInterface[]
  38. * The incoming $entities parameter, filtered for valid entities. Array keys
  39. * are preserved.
  40. */
  41. public function validateReferenceableNewEntities(array $entities);
  42. }