EntityRepositoryInterface.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. /**
  4. * Provides an interface for an entity repository.
  5. */
  6. interface EntityRepositoryInterface {
  7. /**
  8. * Loads an entity by UUID.
  9. *
  10. * Note that some entity types may not support UUIDs.
  11. *
  12. * @param string $entity_type_id
  13. * The entity type ID to load from.
  14. * @param string $uuid
  15. * The UUID of the entity to load.
  16. *
  17. * @return \Drupal\Core\Entity\EntityInterface|null
  18. * The entity object, or NULL if there is no entity with the given UUID.
  19. *
  20. * @throws \Drupal\Core\Entity\EntityStorageException
  21. * Thrown in case the requested entity type does not support UUIDs.
  22. */
  23. public function loadEntityByUuid($entity_type_id, $uuid);
  24. /**
  25. * Loads an entity by the config target identifier.
  26. *
  27. * @param string $entity_type_id
  28. * The entity type ID to load from.
  29. * @param string $target
  30. * The configuration target to load, as returned from
  31. * \Drupal\Core\Entity\EntityInterface::getConfigTarget().
  32. *
  33. * @return \Drupal\Core\Entity\EntityInterface|null
  34. * The entity object, or NULL if there is no entity with the given config
  35. * target identifier.
  36. *
  37. * @throws \Drupal\Core\Entity\EntityStorageException
  38. * Thrown if the target identifier is a UUID but the entity type does not
  39. * support UUIDs.
  40. *
  41. * @see \Drupal\Core\Entity\EntityInterface::getConfigTarget()
  42. */
  43. public function loadEntityByConfigTarget($entity_type_id, $target);
  44. /**
  45. * Gets the entity translation to be used in the given context.
  46. *
  47. * This will check whether a translation for the desired language is available
  48. * and if not, it will fall back to the most appropriate translation based on
  49. * the provided context.
  50. *
  51. * @param \Drupal\Core\Entity\EntityInterface $entity
  52. * The entity whose translation will be returned.
  53. * @param string $langcode
  54. * (optional) The language of the current context. Defaults to the current
  55. * content language.
  56. * @param array $context
  57. * (optional) An associative array of arbitrary data that can be useful to
  58. * determine the proper fallback sequence.
  59. *
  60. * @return \Drupal\Core\Entity\EntityInterface
  61. * An entity object for the translated data.
  62. *
  63. * @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
  64. */
  65. public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []);
  66. }