Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
|
@ -0,0 +1,6 @@
|
|||
id: dotted.default
|
||||
label: Default
|
||||
weight: 0
|
||||
protected_property: Default
|
||||
# Intentionally commented out to verify default status behavior.
|
||||
# status: 1
|
|
@ -0,0 +1,4 @@
|
|||
id: isinstallable
|
||||
label: Default
|
||||
weight: 0
|
||||
protected_property: Default
|
|
@ -0,0 +1,2 @@
|
|||
id: default
|
||||
label: Default
|
|
@ -0,0 +1,2 @@
|
|||
foo: bar
|
||||
404: herp
|
|
@ -0,0 +1,10 @@
|
|||
array: []
|
||||
boolean: true
|
||||
exp: 1.2e+34
|
||||
float: 3.14159
|
||||
float_as_integer: !!float 1
|
||||
hex: 0xC
|
||||
int: 99
|
||||
octal: 0775
|
||||
string: string
|
||||
string_int: '1'
|
|
@ -0,0 +1 @@
|
|||
foo: de bar
|
|
@ -0,0 +1 @@
|
|||
foo: en bar
|
|
@ -0,0 +1 @@
|
|||
foo: fr bar
|
|
@ -0,0 +1,6 @@
|
|||
# See \Drupal\config\Tests\ConfigInstallProfileOverrideTest
|
||||
id: override
|
||||
label: Default
|
||||
weight: 0
|
||||
protected_property: Default
|
||||
status: true
|
|
@ -0,0 +1,10 @@
|
|||
# See \Drupal\config\Tests\ConfigInstallProfileOverrideTest
|
||||
# This configuration entity has dependencies which would be met.
|
||||
id: override_unmet
|
||||
label: Default
|
||||
weight: 0
|
||||
protected_property: Default
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- tour
|
|
@ -0,0 +1,154 @@
|
|||
# Schema for the configuration files of the Configuration Test module.
|
||||
|
||||
config_test_dynamic:
|
||||
type: config_entity
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
weight:
|
||||
type: integer
|
||||
label: 'Weight'
|
||||
style:
|
||||
type: string
|
||||
label: 'style'
|
||||
size:
|
||||
type: string
|
||||
label: 'Size'
|
||||
size_value:
|
||||
type: string
|
||||
label: 'Size value'
|
||||
protected_property:
|
||||
type: string
|
||||
label: 'Protected property'
|
||||
|
||||
config_test.dynamic.*:
|
||||
type: config_test_dynamic
|
||||
label: 'Config test dynamic settings'
|
||||
|
||||
config_test.dynamic.*.*:
|
||||
type: config_test_dynamic
|
||||
label: 'Config test dynamic settings'
|
||||
|
||||
config_test.query.*:
|
||||
type: config_entity
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
array:
|
||||
type: sequence
|
||||
label: 'Array level 1'
|
||||
sequence:
|
||||
type: sequence
|
||||
label: 'Array level 2'
|
||||
sequence:
|
||||
type: integer
|
||||
label: 'Value'
|
||||
number:
|
||||
type: integer
|
||||
label: 'number'
|
||||
|
||||
config_test.types:
|
||||
type: config_object
|
||||
label: 'Configuration type'
|
||||
mapping:
|
||||
array:
|
||||
type: sequence
|
||||
label: 'Array'
|
||||
sequence:
|
||||
type: string
|
||||
label: 'Item'
|
||||
boolean:
|
||||
type: boolean
|
||||
label: 'Boolean'
|
||||
float:
|
||||
type: float
|
||||
label: 'Float'
|
||||
float_as_integer:
|
||||
type: float
|
||||
label: 'Float'
|
||||
exp:
|
||||
type: float
|
||||
label: 'Exponential'
|
||||
hex:
|
||||
type: integer
|
||||
label: 'Hexadecimal'
|
||||
int:
|
||||
type: integer
|
||||
label: 'Integer'
|
||||
octal:
|
||||
type: integer
|
||||
label: 'Octal'
|
||||
string:
|
||||
type: string
|
||||
label: 'String'
|
||||
string_int:
|
||||
type: string
|
||||
label: 'String integer'
|
||||
|
||||
config_test.no_status.default:
|
||||
type: config_object
|
||||
label: 'Configuration no status default'
|
||||
mapping:
|
||||
id:
|
||||
type: string
|
||||
label: 'ID'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
|
||||
config_test.system:
|
||||
type: config_object
|
||||
label: 'Configuration system'
|
||||
mapping:
|
||||
foo:
|
||||
type: string
|
||||
label: 'Foo'
|
||||
baz:
|
||||
type: string
|
||||
label: 'Baz'
|
||||
'404':
|
||||
type: string
|
||||
label: '404'
|
||||
|
||||
config_test.new:
|
||||
type: config_object
|
||||
label: 'Configuration test'
|
||||
mapping:
|
||||
key:
|
||||
type: string
|
||||
label: 'Test setting'
|
||||
new_key:
|
||||
type: string
|
||||
label: 'Test setting'
|
||||
uuid:
|
||||
type: string
|
||||
label: 'UUID'
|
||||
|
||||
config_test.old:
|
||||
type: config_test.new
|
||||
|
||||
config_test.foo:
|
||||
type: config_object
|
||||
label: 'Configuration test'
|
||||
mapping:
|
||||
value:
|
||||
type: mapping
|
||||
label: 'Value'
|
||||
mapping:
|
||||
key:
|
||||
type: string
|
||||
label: 'Key'
|
||||
label:
|
||||
type: label
|
||||
label: 'Label'
|
||||
|
||||
config_test.bar:
|
||||
type: config_test.foo
|
52
core/modules/config/tests/config_test/config_test.hooks.inc
Normal file
52
core/modules/config/tests/config_test/config_test.hooks.inc
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Fake third-party hook implementations for ConfigTest entities.
|
||||
*
|
||||
* Testing the module/hook system is not the purpose of this test helper module.
|
||||
* Therefore, this file implements hooks on behalf of config_test module for
|
||||
* config_test entity hooks themselves.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_config_test_load().
|
||||
*/
|
||||
function config_test_config_test_load() {
|
||||
$GLOBALS['hook_config_test']['load'] = __FUNCTION__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_config_test_presave().
|
||||
*/
|
||||
function config_test_config_test_presave() {
|
||||
$GLOBALS['hook_config_test']['presave'] = __FUNCTION__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_config_test_insert().
|
||||
*/
|
||||
function config_test_config_test_insert() {
|
||||
$GLOBALS['hook_config_test']['insert'] = __FUNCTION__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_config_test_update().
|
||||
*/
|
||||
function config_test_config_test_update() {
|
||||
$GLOBALS['hook_config_test']['update'] = __FUNCTION__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_config_test_predelete().
|
||||
*/
|
||||
function config_test_config_test_predelete() {
|
||||
$GLOBALS['hook_config_test']['predelete'] = __FUNCTION__;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_config_test_delete().
|
||||
*/
|
||||
function config_test_config_test_delete() {
|
||||
$GLOBALS['hook_config_test']['delete'] = __FUNCTION__;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
name: 'Configuration test'
|
||||
type: module
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,5 @@
|
|||
config_test_entity_add_local_action:
|
||||
route_name: config_test.entity_add
|
||||
title: 'Add test configuration'
|
||||
appears_on:
|
||||
- entity.config_test.collection
|
|
@ -0,0 +1,4 @@
|
|||
entity.config_test.edit_form_tab:
|
||||
route_name: entity.config_test.edit_form
|
||||
title: 'Edit'
|
||||
base_route: entity.config_test.edit_form
|
64
core/modules/config/tests/config_test/config_test.module
Normal file
64
core/modules/config/tests/config_test/config_test.module
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?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';
|
||||
|
||||
/**
|
||||
* 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() for 'config_test'.
|
||||
*/
|
||||
function config_test_config_test_create(ConfigTest $config_test) {
|
||||
if (\Drupal::state()->get('config_test.prepopulate')) {
|
||||
$config_test->set('foo', 'baz');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_alter().
|
||||
*/
|
||||
function config_test_entity_type_alter(array &$entity_types) {
|
||||
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
|
||||
// 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_types['config_test']->set('translatable', \Drupal::service('state')->get('config_test.translatable'));
|
||||
|
||||
// Create a clone of config_test that does not have a status.
|
||||
$entity_types['config_test_no_status'] = clone $entity_types['config_test'];
|
||||
$config_test_no_status = &$entity_types['config_test_no_status'];
|
||||
$config_test_no_status->setLinkTemplate('edit-form', '/admin/structure/config_test/manage/{config_test_no_status}');
|
||||
$config_test_no_status->setLinkTemplate('delete-form', '/admin/structure/config_test/manage/{config_test_no_status}/delete');
|
||||
|
||||
$keys = $config_test_no_status->getKeys();
|
||||
unset($keys['status']);
|
||||
$config_test_no_status->set('id', 'config_test_no_status');
|
||||
$config_test_no_status->set('entity_keys', $keys);
|
||||
$config_test_no_status->set('config_prefix', 'no_status');
|
||||
if (\Drupal::service('state')->get('config_test.lookup_keys', FALSE)) {
|
||||
$entity_types['config_test']->set('lookup_keys', ['uuid', 'style']);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
entity.config_test.collection:
|
||||
path: '/admin/structure/config_test'
|
||||
defaults:
|
||||
_entity_list: 'config_test'
|
||||
_title: 'Test configuration'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
config_test.entity_add:
|
||||
path: '/admin/structure/config_test/add'
|
||||
defaults:
|
||||
_entity_form: 'config_test'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
entity.config_test.edit_form:
|
||||
path: '/admin/structure/config_test/manage/{config_test}'
|
||||
defaults:
|
||||
_entity_form: config_test
|
||||
_title_callback: '\Drupal\config_test\ConfigTestController::editTitle'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
entity.config_test.edit_form_config_test_no_status:
|
||||
path: '/admin/structure/config_test/manage/{config_test_no_status}'
|
||||
defaults:
|
||||
_entity_form: config_test_no_status
|
||||
_title_callback: '\Drupal\config_test\ConfigTestController::editTitle'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
entity.config_test.enable:
|
||||
path: '/admin/structure/config_test/manage/{config_test}/enable'
|
||||
defaults:
|
||||
_controller: '\Drupal\config_test\ConfigTestController::enable'
|
||||
entity_type: 'config_test'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
entity.config_test.disable:
|
||||
path: '/admin/structure/config_test/manage/{config_test}/disable'
|
||||
defaults:
|
||||
_controller: '\Drupal\config_test\ConfigTestController::disable'
|
||||
entity_type: 'config_test'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
entity.config_test.delete_form:
|
||||
path: '/admin/structure/config_test/manage/{config_test}/delete'
|
||||
defaults:
|
||||
_entity_form: 'config_test.delete'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
entity.config_test.delete_form_config_test_no_status:
|
||||
path: '/admin/structure/config_test/manage/{config_test_no_status}/delete'
|
||||
defaults:
|
||||
_entity_form: 'config_test_no_status.delete'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
||||
|
||||
config_test.schema_listener:
|
||||
path: '/config_test/schema_listener'
|
||||
defaults:
|
||||
_controller: '\Drupal\config_test\SchemaListenerController::test'
|
||||
requirements:
|
||||
_permission: 'administer site configuration'
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\ConfigTestAccessControlHandler.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\Entity\EntityAccessControlHandler;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Defines the access control handler for the config_test entity type.
|
||||
*
|
||||
* @see \Drupal\config_test\Entity\ConfigTest
|
||||
*/
|
||||
class ConfigTestAccessControlHandler extends EntityAccessControlHandler {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
||||
return AccessResult::allowed();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
|
||||
return AccessResult::allowed();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\ConfigTestController.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\config_test\Entity\ConfigTest;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
|
||||
/**
|
||||
* Route controller class for the config_test module.
|
||||
*/
|
||||
class ConfigTestController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* Route title callback.
|
||||
*
|
||||
* @param \Drupal\config_test\Entity\ConfigTest $config_test
|
||||
* The ConfigTest object.
|
||||
*
|
||||
* @return string
|
||||
* The title for the ConfigTest edit form.
|
||||
*/
|
||||
public function editTitle(ConfigTest $config_test) {
|
||||
return $this->t('Edit %label', array('%label' => $config_test->label()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a ConfigTest object.
|
||||
*
|
||||
* @param \Drupal\config_test\ConfigTest $config_test
|
||||
* The ConfigTest object to enable.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* A redirect response to the config_test listing page.
|
||||
*/
|
||||
function enable(ConfigTest $config_test) {
|
||||
$config_test->enable()->save();
|
||||
return new RedirectResponse($config_test->url('collection', array('absolute' => TRUE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables a ConfigTest object.
|
||||
*
|
||||
* @param \Drupal\config_test\ConfigTest $config_test
|
||||
* The ConfigTest object to disable.
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse
|
||||
* A redirect response to the config_test listing page.
|
||||
*/
|
||||
function disable(ConfigTest $config_test) {
|
||||
$config_test->disable()->save();
|
||||
return new RedirectResponse($config_test->url('collection', array('absolute' => TRUE)));
|
||||
}
|
||||
|
||||
}
|
145
core/modules/config/tests/config_test/src/ConfigTestForm.php
Normal file
145
core/modules/config/tests/config_test/src/ConfigTestForm.php
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\ConfigTestForm.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Entity\EntityForm;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
|
||||
/**
|
||||
* Form controller for the test config edit forms.
|
||||
*/
|
||||
class ConfigTestForm extends EntityForm {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function form(array $form, FormStateInterface $form_state) {
|
||||
$form = parent::form($form, $form_state);
|
||||
|
||||
$entity = $this->entity;
|
||||
$form['label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Label',
|
||||
'#default_value' => $entity->label(),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['id'] = array(
|
||||
'#type' => 'machine_name',
|
||||
'#default_value' => $entity->id(),
|
||||
'#required' => TRUE,
|
||||
'#machine_name' => array(
|
||||
'exists' => 'config_test_load',
|
||||
'replace_pattern' => '[^a-z0-9_.]+',
|
||||
),
|
||||
);
|
||||
$form['weight'] = array(
|
||||
'#type' => 'weight',
|
||||
'#title' => 'Weight',
|
||||
'#default_value' => $entity->get('weight'),
|
||||
);
|
||||
$form['style'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'Image style',
|
||||
'#options' => array(),
|
||||
'#default_value' => $entity->get('style'),
|
||||
'#access' => FALSE,
|
||||
);
|
||||
if ($this->moduleHandler->moduleExists('image')) {
|
||||
$form['style']['#access'] = TRUE;
|
||||
$form['style']['#options'] = image_style_options();
|
||||
}
|
||||
|
||||
// The main premise of entity forms is that we get to work with an entity
|
||||
// object at all times instead of checking submitted values from the form
|
||||
// state.
|
||||
$size = $entity->get('size');
|
||||
|
||||
$form['size_wrapper'] = array(
|
||||
'#type' => 'container',
|
||||
'#attributes' => array(
|
||||
'id' => 'size-wrapper',
|
||||
),
|
||||
);
|
||||
$form['size_wrapper']['size'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'Size',
|
||||
'#options' => array(
|
||||
'custom' => 'Custom',
|
||||
),
|
||||
'#empty_option' => '- None -',
|
||||
'#default_value' => $size,
|
||||
'#ajax' => array(
|
||||
'callback' => '::updateSize',
|
||||
'wrapper' => 'size-wrapper',
|
||||
),
|
||||
);
|
||||
$form['size_wrapper']['size_submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Change size'),
|
||||
'#attributes' => array(
|
||||
'class' => array('js-hide'),
|
||||
),
|
||||
'#submit' => array(array(get_class($this), 'changeSize')),
|
||||
);
|
||||
$form['size_wrapper']['size_value'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'Custom size value',
|
||||
'#options' => array(
|
||||
'small' => 'Small',
|
||||
'medium' => 'Medium',
|
||||
'large' => 'Large',
|
||||
),
|
||||
'#default_value' => $entity->get('size_value'),
|
||||
'#access' => !empty($size),
|
||||
);
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Save',
|
||||
);
|
||||
$form['actions']['delete'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Delete',
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax callback for the size selection element.
|
||||
*/
|
||||
public static function updateSize(array $form, FormStateInterface $form_state) {
|
||||
return $form['size_wrapper'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Element submit handler for non-JS testing.
|
||||
*/
|
||||
public static function changeSize(array $form, FormStateInterface $form_state) {
|
||||
$form_state->setRebuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function save(array $form, FormStateInterface $form_state) {
|
||||
$entity = $this->entity;
|
||||
$status = $entity->save();
|
||||
|
||||
if ($status === SAVED_UPDATED) {
|
||||
drupal_set_message(format_string('%label configuration has been updated.', array('%label' => $entity->label())));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(format_string('%label configuration has been created.', array('%label' => $entity->label())));
|
||||
}
|
||||
|
||||
$form_state->setRedirectUrl($this->entity->urlInfo('collection'));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\ConfigTestInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
|
||||
/**
|
||||
* Provides an interface defining a config_test entity.
|
||||
*/
|
||||
interface ConfigTestInterface extends ConfigEntityInterface {
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\ConfigTestListBuilder.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
|
||||
/**
|
||||
* Defines a class to build a listing of ConfigTest entities.
|
||||
*
|
||||
* @see \Drupal\config_test\Entity\ConfigTest
|
||||
*/
|
||||
class ConfigTestListBuilder extends ConfigEntityListBuilder {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildHeader() {
|
||||
$header['label'] = t('Label');
|
||||
$header['id'] = t('Machine name');
|
||||
return $header + parent::buildHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildRow(EntityInterface $entity) {
|
||||
$row['label'] = $this->getLabel($entity);
|
||||
$row['id'] = $entity->id();
|
||||
return $row + parent::buildRow($entity);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\ConfigTestStorage.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityStorage;
|
||||
use Drupal\Core\Config\Config;
|
||||
|
||||
/**
|
||||
* @todo.
|
||||
*/
|
||||
class ConfigTestStorage extends ConfigEntityStorage {
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Core\Config\Entity\ConfigEntityStorage::importCreate().
|
||||
*/
|
||||
public function importCreate($name, Config $new_config, Config $old_config) {
|
||||
// Set a global value we can check in test code.
|
||||
$GLOBALS['hook_config_import'] = __METHOD__;
|
||||
|
||||
return parent::importCreate($name, $new_config, $old_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Core\Config\Entity\ConfigEntityStorage::importUpdate().
|
||||
*/
|
||||
public function importUpdate($name, Config $new_config, Config $old_config) {
|
||||
// Set a global value we can check in test code.
|
||||
$GLOBALS['hook_config_import'] = __METHOD__;
|
||||
|
||||
return parent::importUpdate($name, $new_config, $old_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Core\Config\Entity\ConfigEntityStorage::importDelete().
|
||||
*/
|
||||
public function importDelete($name, Config $new_config, Config $old_config) {
|
||||
// Set a global value we can check in test code.
|
||||
$GLOBALS['hook_config_import'] = __METHOD__;
|
||||
|
||||
return parent::importDelete($name, $new_config, $old_config);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\Entity\ConfigQueryTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test\Entity;
|
||||
|
||||
/**
|
||||
* Defines the ConfigQueryTest configuration entity used by the query test.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "config_query_test",
|
||||
* label = @Translation("Test configuration for query"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\config_test\ConfigTestStorage",
|
||||
* "list_builder" = "Drupal\Core\Config\Entity\ConfigEntityListBuilder",
|
||||
* "form" = {
|
||||
* "default" = "Drupal\config_test\ConfigTestForm"
|
||||
* }
|
||||
* },
|
||||
* config_prefix = "query",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label"
|
||||
* }
|
||||
* )
|
||||
*
|
||||
* @see \Drupal\system\Tests\Entity\ConfigEntityQueryTest
|
||||
*/
|
||||
class ConfigQueryTest extends ConfigTest {
|
||||
|
||||
/**
|
||||
* A number used by the sort tests.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $number;
|
||||
|
||||
/**
|
||||
* An array used by the wildcard tests.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $array = array();
|
||||
|
||||
}
|
164
core/modules/config/tests/config_test/src/Entity/ConfigTest.php
Normal file
164
core/modules/config/tests/config_test/src/Entity/ConfigTest.php
Normal file
|
@ -0,0 +1,164 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\Entity\ConfigTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test\Entity;
|
||||
|
||||
use Drupal\Core\Config\Entity\ConfigEntityBase;
|
||||
use Drupal\config_test\ConfigTestInterface;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityInterface;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
|
||||
/**
|
||||
* Defines the ConfigTest configuration entity.
|
||||
*
|
||||
* @ConfigEntityType(
|
||||
* id = "config_test",
|
||||
* label = @Translation("Test configuration"),
|
||||
* handlers = {
|
||||
* "storage" = "Drupal\config_test\ConfigTestStorage",
|
||||
* "list_builder" = "Drupal\config_test\ConfigTestListBuilder",
|
||||
* "form" = {
|
||||
* "default" = "Drupal\config_test\ConfigTestForm",
|
||||
* "delete" = "Drupal\Core\Entity\EntityDeleteForm"
|
||||
* },
|
||||
* "access" = "Drupal\config_test\ConfigTestAccessControlHandler"
|
||||
* },
|
||||
* config_prefix = "dynamic",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "label" = "label",
|
||||
* "status" = "status"
|
||||
* },
|
||||
* links = {
|
||||
* "edit-form" = "/admin/structure/config_test/manage/{config_test}",
|
||||
* "delete-form" = "/admin/structure/config_test/manage/{config_test}/delete",
|
||||
* "enable" = "/admin/structure/config_test/manage/{config_test}/enable",
|
||||
* "disable" = "/admin/structure/config_test/manage/{config_test}/disable",
|
||||
* "collection" = "/admin/structure/config_test",
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class ConfigTest extends ConfigEntityBase implements ConfigTestInterface {
|
||||
|
||||
/**
|
||||
* The machine name for the configuration entity.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* The human-readable name of the configuration entity.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $label;
|
||||
|
||||
/**
|
||||
* The weight of the configuration entity.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $weight = 0;
|
||||
|
||||
/**
|
||||
* The image style to use.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $style;
|
||||
|
||||
/**
|
||||
* A protected property of the configuration entity.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $protected_property;
|
||||
|
||||
/**
|
||||
* Overrides \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
|
||||
*/
|
||||
public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) {
|
||||
\Drupal::state()->set('config_entity_sort', TRUE);
|
||||
return parent::sort($a, $b);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
|
||||
// Used to test secondary writes during config sync.
|
||||
if ($this->id() == 'primary') {
|
||||
$secondary = $storage->create(array(
|
||||
'id' => 'secondary',
|
||||
'label' => 'Secondary Default',
|
||||
));
|
||||
$secondary->save();
|
||||
}
|
||||
if ($this->id() == 'deleter') {
|
||||
$deletee = $storage->load('deletee');
|
||||
$deletee->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function postDelete(EntityStorageInterface $storage, array $entities) {
|
||||
parent::postDelete($storage, $entities);
|
||||
foreach ($entities as $entity) {
|
||||
if ($entity->id() == 'deleter') {
|
||||
$deletee = $storage->load('deletee');
|
||||
$deletee->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function onDependencyRemoval(array $dependencies) {
|
||||
$changed = parent::onDependencyRemoval($dependencies);
|
||||
if (!isset($this->dependencies['enforced']['config'])) {
|
||||
return $changed;
|
||||
}
|
||||
$fix_deps = \Drupal::state()->get('config_test.fix_dependencies', array());
|
||||
foreach ($dependencies['config'] as $entity) {
|
||||
if (in_array($entity->getConfigDependencyName(), $fix_deps)) {
|
||||
$key = array_search($entity->getConfigDependencyName(), $this->dependencies['enforced']['config']);
|
||||
if ($key !== FALSE) {
|
||||
$changed = TRUE;
|
||||
unset($this->dependencies['enforced']['config'][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the enforced dependencies.
|
||||
*
|
||||
* @param array $dependencies
|
||||
* A config dependency array.
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @see \Drupal\Core\Config\Entity\ConfigDependencyManager
|
||||
*/
|
||||
public function setEnforcedDependencies(array $dependencies) {
|
||||
$this->dependencies['enforced'] = $dependencies;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isInstallable() {
|
||||
return $this->id != 'isinstallable' || \Drupal::state()->get('config_test.isinstallable');
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\SchemaListenerController.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\Config\Schema\SchemaIncompleteException;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Controller for testing \Drupal\Core\Config\Testing\ConfigSchemaChecker.
|
||||
*/
|
||||
class SchemaListenerController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* Constructs the SchemaListenerController object.
|
||||
*
|
||||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
|
||||
* The config factory.
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory) {
|
||||
$this->configFactory = $config_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('config.factory')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests the WebTestBase tests can use strict schema checking.
|
||||
*/
|
||||
public function test() {
|
||||
try {
|
||||
$this->configFactory->getEditable('config_schema_test.schemaless')->set('foo', 'bar')->save();
|
||||
}
|
||||
catch (SchemaIncompleteException $e) {
|
||||
return [
|
||||
'#markup' => $e->getMessage(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\config_test\TestInstallStorage.
|
||||
*/
|
||||
|
||||
namespace Drupal\config_test;
|
||||
|
||||
use Drupal\Core\Config\InstallStorage;
|
||||
use Drupal\Core\Extension\ExtensionDiscovery;
|
||||
|
||||
/**
|
||||
* Tests configuration of profiles, modules and themes.
|
||||
*
|
||||
* A test configuration storage to read configuration from all profiles, modules
|
||||
* and themes regardless of installation status or installed profile.
|
||||
*/
|
||||
class TestInstallStorage extends InstallStorage {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getAllFolders() {
|
||||
if (!isset($this->folders)) {
|
||||
$this->folders = $this->getCoreNames();
|
||||
$listing = new ExtensionDiscovery(\Drupal::root());
|
||||
$listing->setProfileDirectories(array());
|
||||
$this->folders += $this->getComponentNames($listing->scan('profile'));
|
||||
$this->folders += $this->getComponentNames($listing->scan('module'));
|
||||
$this->folders += $this->getComponentNames($listing->scan('theme'));
|
||||
}
|
||||
return $this->folders;
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue