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