ContextInterface.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. namespace Drupal\context;
  3. use Drupal\Core\Condition\ConditionInterface;
  4. use Drupal\Core\Condition\ConditionPluginCollection;
  5. use Drupal\Core\Config\Entity\ConfigEntityInterface;
  6. use Drupal\context\Plugin\ContextReactionPluginCollection;
  7. use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
  8. interface ContextInterface extends ConfigEntityInterface, EntityWithPluginCollectionInterface {
  9. /**
  10. * The default value for a context that is not assigned to a group.
  11. */
  12. const CONTEXT_GROUP_NONE = NULL;
  13. /**
  14. * Get the ID of the context.
  15. *
  16. * @return string
  17. */
  18. public function id();
  19. /**
  20. * Get the machine name of the context.
  21. *
  22. * @return string
  23. */
  24. public function getName();
  25. /**
  26. * Set the machine name of the context.
  27. *
  28. * @param string $name
  29. *
  30. * @return $this
  31. */
  32. public function setName($name);
  33. /**
  34. * Get the context label.
  35. *
  36. * @return string
  37. */
  38. public function getLabel();
  39. /**
  40. * Set the context label.
  41. *
  42. * @param string $label
  43. *
  44. * @return $this
  45. */
  46. public function setLabel($label);
  47. /**
  48. * Get the context description.
  49. *
  50. * @return string
  51. */
  52. public function getDescription();
  53. /**
  54. * Set the context description.
  55. *
  56. * @param string $description
  57. *
  58. * @return $this
  59. */
  60. public function setDescription($description);
  61. /**
  62. * Get the group this context belongs to.
  63. *
  64. * @return null|string
  65. */
  66. public function getGroup();
  67. /**
  68. * Set the group this context should belong to.
  69. *
  70. * @param null|string $group
  71. *
  72. * @return $this
  73. */
  74. public function setGroup($group);
  75. /**
  76. * Get the weight for this context.
  77. *
  78. * @return int
  79. */
  80. public function getWeight();
  81. /**
  82. * Set the weight for this context.
  83. *
  84. * @param int $weight
  85. * The weight to set for this context.
  86. *
  87. * @return $this
  88. */
  89. public function setWeight($weight);
  90. /**
  91. * If the context requires all conditions to validate.
  92. *
  93. * @return boolean
  94. */
  95. public function requiresAllConditions();
  96. /**
  97. * Set if all conditions should be required for this context to validate.
  98. *
  99. * @param bool $require
  100. * If a condition is required or not.
  101. *
  102. * @return $this
  103. */
  104. public function setRequireAllConditions($require);
  105. /**
  106. * Get a list of all conditions.
  107. *
  108. * @return ConditionInterface[]|ConditionPluginCollection
  109. */
  110. public function getConditions();
  111. /**
  112. * Get a condition with the specified ID.
  113. *
  114. * @param string $condition_id
  115. * The condition to get.
  116. *
  117. * @return \Drupal\Core\Condition\ConditionInterface
  118. */
  119. public function getCondition($condition_id);
  120. /**
  121. * Set the conditions.
  122. *
  123. * @param array $configuration
  124. * The configuration for the condition plugin.
  125. *
  126. * @return string
  127. */
  128. public function addCondition(array $configuration);
  129. /**
  130. * Remove the specified condition.
  131. *
  132. * @param string $condition_id
  133. * The id of the condition to remove.
  134. *
  135. * @return $this
  136. */
  137. public function removeCondition($condition_id);
  138. /**
  139. * Check to see if the context has the specified condition.
  140. *
  141. * @param string $condition_id
  142. * The ID of the condition to check for.
  143. *
  144. * @return bool
  145. */
  146. public function hasCondition($condition_id);
  147. /**
  148. * Get a list of all the reactions.
  149. *
  150. * @return ContextReactionInterface[]|ContextReactionPluginCollection
  151. */
  152. public function getReactions();
  153. /**
  154. * Get a reaction with the specified ID.
  155. *
  156. * @param string $reaction_id
  157. * The ID of the reaction to get.
  158. *
  159. * @return ContextReactionInterface
  160. */
  161. public function getReaction($reaction_id);
  162. /**
  163. * Add a context reaction.
  164. *
  165. * @param array $configuration
  166. *
  167. * @return string
  168. */
  169. public function addReaction(array $configuration);
  170. /**
  171. * Remove the specified reaction.
  172. *
  173. * @param string $reaction_id
  174. * The id of the reaction to remove.
  175. *
  176. * @return $this
  177. */
  178. public function removeReaction($reaction_id);
  179. /**
  180. * Check to see if the context has the specified reaction.
  181. *
  182. * @param string $reaction_id
  183. * The ID of the reaction to check for.
  184. *
  185. * @return bool
  186. */
  187. public function hasReaction($reaction_id);
  188. }