Provides Config module hook implementations for testing purposes.
<?php
/**
* @file
* Provides Config module hook implementations for testing purposes.
*/
use Drupal\config_test\Plugin\Core\Entity\ConfigTest;
use Symfony\Component\HttpFoundation\RedirectResponse;
require_once dirname(__FILE__) . '/config_test.hooks.inc';
/**
* Entity URI callback.
*
* @param Drupal\config_test\Plugin\Core\Entity\ConfigTest $config_test
* A ConfigTest entity.
*/
function config_test_uri(ConfigTest $config_test) {
return array(
'path' => 'admin/structure/config_test/manage/' . $config_test
->id(),
);
}
/**
* 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_edit',
);
$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;
}
/**
* Implements hook_local_actions()
*/
function config_test_local_actions() {
return array(
array(
'route_name' => 'config_test_entity_add',
'title' => t('Add test configuration'),
'appears_on' => array(
'config_test_list_page',
),
),
);
}
/**
* 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';
}
Name | Description |
---|---|
config_test_cache_flush | Implements hook_cache_flush(). |
config_test_config_test_create | Implements hook_ENTITY_TYPE_create(). |
config_test_entity_info_alter | Implements hook_entity_info_alter(). |
config_test_load | Loads a ConfigTest object. |
config_test_local_actions | Implements hook_local_actions() |
config_test_menu | Implements hook_menu(). |
config_test_uri | Entity URI callback. |