Select Git revision
node.module
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
config_test.module 2.61 KiB
<?php
/**
* @file
* Provides Config module hook implementations for testing purposes.
*/
use Drupal\config_test\Entity\ConfigTest;
use Symfony\Component\HttpFoundation\RedirectResponse;
require_once dirname(__FILE__) . '/config_test.hooks.inc';
/**
* Implements hook_menu().
*/
function config_test_menu() {
$items['admin/structure/config_test'] = array(
'title' => 'Test configuration',
'route_name' => 'config_test.list_page',
);
$items['admin/structure/config_test/add'] = array(
'title' => 'Add test configuration',
'route_name' => 'config_test.entity_add',
'type' => MENU_SIBLING_LOCAL_TASK,
);
$items['admin/structure/config_test/manage/%config_test'] = array(
'route_name' => 'config_test.entity',
);
$items['admin/structure/config_test/manage/%config_test/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/structure/config_test/manage/%config_test/delete'] = array(
'title' => 'Delete',
'route_name' => 'config_test.entity_delete',
);
$items['admin/structure/config_test/manage/%config_test/enable'] = array(
'title' => 'Enable',
'route_name' => 'config_test.entity_enable',
);
$items['admin/structure/config_test/manage/%config_test/disable'] = array(
'title' => 'Disable',
'route_name' => 'config_test.entity_disable',
);
return $items;
}
/**
* Loads a ConfigTest object.
*
* @param string $id
* The ID of the ConfigTest object to load.
*/
function config_test_load($id) {
return entity_load('config_test', $id);
}
/**
* Implements hook_cache_flush().
*/
function config_test_cache_flush() {
// Set a global value we can check in test code.
$GLOBALS['hook_cache_flush'] = __FUNCTION__;
}
/**
* Implements hook_ENTITY_TYPE_create().
*/
function config_test_config_test_create(ConfigTest $config_test) {
if (\Drupal::state()->get('config_test.prepopulate')) {
$config_test->set('foo', 'baz');
}
}
/**
* Implements hook_entity_info_alter().
*/
function config_test_entity_info_alter(&$entity_info) {
// The 'translatable' entity key is not supposed to change over time. In this
// case we can safely do it because we set it once and we do not change it for
// all the duration of the test session.
$entity_info['config_test']['translatable'] = \Drupal::service('state')->get('config_test.translatable');
// Create a clone of config_test that does not have a status.
$entity_info['config_test_no_status'] = $entity_info['config_test'];
unset($entity_info['config_test_no_status']['entity_keys']['status']);
$entity_info['config_test_no_status']['config_prefix'] = 'config_test.no_status';
}