plugin.api.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Plugin system.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Alter the filtering of plugin definitions for a specific plugin type.
  12. *
  13. * TYPE (e.g. "block", "layout") limits hook scope to a plugin type.
  14. * For example, HOOK_plugin_filter_block_alter() would be invoked
  15. * by a hook listener which specifies the 'block' plugin list,
  16. * e.g., BlockLibraryController or ChooseBlockController.
  17. *
  18. * @param \Drupal\Component\Plugin\Definition\PluginDefinitionInterface[]|array[] $definitions
  19. * The array of plugin definitions.
  20. * @param mixed[] $extra
  21. * An associative array containing additional information provided by the code
  22. * requesting the filtered definitions.
  23. * @param string $consumer
  24. * A string identifying the consumer of these plugin definitions.
  25. */
  26. function hook_plugin_filter_TYPE_alter(array &$definitions, array $extra, $consumer) {
  27. // Remove the "Help" block from the Block UI list.
  28. if ($consumer == 'block_ui') {
  29. unset($definitions['help_block']);
  30. }
  31. // If the theme is specified, remove the branding block from the Bartik theme.
  32. if (isset($extra['theme']) && $extra['theme'] === 'bartik') {
  33. unset($definitions['system_branding_block']);
  34. }
  35. // Remove the "Main page content" block from everywhere.
  36. unset($definitions['system_main_block']);
  37. }
  38. /**
  39. * Alter the filtering of plugin definitions for a specific type and consumer.
  40. *
  41. * TYPE (e.g. "block", "layout") limits hook scope to a plugin type.
  42. * CONSUMER (e.g., "block_ui", "layout_builder") limits hook scope to one or
  43. * more listeners, typically provided the same module. For example,
  44. * HOOK_plugin_filter_layout__layout_builder_alter() would affect
  45. * Layout Builder's listeners for the 'layout' plugin type (see
  46. * ChooseSectionController), while HOOK_plugin_filter_block__block_ui_alter()
  47. * would affect the Block UI's listeners for the 'block' plugin type.
  48. *
  49. * @param \Drupal\Component\Plugin\Definition\PluginDefinitionInterface[]|array[] $definitions
  50. * The array of plugin definitions.
  51. * @param mixed[] $extra
  52. * An associative array containing additional information provided by the code
  53. * requesting the filtered definitions.
  54. */
  55. function hook_plugin_filter_TYPE__CONSUMER_alter(array &$definitions, array $extra) {
  56. // Explicitly remove the "Help" block for this consumer.
  57. unset($definitions['help_block']);
  58. }
  59. /**
  60. * @} End of "addtogroup hooks".
  61. */