ContextAwarePluginDefinitionInterface.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Drupal\Component\Plugin\Definition;
  3. use Drupal\Component\Plugin\Context\ContextDefinitionInterface;
  4. /**
  5. * Provides an interface for plugin definitions which use contexts.
  6. *
  7. * @ingroup Plugin
  8. */
  9. interface ContextAwarePluginDefinitionInterface extends PluginDefinitionInterface {
  10. /**
  11. * Checks if the plugin defines a particular context.
  12. *
  13. * @param string $name
  14. * The context name.
  15. *
  16. * @return bool
  17. * TRUE if the plugin defines the given context, otherwise FALSE.
  18. */
  19. public function hasContextDefinition($name);
  20. /**
  21. * Returns all context definitions for this plugin.
  22. *
  23. * @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface[]
  24. * The context definitions.
  25. */
  26. public function getContextDefinitions();
  27. /**
  28. * Returns a particular context definition for this plugin.
  29. *
  30. * @param string $name
  31. * The context name.
  32. *
  33. * @return \Drupal\Component\Plugin\Context\ContextDefinitionInterface
  34. * The context definition.
  35. *
  36. * @throws \Drupal\Component\Plugin\Exception\ContextException
  37. * Thrown if the plugin does not define the given context.
  38. */
  39. public function getContextDefinition($name);
  40. /**
  41. * Adds a context to this plugin definition.
  42. *
  43. * @param string $name
  44. * The context name.
  45. * @param \Drupal\Component\Plugin\Context\ContextDefinitionInterface $definition
  46. * The context definition.
  47. *
  48. * @return $this
  49. * The called object.
  50. */
  51. public function addContextDefinition($name, ContextDefinitionInterface $definition);
  52. /**
  53. * Removes a context definition from this plugin.
  54. *
  55. * @param string $name
  56. * The context name.
  57. *
  58. * @return $this
  59. * The called object.
  60. */
  61. public function removeContextDefinition($name);
  62. }