EntityDisplayRepositoryInterface.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. /**
  4. * Provides an interface for an entity display repository.
  5. */
  6. interface EntityDisplayRepositoryInterface {
  7. /**
  8. * The default display mode ID.
  9. *
  10. * @var string
  11. */
  12. const DEFAULT_DISPLAY_MODE = 'default';
  13. /**
  14. * Gets the entity view mode info for all entity types.
  15. *
  16. * @return array
  17. * The view mode info for all entity types.
  18. */
  19. public function getAllViewModes();
  20. /**
  21. * Gets the entity view mode info for a specific entity type.
  22. *
  23. * @param string $entity_type_id
  24. * The entity type whose view mode info should be returned.
  25. *
  26. * @return array
  27. * The view mode info for a specific entity type.
  28. */
  29. public function getViewModes($entity_type_id);
  30. /**
  31. * Gets the entity form mode info for all entity types.
  32. *
  33. * @return array
  34. * The form mode info for all entity types.
  35. */
  36. public function getAllFormModes();
  37. /**
  38. * Gets the entity form mode info for a specific entity type.
  39. *
  40. * @param string $entity_type_id
  41. * The entity type whose form mode info should be returned.
  42. *
  43. * @return array
  44. * The form mode info for a specific entity type.
  45. */
  46. public function getFormModes($entity_type_id);
  47. /**
  48. * Gets an array of view mode options.
  49. *
  50. * @param string $entity_type_id
  51. * The entity type whose view mode options should be returned.
  52. *
  53. * @return array
  54. * An array of view mode labels, keyed by the display mode ID.
  55. */
  56. public function getViewModeOptions($entity_type_id);
  57. /**
  58. * Gets an array of form mode options.
  59. *
  60. * @param string $entity_type_id
  61. * The entity type whose form mode options should be returned.
  62. *
  63. * @return array
  64. * An array of form mode labels, keyed by the display mode ID.
  65. */
  66. public function getFormModeOptions($entity_type_id);
  67. /**
  68. * Returns an array of enabled view mode options by bundle.
  69. *
  70. * @param string $entity_type_id
  71. * The entity type whose view mode options should be returned.
  72. * @param string $bundle
  73. * The name of the bundle.
  74. *
  75. * @return array
  76. * An array of view mode labels, keyed by the display mode ID.
  77. */
  78. public function getViewModeOptionsByBundle($entity_type_id, $bundle);
  79. /**
  80. * Returns an array of enabled form mode options by bundle.
  81. *
  82. * @param string $entity_type_id
  83. * The entity type whose form mode options should be returned.
  84. * @param string $bundle
  85. * The name of the bundle.
  86. *
  87. * @return array
  88. * An array of form mode labels, keyed by the display mode ID.
  89. */
  90. public function getFormModeOptionsByBundle($entity_type_id, $bundle);
  91. /**
  92. * Clears the gathered display mode info.
  93. *
  94. * @return $this
  95. */
  96. public function clearDisplayModeInfo();
  97. /**
  98. * Returns the entity view display associated with a bundle and view mode.
  99. *
  100. * Use this function when assigning suggested display options for a component
  101. * in a given view mode. Note that they will only be actually used at render
  102. * time if the view mode itself is configured to use dedicated display
  103. * settings for the bundle; if not, the 'default' display is used instead.
  104. *
  105. * The function reads the entity view display from the current configuration,
  106. * or returns a ready-to-use empty one if configuration entry exists yet for
  107. * this bundle and view mode. This streamlines manipulation of display objects
  108. * by always returning a consistent object that reflects the current state of
  109. * the configuration.
  110. *
  111. * Example usage:
  112. * - Set the 'body' field to be displayed and the 'field_image' field to be
  113. * hidden on article nodes in the 'default' display.
  114. * @code
  115. * \Drupal::service('entity_display.repository')
  116. * ->getViewDisplay('node', 'article', 'default')
  117. * ->setComponent('body', array(
  118. * 'type' => 'text_summary_or_trimmed',
  119. * 'settings' => array('trim_length' => '200')
  120. * 'weight' => 1,
  121. * ))
  122. * ->removeComponent('field_image')
  123. * ->save();
  124. * @endcode
  125. *
  126. * @param string $entity_type
  127. * The entity type.
  128. * @param string $bundle
  129. * The bundle.
  130. * @param string $view_mode
  131. * (optional) The view mode. Defaults to self::DEFAULT_DISPLAY_MODE.
  132. *
  133. * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface
  134. * The entity view display associated with the view mode.
  135. */
  136. public function getViewDisplay($entity_type, $bundle, $view_mode = self::DEFAULT_DISPLAY_MODE);
  137. /**
  138. * Returns the entity form display associated with a bundle and form mode.
  139. *
  140. * The function reads the entity form display object from the current
  141. * configuration, or returns a ready-to-use empty one if no configuration
  142. * entry exists yet for this bundle and form mode. This streamlines
  143. * manipulation of entity form displays by always returning a consistent
  144. * object that reflects the current state of the configuration.
  145. *
  146. * Example usage:
  147. * - Set the 'body' field to be displayed with the
  148. * 'text_textarea_with_summary' widget and the 'field_image' field to be
  149. * hidden on article nodes in the 'default' form mode.
  150. * @code
  151. * \Drupal::service('entity_display.repository')
  152. * ->getFormDisplay('node', 'article', 'default')
  153. * ->setComponent('body', array(
  154. * 'type' => 'text_textarea_with_summary',
  155. * 'weight' => 1,
  156. * ))
  157. * ->setComponent('field_image', array(
  158. * 'region' => 'hidden',
  159. * ))
  160. * ->save();
  161. * @endcode
  162. *
  163. * @param string $entity_type
  164. * The entity type.
  165. * @param string $bundle
  166. * The bundle.
  167. * @param string $form_mode
  168. * (optional) The form mode. Defaults to self::DEFAULT_DISPLAY_MODE.
  169. *
  170. * @return \Drupal\Core\Entity\Display\EntityFormDisplayInterface
  171. * The entity form display associated with the given form mode.
  172. *
  173. * @see \Drupal\Core\Entity\EntityStorageInterface::create()
  174. * @see \Drupal\Core\Entity\EntityStorageInterface::load()
  175. */
  176. public function getFormDisplay($entity_type, $bundle, $form_mode = self::DEFAULT_DISPLAY_MODE);
  177. }