class ConfigTestHooksHooks

Hook implementations for config_test.

Hierarchy

Expanded class hierarchy of ConfigTestHooksHooks

File

core/modules/config/tests/config_test/src/Hook/ConfigTestHooksHooks.php, line 13

Namespace

Drupal\config_test\Hook
View source
class ConfigTestHooksHooks {
  
  /**
   * Implements hook_ENTITY_TYPE_load().
   */
  public function configTestLoad() : void {
    $GLOBALS['hook_config_test']['load'] = 'config_test_config_test_load';
  }
  
  /**
   * Implements hook_ENTITY_TYPE_create() for 'config_test'.
   */
  public function configTestCreate(ConfigTest $config_test) : void {
    if (\Drupal::state()->get('config_test.prepopulate')) {
      $config_test->set('foo', 'baz');
    }
    $this->updateIsSyncingStore('create', $config_test);
  }
  
  /**
   * Implements hook_ENTITY_TYPE_presave().
   */
  public function configTestPresave(ConfigTest $config_test) : void {
    $GLOBALS['hook_config_test']['presave'] = 'config_test_config_test_presave';
    $this->updateIsSyncingStore('presave', $config_test);
  }
  
  /**
   * Implements hook_ENTITY_TYPE_insert().
   */
  public function configTestInsert(ConfigTest $config_test) : void {
    $GLOBALS['hook_config_test']['insert'] = 'config_test_config_test_insert';
    $this->updateIsSyncingStore('insert', $config_test);
  }
  
  /**
   * Implements hook_ENTITY_TYPE_update().
   */
  public function configTestUpdate(ConfigTest $config_test) : void {
    $GLOBALS['hook_config_test']['update'] = 'config_test_config_test_update';
    $this->updateIsSyncingStore('update', $config_test);
  }
  
  /**
   * Implements hook_ENTITY_TYPE_predelete().
   */
  public function configTestPredelete(ConfigTest $config_test) : void {
    $GLOBALS['hook_config_test']['predelete'] = 'config_test_config_test_predelete';
    $this->updateIsSyncingStore('predelete', $config_test);
  }
  
  /**
   * Implements hook_ENTITY_TYPE_delete().
   */
  public function configTestDelete(ConfigTest $config_test) : void {
    $GLOBALS['hook_config_test']['delete'] = 'config_test_config_test_delete';
    $this->updateIsSyncingStore('delete', $config_test);
  }
  
  /**
   * Helper function for testing hooks during configuration sync.
   *
   * @param string $hook
   *   The fired hook.
   * @param \Drupal\config_test\Entity\ConfigTest $config_test
   *   The ConfigTest entity.
   */
  protected function updateIsSyncingStore($hook, ConfigTest $config_test) {
    $current_value = \Drupal::state()->get('config_test.store_isSyncing', FALSE);
    if ($current_value !== FALSE) {
      $current_value['global_state::' . $hook] = \Drupal::isConfigSyncing();
      $current_value['entity_state::' . $hook] = $config_test->isSyncing();
      \Drupal::state()->set('config_test.store_isSyncing', $current_value);
    }
  }

}

Members

Title Sort descending Modifiers Object type Summary
ConfigTestHooksHooks::configTestCreate public function Implements hook_ENTITY_TYPE_create() for 'config_test'.
ConfigTestHooksHooks::configTestDelete public function Implements hook_ENTITY_TYPE_delete().
ConfigTestHooksHooks::configTestInsert public function Implements hook_ENTITY_TYPE_insert().
ConfigTestHooksHooks::configTestLoad public function Implements hook_ENTITY_TYPE_load().
ConfigTestHooksHooks::configTestPredelete public function Implements hook_ENTITY_TYPE_predelete().
ConfigTestHooksHooks::configTestPresave public function Implements hook_ENTITY_TYPE_presave().
ConfigTestHooksHooks::configTestUpdate public function Implements hook_ENTITY_TYPE_update().
ConfigTestHooksHooks::updateIsSyncingStore protected function Helper function for testing hooks during configuration sync.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.