5 * Fake third-party hook implementations for ConfigTest entities.
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.
12 use Drupal\config_test\Entity\ConfigTest;
15 * Implements hook_config_test_load().
17 function config_test_config_test_load() {
18 $GLOBALS['hook_config_test']['load'] = __FUNCTION__;
22 * Implements hook_ENTITY_TYPE_create() for 'config_test'.
24 function config_test_config_test_create(ConfigTest $config_test) {
25 if (\Drupal::state()->get('config_test.prepopulate')) {
26 $config_test->set('foo', 'baz');
28 _config_test_update_is_syncing_store('create', $config_test);
32 * Implements hook_config_test_presave().
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);
40 * Implements hook_config_test_insert().
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);
48 * Implements hook_config_test_update().
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);
56 * Implements hook_config_test_predelete().
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);
64 * Implements hook_config_test_delete().
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);
72 * Helper function for testing hooks during configuration sync.
76 * @param \Drupal\config_test\Entity\ConfigTest $config_test
77 * The ConfigTest entity.
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);