config_test.hooks.inc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @file
  4. * Fake third-party hook implementations for ConfigTest entities.
  5. *
  6. * Testing the module/hook system is not the purpose of this test helper module.
  7. * Therefore, this file implements hooks on behalf of config_test module for
  8. * config_test entity hooks themselves.
  9. */
  10. use Drupal\config_test\Entity\ConfigTest;
  11. /**
  12. * Implements hook_config_test_load().
  13. */
  14. function config_test_config_test_load() {
  15. $GLOBALS['hook_config_test']['load'] = __FUNCTION__;
  16. }
  17. /**
  18. * Implements hook_ENTITY_TYPE_create() for 'config_test'.
  19. */
  20. function config_test_config_test_create(ConfigTest $config_test) {
  21. if (\Drupal::state()->get('config_test.prepopulate')) {
  22. $config_test->set('foo', 'baz');
  23. }
  24. _config_test_update_is_syncing_store('create', $config_test);
  25. }
  26. /**
  27. * Implements hook_config_test_presave().
  28. */
  29. function config_test_config_test_presave(ConfigTest $config_test) {
  30. $GLOBALS['hook_config_test']['presave'] = __FUNCTION__;
  31. _config_test_update_is_syncing_store('presave', $config_test);
  32. }
  33. /**
  34. * Implements hook_config_test_insert().
  35. */
  36. function config_test_config_test_insert(ConfigTest $config_test) {
  37. $GLOBALS['hook_config_test']['insert'] = __FUNCTION__;
  38. _config_test_update_is_syncing_store('insert', $config_test);
  39. }
  40. /**
  41. * Implements hook_config_test_update().
  42. */
  43. function config_test_config_test_update(ConfigTest $config_test) {
  44. $GLOBALS['hook_config_test']['update'] = __FUNCTION__;
  45. _config_test_update_is_syncing_store('update', $config_test);
  46. }
  47. /**
  48. * Implements hook_config_test_predelete().
  49. */
  50. function config_test_config_test_predelete(ConfigTest $config_test) {
  51. $GLOBALS['hook_config_test']['predelete'] = __FUNCTION__;
  52. _config_test_update_is_syncing_store('predelete', $config_test);
  53. }
  54. /**
  55. * Implements hook_config_test_delete().
  56. */
  57. function config_test_config_test_delete(ConfigTest $config_test) {
  58. $GLOBALS['hook_config_test']['delete'] = __FUNCTION__;
  59. _config_test_update_is_syncing_store('delete', $config_test);
  60. }
  61. /**
  62. * Helper function for testing hooks during configuration sync.
  63. *
  64. * @param string $hook
  65. * The fired hook.
  66. * @param \Drupal\config_test\Entity\ConfigTest $config_test
  67. * The ConfigTest entity.
  68. */
  69. function _config_test_update_is_syncing_store($hook, ConfigTest $config_test) {
  70. $current_value = \Drupal::state()->get('config_test.store_isSyncing', FALSE);
  71. if ($current_value !== FALSE) {
  72. $current_value['global_state::' . $hook] = \Drupal::isConfigSyncing();
  73. $current_value['entity_state::' . $hook] = $config_test->isSyncing();
  74. \Drupal::state()->set('config_test.store_isSyncing', $current_value);
  75. }
  76. }