ComplexDataInterface.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Drupal\Core\TypedData;
  3. /**
  4. * Interface for complex data; i.e. data containing named and typed properties.
  5. *
  6. * The name of a property has to be a valid PHP variable name, starting with
  7. * an alphabetic character.
  8. *
  9. * This is implemented by entities as well as by field item classes of
  10. * entities.
  11. *
  12. * When implementing this interface which extends Traversable, make sure to list
  13. * IteratorAggregate or Iterator before this interface in the implements clause.
  14. *
  15. * @see \Drupal\Core\TypedData\ComplexDataDefinitionInterface
  16. *
  17. * @ingroup typed_data
  18. */
  19. interface ComplexDataInterface extends TraversableTypedDataInterface {
  20. /**
  21. * Gets the data definition.
  22. *
  23. * @return \Drupal\Core\TypedData\ComplexDataDefinitionInterface
  24. * The data definition object describing the complex data.
  25. */
  26. public function getDataDefinition();
  27. /**
  28. * Gets a property object.
  29. *
  30. * @param $property_name
  31. * The name of the property to get; e.g., 'title' or 'name'.
  32. *
  33. * @return \Drupal\Core\TypedData\TypedDataInterface
  34. * The property object.
  35. *
  36. * @throws \InvalidArgumentException
  37. * If an invalid property name is given.
  38. * @throws \Drupal\Core\TypedData\Exception\MissingDataException
  39. * If the complex data structure is unset and no property can be created.
  40. */
  41. public function get($property_name);
  42. /**
  43. * Sets a property value.
  44. *
  45. * @param $property_name
  46. * The name of the property to set; e.g., 'title' or 'name'.
  47. * @param $value
  48. * The value to set, or NULL to unset the property.
  49. * @param bool $notify
  50. * (optional) Whether to notify the parent object of the change. Defaults to
  51. * TRUE. If the update stems from a parent object, set it to FALSE to avoid
  52. * being notified again.
  53. *
  54. * @return $this
  55. *
  56. * @throws \InvalidArgumentException
  57. * If the specified property does not exist.
  58. * @throws \Drupal\Core\TypedData\Exception\MissingDataException
  59. * If the complex data structure is unset and no property can be set.
  60. */
  61. public function set($property_name, $value, $notify = TRUE);
  62. /**
  63. * Gets an array of property objects.
  64. *
  65. * @param bool $include_computed
  66. * If set to TRUE, computed properties are included. Defaults to FALSE.
  67. *
  68. * @return \Drupal\Core\TypedData\TypedDataInterface[]
  69. * An array of property objects implementing the TypedDataInterface, keyed
  70. * by property name.
  71. *
  72. * @throws \Drupal\Core\TypedData\Exception\MissingDataException
  73. * If the complex data structure is unset and no property can be created.
  74. */
  75. public function getProperties($include_computed = FALSE);
  76. /**
  77. * Returns an array of all property values.
  78. *
  79. * Gets an array of plain property values including all not-computed
  80. * properties.
  81. *
  82. * @return array
  83. * An array of property values, keyed by property name.
  84. *
  85. * @throws \Drupal\Core\TypedData\Exception\MissingDataException
  86. * If the complex data structure is unset and no property can be created.
  87. */
  88. public function toArray();
  89. /**
  90. * Determines whether the data structure is empty.
  91. *
  92. * @return bool
  93. * TRUE if the data structure is empty, FALSE otherwise.
  94. */
  95. public function isEmpty();
  96. }