Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
18
web/core/modules/system/tests/fixtures/update/block.block.secondtestfor2513534.yml
vendored
Normal file
18
web/core/modules/system/tests/fixtures/update/block.block.secondtestfor2513534.yml
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
uuid: 3c4e92c3-5fb1-408d-993c-6066559230be
|
||||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
theme:
|
||||
- bartik
|
||||
id: pagetitle_2
|
||||
theme: bartik
|
||||
region: '-1'
|
||||
weight: null
|
||||
provider: null
|
||||
plugin: page_title_block
|
||||
settings:
|
||||
id: page_title_block
|
||||
label: 'Page title'
|
||||
provider: core
|
||||
label_display: '0'
|
||||
visibility: { }
|
18
web/core/modules/system/tests/fixtures/update/block.block.testfor2513534.yml
vendored
Normal file
18
web/core/modules/system/tests/fixtures/update/block.block.testfor2513534.yml
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
uuid: 87097da9-29d1-441f-8b00-b93852c760d6
|
||||
langcode: en
|
||||
status: false
|
||||
dependencies:
|
||||
theme:
|
||||
- bartik
|
||||
id: pagetitle_1
|
||||
theme: bartik
|
||||
region: '-1'
|
||||
weight: -8
|
||||
provider: null
|
||||
plugin: page_title_block
|
||||
settings:
|
||||
id: page_title_block
|
||||
label: 'Page title'
|
||||
provider: core
|
||||
label_display: '0'
|
||||
visibility: { }
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -23,16 +23,16 @@ $block_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/block.block.thirdt
|
|||
|
||||
foreach ($block_configs as $block_config) {
|
||||
$connection->insert('config')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'collection',
|
||||
'name',
|
||||
'data',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => '',
|
||||
'name' => 'block.block.' . $block_config['id'],
|
||||
'data' => serialize($block_config),
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,64 +11,64 @@ use Drupal\Core\Database\Database;
|
|||
$connection = Database::getConnection();
|
||||
|
||||
$connection->insert('key_value')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'collection',
|
||||
'name',
|
||||
'value',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.body',
|
||||
'value' => 'a:2:{s:19:"block_content__body";a:4:{s:11:"description";s:42:"Data storage for block_content field body.";s:6:"fields";a:9:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:10:"body_value";a:3:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:1;}s:12:"body_summary";a:3:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:0;}s:11:"body_format";a:3:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:255;s:8:"not null";b:0;}}s:11:"primary key";a:4:{i:0;s:9:"entity_id";i:1;s:7:"deleted";i:2;s:5:"delta";i:3;s:8:"langcode";}s:7:"indexes";a:3:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}s:11:"body_format";a:1:{i:0;s:11:"body_format";}}}s:28:"block_content_revision__body";a:4:{s:11:"description";s:54:"Revision archive storage for block_content field body.";s:6:"fields";a:9:{s:6:"bundle";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:88:"The field instance bundle to which this row belongs, used when deleting a field instance";}s:7:"deleted";a:5:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;s:7:"default";i:0;s:11:"description";s:60:"A boolean indicating whether this data item has been deleted";}s:9:"entity_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:38:"The entity id this data is attached to";}s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:47:"The entity revision id this data is attached to";}s:8:"langcode";a:5:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;s:7:"default";s:0:"";s:11:"description";s:37:"The language code for this data item.";}s:5:"delta";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:8:"not null";b:1;s:11:"description";s:67:"The sequence number for this data item, used for multi-value fields";}s:10:"body_value";a:3:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:1;}s:12:"body_summary";a:3:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:0;}s:11:"body_format";a:3:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:255;s:8:"not null";b:0;}}s:11:"primary key";a:5:{i:0;s:9:"entity_id";i:1;s:11:"revision_id";i:2;s:7:"deleted";i:3;s:5:"delta";i:4;s:8:"langcode";}s:7:"indexes";a:3:{s:6:"bundle";a:1:{i:0;s:6:"bundle";}s:11:"revision_id";a:1:{i:0;s:11:"revision_id";}s:11:"body_format";a:1:{i:0;s:11:"body_format";}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.changed',
|
||||
'value' => 'a:2:{s:24:"block_content_field_data";a:1:{s:6:"fields";a:1:{s:7:"changed";a:2:{s:4:"type";s:3:"int";s:8:"not null";b:0;}}}s:28:"block_content_field_revision";a:1:{s:6:"fields";a:1:{s:7:"changed";a:2:{s:4:"type";s:3:"int";s:8:"not null";b:0;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.default_langcode',
|
||||
'value' => 'a:2:{s:24:"block_content_field_data";a:1:{s:6:"fields";a:1:{s:16:"default_langcode";a:3:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;}}}s:28:"block_content_field_revision";a:1:{s:6:"fields";a:1:{s:16:"default_langcode";a:3:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:1;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.id',
|
||||
'value' => 'a:4:{s:13:"block_content";a:1:{s:6:"fields";a:1:{s:2:"id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:1;}}}s:24:"block_content_field_data";a:1:{s:6:"fields";a:1:{s:2:"id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:1;}}}s:22:"block_content_revision";a:1:{s:6:"fields";a:1:{s:2:"id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:1;}}}s:28:"block_content_field_revision";a:1:{s:6:"fields";a:1:{s:2:"id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:1;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.info',
|
||||
'value' => 'a:2:{s:24:"block_content_field_data";a:1:{s:6:"fields";a:1:{s:4:"info";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:255;s:6:"binary";b:0;s:8:"not null";b:0;}}}s:28:"block_content_field_revision";a:1:{s:6:"fields";a:1:{s:4:"info";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:255;s:6:"binary";b:0;s:8:"not null";b:0;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.langcode',
|
||||
'value' => 'a:4:{s:13:"block_content";a:1:{s:6:"fields";a:1:{s:8:"langcode";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:12;s:8:"is_ascii";b:1;s:8:"not null";b:1;}}}s:24:"block_content_field_data";a:1:{s:6:"fields";a:1:{s:8:"langcode";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:12;s:8:"is_ascii";b:1;s:8:"not null";b:1;}}}s:22:"block_content_revision";a:1:{s:6:"fields";a:1:{s:8:"langcode";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:12;s:8:"is_ascii";b:1;s:8:"not null";b:1;}}}s:28:"block_content_field_revision";a:1:{s:6:"fields";a:1:{s:8:"langcode";a:4:{s:4:"type";s:7:"varchar";s:6:"length";i:12;s:8:"is_ascii";b:1;s:8:"not null";b:1;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.revision_id',
|
||||
'value' => 'a:4:{s:13:"block_content";a:1:{s:6:"fields";a:1:{s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:0;}}}s:24:"block_content_field_data";a:1:{s:6:"fields";a:1:{s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:1;}}}s:22:"block_content_revision";a:1:{s:6:"fields";a:1:{s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:1;}}}s:28:"block_content_field_revision";a:1:{s:6:"fields";a:1:{s:11:"revision_id";a:4:{s:4:"type";s:3:"int";s:8:"unsigned";b:1;s:4:"size";s:6:"normal";s:8:"not null";b:1;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.revision_log',
|
||||
'value' => 'a:1:{s:22:"block_content_revision";a:1:{s:6:"fields";a:1:{s:12:"revision_log";a:3:{s:4:"type";s:4:"text";s:4:"size";s:3:"big";s:8:"not null";b:0;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.revision_translation_affected',
|
||||
'value' => 'a:2:{s:24:"block_content_field_data";a:1:{s:6:"fields";a:1:{s:29:"revision_translation_affected";a:3:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:0;}}}s:28:"block_content_field_revision";a:1:{s:6:"fields";a:1:{s:29:"revision_translation_affected";a:3:{s:4:"type";s:3:"int";s:4:"size";s:4:"tiny";s:8:"not null";b:0;}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.type',
|
||||
'value' => 'a:2:{s:13:"block_content";a:2:{s:6:"fields";a:1:{s:4:"type";a:4:{s:11:"description";s:28:"The ID of the target entity.";s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;}}s:7:"indexes";a:1:{s:36:"block_content_field__type__target_id";a:1:{i:0;s:4:"type";}}}s:24:"block_content_field_data";a:2:{s:6:"fields";a:1:{s:4:"type";a:4:{s:11:"description";s:28:"The ID of the target entity.";s:4:"type";s:13:"varchar_ascii";s:6:"length";i:32;s:8:"not null";b:1;}}s:7:"indexes";a:1:{s:36:"block_content_field__type__target_id";a:1:{i:0;s:4:"type";}}}}',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => 'entity.storage_schema.sql',
|
||||
'name' => 'block_content.field_schema_data.uuid',
|
||||
'value' => 'a:1:{s:13:"block_content";a:2:{s:6:"fields";a:1:{s:4:"uuid";a:4:{s:4:"type";s:13:"varchar_ascii";s:6:"length";i:128;s:6:"binary";b:0;s:8:"not null";b:1;}}s:11:"unique keys";a:1:{s:32:"block_content_field__uuid__value";a:1:{i:0;s:4:"uuid";}}}}',
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
|
|
Binary file not shown.
|
@ -31,11 +31,11 @@ foreach ($block_configs as $block_config) {
|
|||
|
||||
// Update the config entity query "index".
|
||||
$existing_blocks = $connection->select('key_value')
|
||||
->fields('key_value', ['value'])
|
||||
->condition('collection', 'config.entity.key_store.block')
|
||||
->condition('name', 'theme:seven')
|
||||
->execute()
|
||||
->fetchField();
|
||||
->fields('key_value', ['value'])
|
||||
->condition('collection', 'config.entity.key_store.block')
|
||||
->condition('name', 'theme:seven')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$existing_blocks = unserialize($existing_blocks);
|
||||
|
||||
$connection->update('key_value')
|
||||
|
|
|
@ -31,11 +31,11 @@ foreach ($block_configs as $block_config) {
|
|||
|
||||
// Update the config entity query "index".
|
||||
$existing_blocks = $connection->select('key_value')
|
||||
->fields('key_value', ['value'])
|
||||
->condition('collection', 'config.entity.key_store.block')
|
||||
->condition('name', 'theme:seven')
|
||||
->execute()
|
||||
->fetchField();
|
||||
->fields('key_value', ['value'])
|
||||
->condition('collection', 'config.entity.key_store.block')
|
||||
->condition('name', 'theme:seven')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$existing_blocks = unserialize($existing_blocks);
|
||||
|
||||
$connection->update('key_value')
|
||||
|
|
50
web/core/modules/system/tests/fixtures/update/drupal-8.update-test-block-disabled-2513534.php
vendored
Normal file
50
web/core/modules/system/tests/fixtures/update/drupal-8.update-test-block-disabled-2513534.php
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains database additions to drupal-8.bare.standard.php.gz for testing the
|
||||
* upgrade path of https://www.drupal.org/node/2513534.
|
||||
*/
|
||||
|
||||
use Drupal\Component\Serialization\Yaml;
|
||||
use Drupal\Core\Database\Database;
|
||||
|
||||
$connection = Database::getConnection();
|
||||
|
||||
// A disabled block.
|
||||
$block_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/block.block.testfor2513534.yml'));
|
||||
|
||||
// A block placed in the default region.
|
||||
$block_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/block.block.secondtestfor2513534.yml'));
|
||||
|
||||
foreach ($block_configs as $block_config) {
|
||||
$connection->insert('config')
|
||||
->fields([
|
||||
'collection',
|
||||
'name',
|
||||
'data',
|
||||
])
|
||||
->values([
|
||||
'collection' => '',
|
||||
'name' => 'block.block.' . $block_config['id'],
|
||||
'data' => serialize($block_config),
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
|
||||
// Update the config entity query "index".
|
||||
$existing_blocks = $connection->select('key_value')
|
||||
->fields('key_value', ['value'])
|
||||
->condition('collection', 'config.entity.key_store.block')
|
||||
->condition('name', 'theme:bartik')
|
||||
->execute()
|
||||
->fetchField();
|
||||
$existing_blocks = unserialize($existing_blocks);
|
||||
|
||||
$connection->update('key_value')
|
||||
->fields([
|
||||
'value' => serialize(array_merge($existing_blocks, ['block.block.testfor2513534', 'block.block.secondtestfor2513534']))
|
||||
])
|
||||
->condition('collection', 'config.entity.key_store.block')
|
||||
->condition('name', 'theme:bartik')
|
||||
->execute();
|
|
@ -10,20 +10,20 @@ use Drupal\Core\Database\Database;
|
|||
$connection = Database::getConnection();
|
||||
|
||||
// Create the table.
|
||||
$connection->schema()->createTable('update_test_schema_table', array(
|
||||
'fields' => array(
|
||||
'a' => array(
|
||||
$connection->schema()->createTable('update_test_schema_table', [
|
||||
'fields' => [
|
||||
'a' => [
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'size' => 'normal',
|
||||
),
|
||||
'b' => array(
|
||||
],
|
||||
'b' => [
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'normal',
|
||||
),
|
||||
),
|
||||
));
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
// Set the schema version.
|
||||
$connection->merge('key_value')
|
||||
|
|
|
@ -18,15 +18,15 @@ $views_configs[] = Yaml::decode(file_get_contents(__DIR__ . '/drupal-8.views-ent
|
|||
|
||||
foreach ($views_configs as $views_config) {
|
||||
$connection->insert('config')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'collection',
|
||||
'name',
|
||||
'data',
|
||||
))
|
||||
->values(array(
|
||||
])
|
||||
->values([
|
||||
'collection' => '',
|
||||
'name' => 'views.view.' . $views_config['id'],
|
||||
'data' => serialize($views_config),
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class AcceptHeaderMatcher implements RouteFilterInterface {
|
|||
// Generates a list of Symfony formats matching the acceptable MIME types.
|
||||
// @todo replace by proper content negotiation library.
|
||||
$acceptable_mime_types = $request->getAcceptableContentTypes();
|
||||
$acceptable_formats = array_filter(array_map(array($request, 'getFormat'), $acceptable_mime_types));
|
||||
$acceptable_formats = array_filter(array_map([$request, 'getFormat'], $acceptable_mime_types));
|
||||
$primary_format = $request->getRequestFormat();
|
||||
|
||||
foreach ($collection as $name => $route) {
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\accept_header_routing_teste\Unit\Routing;
|
||||
|
||||
use Drupal\accept_header_routing_test\Routing\AcceptHeaderMatcher;
|
||||
use Drupal\Tests\Core\Routing\RoutingFixtures;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Confirm that the mime types partial matcher is functioning properly.
|
||||
*
|
||||
* @group Routing
|
||||
*/
|
||||
class AcceptHeaderMatcherTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* A collection of shared fixture data for tests.
|
||||
*
|
||||
* @var \Drupal\Tests\Core\Routing\RoutingFixtures
|
||||
*/
|
||||
protected $fixtures;
|
||||
|
||||
/**
|
||||
* The matcher object that is going to be tested.
|
||||
*
|
||||
* @var \Drupal\accept_header_routing_test\Routing\AcceptHeaderMatcher
|
||||
*/
|
||||
protected $matcher;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->fixtures = new RoutingFixtures();
|
||||
$this->matcher = new AcceptHeaderMatcher();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides data for the Accept header filtering test.
|
||||
*
|
||||
* @see Drupal\Tests\Core\Routing\AcceptHeaderMatcherTest::testAcceptFiltering()
|
||||
*/
|
||||
public function acceptFilterProvider() {
|
||||
return [
|
||||
// Check that JSON routes get filtered and prioritized correctly.
|
||||
['application/json, text/xml;q=0.9', 'json', 'route_c', 'route_e'],
|
||||
// Tests a JSON request with alternative JSON MIME type Accept header.
|
||||
['application/x-json, text/xml;q=0.9', 'json', 'route_c', 'route_e'],
|
||||
// Tests a standard HTML request.
|
||||
['text/html, text/xml;q=0.9', 'html', 'route_e', 'route_c'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that requests using Accept headers get filtered correctly.
|
||||
*
|
||||
* @param string $accept_header
|
||||
* The HTTP Accept header value of the request.
|
||||
* @param string $format
|
||||
* The request format.
|
||||
* @param string $included_route
|
||||
* The route name that should survive the filter and be ranked first.
|
||||
* @param string $excluded_route
|
||||
* The route name that should be filtered out during matching.
|
||||
*
|
||||
* @dataProvider acceptFilterProvider
|
||||
*/
|
||||
public function testAcceptFiltering($accept_header, $format, $included_route, $excluded_route) {
|
||||
$collection = $this->fixtures->sampleRouteCollection();
|
||||
|
||||
$request = Request::create('path/two', 'GET');
|
||||
$request->headers->set('Accept', $accept_header);
|
||||
$request->setRequestFormat($format);
|
||||
$routes = $this->matcher->filter($collection, $request);
|
||||
$this->assertEquals(count($routes), 4, 'The correct number of routes was found.');
|
||||
$this->assertNotNull($routes->get($included_route), "Route $included_route was found when matching $accept_header.");
|
||||
$this->assertNull($routes->get($excluded_route), "Route $excluded_route was not found when matching $accept_header.");
|
||||
foreach ($routes as $name => $route) {
|
||||
$this->assertEquals($name, $included_route, "Route $included_route is the first one in the collection when matching $accept_header.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms that the AcceptHeaderMatcher throws an exception for no-route.
|
||||
*
|
||||
* @expectedException \Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException
|
||||
* @expectedExceptionMessage No route found for the specified formats application/json text/xml.
|
||||
*/
|
||||
public function testNoRouteFound() {
|
||||
// Remove the sample routes that would match any method.
|
||||
$routes = $this->fixtures->sampleRouteCollection();
|
||||
$routes->remove('route_a');
|
||||
$routes->remove('route_b');
|
||||
$routes->remove('route_c');
|
||||
$routes->remove('route_d');
|
||||
|
||||
$request = Request::create('path/two', 'GET');
|
||||
$request->headers->set('Accept', 'application/json, text/xml;q=0.9');
|
||||
$request->setRequestFormat('json');
|
||||
$this->matcher->filter($routes, $request);
|
||||
$this->matcher->filter($routes, $request);
|
||||
$this->fail('No exception was thrown.');
|
||||
}
|
||||
|
||||
}
|
|
@ -89,7 +89,7 @@ function ajax_forms_test_advanced_commands_css_callback($form, FormStateInterfac
|
|||
$color = 'blue';
|
||||
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new CssCommand($selector, array('background-color' => $color)));
|
||||
$response->addCommand(new CssCommand($selector, ['background-color' => $color]));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ function ajax_forms_test_advanced_commands_data_callback($form, FormStateInterfa
|
|||
*/
|
||||
function ajax_forms_test_advanced_commands_invoke_callback($form, FormStateInterface $form_state) {
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new InvokeCommand('#invoke_div', 'addClass', array('error')));
|
||||
$response->addCommand(new InvokeCommand('#invoke_div', 'addClass', ['error']));
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ function ajax_forms_test_advanced_commands_add_css_callback($form, FormStateInte
|
|||
*/
|
||||
function ajax_forms_test_validation_form_callback($form, FormStateInterface $form_state) {
|
||||
drupal_set_message("ajax_forms_test_validation_form_callback invoked");
|
||||
drupal_set_message(t("Callback: drivertext=%drivertext, spare_required_field=%spare_required_field", array('%drivertext' => $form_state->getValue('drivertext'), '%spare_required_field' => $form_state->getValue('spare_required_field'))));
|
||||
drupal_set_message(t("Callback: drivertext=%drivertext, spare_required_field=%spare_required_field", ['%drivertext' => $form_state->getValue('drivertext'), '%spare_required_field' => $form_state->getValue('spare_required_field')]));
|
||||
return ['#markup' => '<div id="message_area">ajax_forms_test_validation_form_callback at ' . date('c') . '</div>'];
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ function ajax_forms_test_validation_form_callback($form, FormStateInterface $for
|
|||
*/
|
||||
function ajax_forms_test_validation_number_form_callback($form, FormStateInterface $form_state) {
|
||||
drupal_set_message("ajax_forms_test_validation_number_form_callback invoked");
|
||||
drupal_set_message(t("Callback: drivernumber=%drivernumber, spare_required_field=%spare_required_field", array('%drivernumber' => $form_state->getValue('drivernumber'), '%spare_required_field' => $form_state->getValue('spare_required_field'))));
|
||||
drupal_set_message(t("Callback: drivernumber=%drivernumber, spare_required_field=%spare_required_field", ['%drivernumber' => $form_state->getValue('drivernumber'), '%spare_required_field' => $form_state->getValue('spare_required_field')]));
|
||||
return ['#markup' => '<div id="message_area_number">ajax_forms_test_validation_number_form_callback at ' . date('c') . '</div>'];
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ class Callbacks {
|
|||
/**
|
||||
* Ajax callback triggered by select.
|
||||
*/
|
||||
function selectCallback($form, FormStateInterface $form_state) {
|
||||
public function selectCallback($form, FormStateInterface $form_state) {
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new HtmlCommand('#ajax_selected_color', $form_state->getValue('select')));
|
||||
$response->addCommand(new DataCommand('#ajax_selected_color', 'form_state_value_select', $form_state->getValue('select')));
|
||||
|
@ -25,7 +25,7 @@ class Callbacks {
|
|||
/**
|
||||
* Ajax callback triggered by checkbox.
|
||||
*/
|
||||
function checkboxCallback($form, FormStateInterface $form_state) {
|
||||
public function checkboxCallback($form, FormStateInterface $form_state) {
|
||||
$response = new AjaxResponse();
|
||||
$response->addCommand(new HtmlCommand('#ajax_checkbox_value', (int) $form_state->getValue('checkbox')));
|
||||
$response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox')));
|
||||
|
@ -35,7 +35,7 @@ class Callbacks {
|
|||
/**
|
||||
* Ajax callback triggered by the checkbox in a #group.
|
||||
*/
|
||||
function checkboxGroupCallback($form, FormStateInterface $form_state) {
|
||||
public function checkboxGroupCallback($form, FormStateInterface $form_state) {
|
||||
return $form['checkbox_in_group_wrapper'];
|
||||
}
|
||||
|
||||
|
|
|
@ -21,178 +21,178 @@ class AjaxFormsTestCommandsForm extends FormBase {
|
|||
* {@inheritdoc}.
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form = array();
|
||||
$form = [];
|
||||
|
||||
// Shows the 'after' command with a callback generating commands.
|
||||
$form['after_command_example'] = array(
|
||||
$form['after_command_example'] = [
|
||||
'#value' => $this->t("AJAX 'After': Click to put something after the div"),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_after_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="after_div">Something can be inserted after this</div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the 'alert' command.
|
||||
$form['alert_command_example'] = array(
|
||||
$form['alert_command_example'] = [
|
||||
'#value' => $this->t("AJAX 'Alert': Click to alert"),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_alert_callback',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Shows the 'append' command.
|
||||
$form['append_command_example'] = array(
|
||||
$form['append_command_example'] = [
|
||||
'#value' => $this->t("AJAX 'Append': Click to append something"),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_append_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="append_div">Append inside this div</div>',
|
||||
);
|
||||
];
|
||||
|
||||
|
||||
// Shows the 'before' command.
|
||||
$form['before_command_example'] = array(
|
||||
$form['before_command_example'] = [
|
||||
'#value' => $this->t("AJAX 'before': Click to put something before the div"),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_before_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="before_div">Insert something before this.</div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the 'changed' command without asterisk.
|
||||
$form['changed_command_example'] = array(
|
||||
$form['changed_command_example'] = [
|
||||
'#value' => $this->t("AJAX changed: Click to mark div changed."),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_changed_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="changed_div"> <div id="changed_div_mark_this">This div can be marked as changed or not.</div></div>',
|
||||
);
|
||||
];
|
||||
// Shows the 'changed' command adding the asterisk.
|
||||
$form['changed_command_asterisk_example'] = array(
|
||||
$form['changed_command_asterisk_example'] = [
|
||||
'#value' => $this->t("AJAX changed: Click to mark div changed with asterisk."),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_changed_asterisk_callback',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Shows the Ajax 'css' command.
|
||||
$form['css_command_example'] = array(
|
||||
$form['css_command_example'] = [
|
||||
'#value' => $this->t("Set the '#box' div to be blue."),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_css_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="css_div" style="height: 50px; width: 50px; border: 1px solid black"> box</div>',
|
||||
);
|
||||
];
|
||||
|
||||
|
||||
// Shows the Ajax 'data' command. But there is no use of this information,
|
||||
// as this would require a javascript client to use the data.
|
||||
$form['data_command_example'] = array(
|
||||
$form['data_command_example'] = [
|
||||
'#value' => $this->t("AJAX data command: Issue command."),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_data_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="data_div">Data attached to this div.</div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the Ajax 'invoke' command.
|
||||
$form['invoke_command_example'] = array(
|
||||
$form['invoke_command_example'] = [
|
||||
'#value' => $this->t("AJAX invoke command: Invoke addClass() method."),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_invoke_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="invoke_div">Original contents</div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the Ajax 'html' command.
|
||||
$form['html_command_example'] = array(
|
||||
$form['html_command_example'] = [
|
||||
'#value' => $this->t("AJAX html: Replace the HTML in a selector."),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_html_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="html_div">Original contents</div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the Ajax 'insert' command.
|
||||
$form['insert_command_example'] = array(
|
||||
$form['insert_command_example'] = [
|
||||
'#value' => $this->t("AJAX insert: Let client insert based on #ajax['method']."),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_insert_callback',
|
||||
'method' => 'prepend',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="insert_div">Original contents</div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the Ajax 'prepend' command.
|
||||
$form['prepend_command_example'] = array(
|
||||
$form['prepend_command_example'] = [
|
||||
'#value' => $this->t("AJAX 'prepend': Click to prepend something"),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_prepend_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="prepend_div">Something will be prepended to this div. </div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the Ajax 'remove' command.
|
||||
$form['remove_command_example'] = array(
|
||||
$form['remove_command_example'] = [
|
||||
'#value' => $this->t("AJAX 'remove': Click to remove text"),
|
||||
'#type' => 'submit',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_remove_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="remove_div"><div id="remove_text">text to be removed</div></div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Shows the Ajax 'restripe' command.
|
||||
$form['restripe_command_example'] = array(
|
||||
$form['restripe_command_example'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t("AJAX 'restripe' command"),
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_restripe_callback',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="restripe_div">
|
||||
<table id="restripe_table" style="border: 1px solid black" >
|
||||
<tr id="table-first"><td>first row</td></tr>
|
||||
<tr ><td>second row</td></tr>
|
||||
</table>
|
||||
</div>',
|
||||
);
|
||||
];
|
||||
|
||||
// Demonstrates the Ajax 'settings' command. The 'settings' command has
|
||||
// nothing visual to "show", but it can be tested via SimpleTest and via
|
||||
// Firebug.
|
||||
$form['settings_command_example'] = array(
|
||||
$form['settings_command_example'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t("AJAX 'settings' command"),
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_settings_callback',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Shows the Ajax 'add_css' command.
|
||||
$form['add_css_command_example'] = array(
|
||||
$form['add_css_command_example'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t("AJAX 'add_css' command"),
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_advanced_commands_add_css_callback',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
$form['submit'] = array(
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Submit'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -26,20 +26,20 @@ class AjaxFormsTestLazyLoadForm extends FormBase {
|
|||
// command to ensure that the 'currentPath' setting is not part
|
||||
// of the Ajax response.
|
||||
$form['#attached']['drupalSettings']['test'] = 'currentPathUpdate';
|
||||
$form['add_files'] = array(
|
||||
$form['add_files'] = [
|
||||
'#title' => $this->t('Add files'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => FALSE,
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Submit'),
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'wrapper' => 'ajax-forms-test-lazy-load-ajax-wrapper',
|
||||
'callback' => 'ajax_forms_test_lazy_load_form_ajax',
|
||||
),
|
||||
],
|
||||
'#prefix' => '<div id="ajax-forms-test-lazy-load-ajax-wrapper"></div>',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -24,47 +24,47 @@ class AjaxFormsTestSimpleForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$object = new Callbacks();
|
||||
|
||||
$form = array();
|
||||
$form['select'] = array(
|
||||
$form = [];
|
||||
$form['select'] = [
|
||||
'#title' => $this->t('Color'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'red' => 'red',
|
||||
'green' => 'green',
|
||||
'blue' => 'blue'),
|
||||
'#ajax' => array(
|
||||
'callback' => array($object, 'selectCallback'),
|
||||
),
|
||||
'blue' => 'blue'],
|
||||
'#ajax' => [
|
||||
'callback' => [$object, 'selectCallback'],
|
||||
],
|
||||
'#suffix' => '<div id="ajax_selected_color">No color yet selected</div>',
|
||||
);
|
||||
];
|
||||
|
||||
$form['checkbox'] = array(
|
||||
$form['checkbox'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Test checkbox'),
|
||||
'#ajax' => array(
|
||||
'callback' => array($object, 'checkboxCallback'),
|
||||
),
|
||||
'#ajax' => [
|
||||
'callback' => [$object, 'checkboxCallback'],
|
||||
],
|
||||
'#suffix' => '<div id="ajax_checkbox_value">No action yet</div>',
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('submit'),
|
||||
);
|
||||
];
|
||||
|
||||
// This is for testing invalid callbacks that should return a 500 error in
|
||||
// \Drupal\Core\Form\FormAjaxResponseBuilderInterface::buildResponse().
|
||||
$invalid_callbacks = array(
|
||||
$invalid_callbacks = [
|
||||
'null' => NULL,
|
||||
'empty' => '',
|
||||
'nonexistent' => 'some_function_that_does_not_exist',
|
||||
);
|
||||
];
|
||||
foreach ($invalid_callbacks as $key => $value) {
|
||||
$form['select_' . $key . '_callback'] = array(
|
||||
$form['select_' . $key . '_callback'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => $this->t('Test %key callbacks', array('%key' => $key)),
|
||||
'#options' => array('red' => 'red'),
|
||||
'#ajax' => array('callback' => $value),
|
||||
);
|
||||
'#title' => $this->t('Test %key callbacks', ['%key' => $key]),
|
||||
'#options' => ['red' => 'red'],
|
||||
'#ajax' => ['callback' => $value],
|
||||
];
|
||||
}
|
||||
|
||||
$form['test_group'] = [
|
||||
|
|
|
@ -21,42 +21,42 @@ class AjaxFormsTestValidationForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['drivertext'] = array(
|
||||
$form['drivertext'] = [
|
||||
'#title' => $this->t('AJAX-enabled textfield.'),
|
||||
'#description' => $this->t("When this one AJAX-triggers and the spare required field is empty, you should not get an error."),
|
||||
'#type' => 'textfield',
|
||||
'#default_value' => $form_state->getValue('drivertext', ''),
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_validation_form_callback',
|
||||
'wrapper' => 'message_area',
|
||||
'method' => 'replace',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="message_area"></div>',
|
||||
);
|
||||
];
|
||||
|
||||
$form['drivernumber'] = array(
|
||||
$form['drivernumber'] = [
|
||||
'#title' => $this->t('AJAX-enabled number field.'),
|
||||
'#description' => $this->t("When this one AJAX-triggers and the spare required field is empty, you should not get an error."),
|
||||
'#type' => 'number',
|
||||
'#default_value' => $form_state->getValue('drivernumber', ''),
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => 'ajax_forms_test_validation_number_form_callback',
|
||||
'wrapper' => 'message_area_number',
|
||||
'method' => 'replace',
|
||||
),
|
||||
],
|
||||
'#suffix' => '<div id="message_area_number"></div>',
|
||||
);
|
||||
];
|
||||
|
||||
$form['spare_required_field'] = array(
|
||||
$form['spare_required_field'] = [
|
||||
'#title' => $this->t("Spare Required Field"),
|
||||
'#type' => 'textfield',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['submit'] = array(
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Submit'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -22,22 +22,22 @@ class AjaxTestController {
|
|||
*/
|
||||
public static function dialogContents() {
|
||||
// This is a regular render array; the keys do not have special meaning.
|
||||
$content = array(
|
||||
$content = [
|
||||
'#title' => '<em>AJAX Dialog & contents</em>',
|
||||
'content' => array(
|
||||
'content' => [
|
||||
'#markup' => 'Example message',
|
||||
),
|
||||
'cancel' => array(
|
||||
],
|
||||
'cancel' => [
|
||||
'#type' => 'link',
|
||||
'#title' => 'Cancel',
|
||||
'#url' => Url::fromRoute('<front>'),
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
// This is a special class to which JavaScript assigns dialog closing
|
||||
// behavior.
|
||||
'class' => array('dialog-cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
'class' => ['dialog-cancel'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
@ -111,88 +111,88 @@ class AjaxTestController {
|
|||
public function dialog() {
|
||||
// Add two wrapper elements for testing non-modal dialogs. Modal dialogs use
|
||||
// the global drupal-modal wrapper by default.
|
||||
$build['dialog_wrappers'] = array('#markup' => '<div id="ajax-test-dialog-wrapper-1"></div><div id="ajax-test-dialog-wrapper-2"></div>');
|
||||
$build['dialog_wrappers'] = ['#markup' => '<div id="ajax-test-dialog-wrapper-1"></div><div id="ajax-test-dialog-wrapper-2"></div>'];
|
||||
|
||||
// Dialog behavior applied to a button.
|
||||
$build['form'] = \Drupal::formBuilder()->getForm('Drupal\ajax_test\Form\AjaxTestDialogForm');
|
||||
|
||||
// Dialog behavior applied to a #type => 'link'.
|
||||
$build['link'] = array(
|
||||
$build['link'] = [
|
||||
'#type' => 'link',
|
||||
'#title' => 'Link 1 (modal)',
|
||||
'#url' => Url::fromRoute('ajax_test.dialog_contents'),
|
||||
'#attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'#attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Dialog behavior applied to links rendered by links.html.twig.
|
||||
$build['links'] = array(
|
||||
$build['links'] = [
|
||||
'#theme' => 'links',
|
||||
'#links' => array(
|
||||
'link2' => array(
|
||||
'#links' => [
|
||||
'link2' => [
|
||||
'title' => 'Link 2 (modal)',
|
||||
'url' => Url::fromRoute('ajax_test.dialog_contents'),
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => json_encode(array(
|
||||
'data-dialog-options' => json_encode([
|
||||
'width' => 400,
|
||||
))
|
||||
),
|
||||
),
|
||||
'link3' => array(
|
||||
])
|
||||
],
|
||||
],
|
||||
'link3' => [
|
||||
'title' => 'Link 3 (non-modal)',
|
||||
'url' => Url::fromRoute('ajax_test.dialog_contents'),
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-options' => json_encode(array(
|
||||
'data-dialog-options' => json_encode([
|
||||
'target' => 'ajax-test-dialog-wrapper-1',
|
||||
'width' => 800,
|
||||
))
|
||||
),
|
||||
),
|
||||
'link4' => array(
|
||||
])
|
||||
],
|
||||
],
|
||||
'link4' => [
|
||||
'title' => 'Link 4 (close non-modal if open)',
|
||||
'url' => Url::fromRoute('ajax_test.dialog_close'),
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
),
|
||||
),
|
||||
'link5' => array(
|
||||
],
|
||||
],
|
||||
'link5' => [
|
||||
'title' => 'Link 5 (form)',
|
||||
'url' => Url::fromRoute('ajax_test.dialog_form'),
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
),
|
||||
),
|
||||
'link6' => array(
|
||||
],
|
||||
],
|
||||
'link6' => [
|
||||
'title' => 'Link 6 (entity form)',
|
||||
'url' => Url::fromRoute('contact.form_add'),
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'modal',
|
||||
'data-dialog-options' => json_encode(array(
|
||||
'data-dialog-options' => json_encode([
|
||||
'width' => 800,
|
||||
'height' => 500,
|
||||
))
|
||||
),
|
||||
),
|
||||
'link7' => array(
|
||||
])
|
||||
],
|
||||
],
|
||||
'link7' => [
|
||||
'title' => 'Link 7 (non-modal, no target)',
|
||||
'url' => Url::fromRoute('ajax_test.dialog_contents'),
|
||||
'attributes' => array(
|
||||
'class' => array('use-ajax'),
|
||||
'attributes' => [
|
||||
'class' => ['use-ajax'],
|
||||
'data-dialog-type' => 'dialog',
|
||||
'data-dialog-options' => json_encode(array(
|
||||
'data-dialog-options' => json_encode([
|
||||
'width' => 800,
|
||||
))
|
||||
),
|
||||
),
|
||||
])
|
||||
],
|
||||
],
|
||||
'link8' => [
|
||||
'title' => 'Link 8 (ajax)',
|
||||
'url' => Url::fromRoute('ajax_test.admin.theme'),
|
||||
|
@ -204,8 +204,8 @@ class AjaxTestController {
|
|||
]),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $build;
|
||||
}
|
||||
|
|
|
@ -28,25 +28,25 @@ class AjaxTestDialogForm extends FormBase {
|
|||
// In order to use WebTestBase::drupalPostAjaxForm() to POST from a link, we need
|
||||
// to have a dummy field we can set in WebTestBase::drupalPostForm() else it won't
|
||||
// submit anything.
|
||||
$form['textfield'] = array(
|
||||
$form['textfield'] = [
|
||||
'#type' => 'hidden'
|
||||
);
|
||||
$form['button1'] = array(
|
||||
];
|
||||
$form['button1'] = [
|
||||
'#type' => 'submit',
|
||||
'#name' => 'button1',
|
||||
'#value' => 'Button 1 (modal)',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => '::modal',
|
||||
),
|
||||
);
|
||||
$form['button2'] = array(
|
||||
],
|
||||
];
|
||||
$form['button2'] = [
|
||||
'#type' => 'submit',
|
||||
'#name' => 'button2',
|
||||
'#value' => 'Button 2 (non-modal)',
|
||||
'#ajax' => array(
|
||||
'#ajax' => [
|
||||
'callback' => '::nonModal',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -24,23 +24,23 @@ class AjaxTestForm extends FormBase {
|
|||
|
||||
$form['#action'] = \Drupal::url('ajax_test.dialog');
|
||||
|
||||
$form['description'] = array(
|
||||
$form['description'] = [
|
||||
'#markup' => '<p>' . $this->t("Ajax Form contents description.") . '</p>',
|
||||
);
|
||||
];
|
||||
|
||||
$form['actions'] = array(
|
||||
$form['actions'] = [
|
||||
'#type' => 'actions',
|
||||
);
|
||||
$form['actions']['submit'] = array(
|
||||
];
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Do it'),
|
||||
);
|
||||
$form['actions']['preview'] = array(
|
||||
];
|
||||
$form['actions']['preview'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => $this->t('Preview'),
|
||||
// No regular submit-handler. This form only works via JavaScript.
|
||||
'#submit' => array(),
|
||||
'#ajax' => array(
|
||||
'#submit' => [],
|
||||
'#ajax' => [
|
||||
// This means the ::preview() method on this class would be invoked in
|
||||
// case of a click event. However, since Drupal core's test runner only
|
||||
// is able to execute PHP, not JS, there is no point in actually
|
||||
|
@ -51,8 +51,8 @@ class AjaxTestForm extends FormBase {
|
|||
// we cannot meaningfully test it anyway.
|
||||
'callback' => '::preview',
|
||||
'event' => 'click',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,7 +100,7 @@ function _batch_test_finished_helper($batch_id, $success, $results, $operations)
|
|||
if (!$success) {
|
||||
// A fatal error occurred during the processing.
|
||||
$error_operation = reset($operations);
|
||||
$messages[] = t('An error occurred while processing @op with arguments:<br />@args', array('@op' => $error_operation[0], '@args' => print_r($error_operation[1], TRUE)));
|
||||
$messages[] = t('An error occurred while processing @op with arguments:<br />@args', ['@op' => $error_operation[0], '@args' => print_r($error_operation[1], TRUE)]);
|
||||
}
|
||||
|
||||
// Use item list template to render the messages.
|
||||
|
|
|
@ -20,11 +20,11 @@ function _batch_test_nested_drupal_form_submit_callback($value) {
|
|||
* Batch 0: Does nothing.
|
||||
*/
|
||||
function _batch_test_batch_0() {
|
||||
$batch = array(
|
||||
'operations' => array(),
|
||||
$batch = [
|
||||
'operations' => [],
|
||||
'finished' => '_batch_test_finished_0',
|
||||
'file' => drupal_get_path('module', 'batch_test') . '/batch_test.callbacks.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -38,15 +38,15 @@ function _batch_test_batch_1() {
|
|||
$total = 10;
|
||||
$sleep = (1000000 / $total) * 2;
|
||||
|
||||
$operations = array();
|
||||
$operations = [];
|
||||
for ($i = 1; $i <= $total; $i++) {
|
||||
$operations[] = array('_batch_test_callback_1', array($i, $sleep));
|
||||
$operations[] = ['_batch_test_callback_1', [$i, $sleep]];
|
||||
}
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'finished' => '_batch_test_finished_1',
|
||||
'file' => drupal_get_path('module', 'batch_test') . '/batch_test.callbacks.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -60,14 +60,14 @@ function _batch_test_batch_2() {
|
|||
$total = 10;
|
||||
$sleep = (1000000 / $total) * 2;
|
||||
|
||||
$operations = array(
|
||||
array('_batch_test_callback_2', array(1, $total, $sleep)),
|
||||
);
|
||||
$batch = array(
|
||||
$operations = [
|
||||
['_batch_test_callback_2', [1, $total, $sleep]],
|
||||
];
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'finished' => '_batch_test_finished_2',
|
||||
'file' => drupal_get_path('module', 'batch_test') . '/batch_test.callbacks.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -85,20 +85,20 @@ function _batch_test_batch_3() {
|
|||
$total = 10;
|
||||
$sleep = (1000000 / $total) * 2;
|
||||
|
||||
$operations = array();
|
||||
$operations = [];
|
||||
for ($i = 1; $i <= round($total / 2); $i++) {
|
||||
$operations[] = array('_batch_test_callback_1', array($i, $sleep));
|
||||
$operations[] = ['_batch_test_callback_1', [$i, $sleep]];
|
||||
}
|
||||
$operations[] = array('_batch_test_callback_2', array(1, $total / 2, $sleep));
|
||||
$operations[] = ['_batch_test_callback_2', [1, $total / 2, $sleep]];
|
||||
for ($i = round($total / 2) + 1; $i <= $total; $i++) {
|
||||
$operations[] = array('_batch_test_callback_1', array($i, $sleep));
|
||||
$operations[] = ['_batch_test_callback_1', [$i, $sleep]];
|
||||
}
|
||||
$operations[] = array('_batch_test_callback_2', array(6, $total / 2, $sleep));
|
||||
$batch = array(
|
||||
$operations[] = ['_batch_test_callback_2', [6, $total / 2, $sleep]];
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'finished' => '_batch_test_finished_3',
|
||||
'file' => drupal_get_path('module', 'batch_test') . '/batch_test.callbacks.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -115,19 +115,19 @@ function _batch_test_batch_4() {
|
|||
$total = 10;
|
||||
$sleep = (1000000 / $total) * 2;
|
||||
|
||||
$operations = array();
|
||||
$operations = [];
|
||||
for ($i = 1; $i <= round($total / 2); $i++) {
|
||||
$operations[] = array('_batch_test_callback_1', array($i, $sleep));
|
||||
$operations[] = ['_batch_test_callback_1', [$i, $sleep]];
|
||||
}
|
||||
$operations[] = array('_batch_test_nested_batch_callback', array());
|
||||
$operations[] = ['_batch_test_nested_batch_callback', []];
|
||||
for ($i = round($total / 2) + 1; $i <= $total; $i++) {
|
||||
$operations[] = array('_batch_test_callback_1', array($i, $sleep));
|
||||
$operations[] = ['_batch_test_callback_1', [$i, $sleep]];
|
||||
}
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'finished' => '_batch_test_finished_4',
|
||||
'file' => drupal_get_path('module', 'batch_test') . '/batch_test.callbacks.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
@ -141,15 +141,15 @@ function _batch_test_batch_5() {
|
|||
$total = 10;
|
||||
$sleep = (1000000 / $total) * 2;
|
||||
|
||||
$operations = array();
|
||||
$operations = [];
|
||||
for ($i = 1; $i <= $total; $i++) {
|
||||
$operations[] = array('_batch_test_callback_5', array($i, $sleep));
|
||||
$operations[] = ['_batch_test_callback_5', [$i, $sleep]];
|
||||
}
|
||||
$batch = array(
|
||||
$batch = [
|
||||
'operations' => $operations,
|
||||
'finished' => '_batch_test_finished_5',
|
||||
'file' => drupal_get_path('module', 'batch_test') . '/batch_test.callbacks.inc',
|
||||
);
|
||||
];
|
||||
return $batch;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@ class BatchTestController {
|
|||
* Render array containing success message.
|
||||
*/
|
||||
public function testRedirect() {
|
||||
return array(
|
||||
'success' => array(
|
||||
return [
|
||||
'success' => [
|
||||
'#markup' => 'Redirection successful.',
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,9 +47,9 @@ class BatchTestController {
|
|||
*/
|
||||
public function testNestedDrupalFormSubmit($value = 1) {
|
||||
// Set the batch and process it.
|
||||
$batch['operations'] = array(
|
||||
array('_batch_test_nested_drupal_form_submit_callback', array($value)),
|
||||
);
|
||||
$batch['operations'] = [
|
||||
['_batch_test_nested_drupal_form_submit_callback', [$value]],
|
||||
];
|
||||
batch_set($batch);
|
||||
return batch_process('batch-test/redirect');
|
||||
}
|
||||
|
@ -95,16 +95,16 @@ class BatchTestController {
|
|||
* @return array
|
||||
* Render array containing markup.
|
||||
*/
|
||||
function testProgrammatic($value = 1) {
|
||||
public function testProgrammatic($value = 1) {
|
||||
$form_state = (new FormState())->setValues([
|
||||
'value' => $value,
|
||||
]);
|
||||
\Drupal::formBuilder()->submitForm('Drupal\batch_test\Form\BatchTestChainedForm', $form_state);
|
||||
return array(
|
||||
'success' => array(
|
||||
return [
|
||||
'success' => [
|
||||
'#markup' => 'Got out of a programmatic batched form.',
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -115,11 +115,11 @@ class BatchTestController {
|
|||
*/
|
||||
public function testThemeBatch() {
|
||||
batch_test_stack(NULL, TRUE);
|
||||
$batch = array(
|
||||
'operations' => array(
|
||||
array('_batch_test_theme_callback', array()),
|
||||
),
|
||||
);
|
||||
$batch = [
|
||||
'operations' => [
|
||||
['_batch_test_theme_callback', []],
|
||||
],
|
||||
];
|
||||
batch_set($batch);
|
||||
return batch_process('batch-test/redirect');
|
||||
}
|
||||
|
|
|
@ -23,21 +23,21 @@ class BatchTestChainedForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
// This value is used to test that $form_state persists through batched
|
||||
// submit handlers.
|
||||
$form['value'] = array(
|
||||
$form['value'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Value',
|
||||
'#default_value' => 1,
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Submit',
|
||||
);
|
||||
$form['#submit'] = array(
|
||||
];
|
||||
$form['#submit'] = [
|
||||
'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit1',
|
||||
'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit2',
|
||||
'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit3',
|
||||
'Drupal\batch_test\Form\BatchTestChainedForm::batchTestChainedFormSubmit4',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,14 +21,14 @@ class BatchTestMockForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['test_value'] = array(
|
||||
$form['test_value'] = [
|
||||
'#title' => t('Test value'),
|
||||
'#type' => 'textfield',
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -27,13 +27,13 @@ class BatchTestMultiStepForm extends FormBase {
|
|||
$form_state->set('step', $step);
|
||||
}
|
||||
|
||||
$form['step_display'] = array(
|
||||
$form['step_display'] = [
|
||||
'#markup' => 'step ' . $step . '<br/>',
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Submit',
|
||||
);
|
||||
];
|
||||
|
||||
// This is a POST form with multiple steps that does not transition from one
|
||||
// step to the next via POST requests, but via GET requests, because it uses
|
||||
|
|
|
@ -21,21 +21,21 @@ class BatchTestSimpleForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['batch'] = array(
|
||||
$form['batch'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => 'Choose batch',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'batch_0' => 'batch 0',
|
||||
'batch_1' => 'batch 1',
|
||||
'batch_2' => 'batch 2',
|
||||
'batch_3' => 'batch 3',
|
||||
'batch_4' => 'batch 4',
|
||||
),
|
||||
);
|
||||
$form['submit'] = array(
|
||||
],
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Submit',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -114,18 +114,18 @@ function common_test_module_implements_alter(&$implementations, $hook) {
|
|||
* Implements hook_theme().
|
||||
*/
|
||||
function common_test_theme() {
|
||||
return array(
|
||||
'common_test_foo' => array(
|
||||
'variables' => array('foo' => 'foo', 'bar' => 'bar'),
|
||||
),
|
||||
'common_test_render_element' => array(
|
||||
return [
|
||||
'common_test_foo' => [
|
||||
'variables' => ['foo' => 'foo', 'bar' => 'bar'],
|
||||
],
|
||||
'common_test_render_element' => [
|
||||
'render element' => 'foo',
|
||||
),
|
||||
'common_test_empty' => array(
|
||||
'variables' => array('foo' => 'foo'),
|
||||
],
|
||||
'common_test_empty' => [
|
||||
'variables' => ['foo' => 'foo'],
|
||||
'function' => 'theme_common_test_empty',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,40 +18,40 @@ class CommonTestController {
|
|||
* generator.
|
||||
*/
|
||||
public function typeLinkActiveClass() {
|
||||
return array(
|
||||
'no_query' => array(
|
||||
return [
|
||||
'no_query' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link with no query string'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
'with_query' => array(
|
||||
],
|
||||
],
|
||||
'with_query' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link with a query string'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'query' => array(
|
||||
'#options' => [
|
||||
'query' => [
|
||||
'foo' => 'bar',
|
||||
'one' => 'two',
|
||||
),
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
'with_query_reversed' => array(
|
||||
],
|
||||
],
|
||||
'with_query_reversed' => [
|
||||
'#type' => 'link',
|
||||
'#title' => t('Link with the same query string in reverse order'),
|
||||
'#url' => Url::fromRoute('<current>'),
|
||||
'#options' => array(
|
||||
'query' => array(
|
||||
'#options' => [
|
||||
'query' => [
|
||||
'one' => 'two',
|
||||
'foo' => 'bar',
|
||||
),
|
||||
],
|
||||
'set_active_class' => TRUE,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -61,18 +61,18 @@ class CommonTestController {
|
|||
* An empty string.
|
||||
*/
|
||||
public function jsAndCssQuerystring() {
|
||||
$attached = array(
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
$attached = [
|
||||
'#attached' => [
|
||||
'library' => [
|
||||
'node/drupal.node',
|
||||
),
|
||||
'css' => array(
|
||||
drupal_get_path('module', 'node') . '/css/node.admin.css' => array(),
|
||||
],
|
||||
'css' => [
|
||||
drupal_get_path('module', 'node') . '/css/node.admin.css' => [],
|
||||
// A relative URI may have a query string.
|
||||
'/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2' => array(),
|
||||
),
|
||||
),
|
||||
);
|
||||
'/' . drupal_get_path('module', 'node') . '/node-fake.css?arg1=value1&arg2=value2' => [],
|
||||
],
|
||||
],
|
||||
];
|
||||
return \Drupal::service('renderer')->renderRoot($attached);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,10 +39,10 @@ class FormController implements FormInterface {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form = $this->condition->buildConfigurationForm($form, $form_state);
|
||||
$form['actions']['submit'] = array(
|
||||
$form['actions']['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,281 +14,281 @@
|
|||
* like any other, not directly in the test file.
|
||||
*/
|
||||
function database_test_schema() {
|
||||
$schema['test'] = array(
|
||||
$schema['test'] = [
|
||||
'description' => 'Basic test table for the database unit tests.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
],
|
||||
'name' => [
|
||||
'description' => "A person's name",
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'binary' => TRUE,
|
||||
),
|
||||
'age' => array(
|
||||
],
|
||||
'age' => [
|
||||
'description' => "The person's age",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'job' => array(
|
||||
],
|
||||
'job' => [
|
||||
'description' => "The person's job",
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => 'Undefined',
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
'unique keys' => array(
|
||||
'name' => array('name')
|
||||
),
|
||||
'indexes' => array(
|
||||
'ages' => array('age'),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
'unique keys' => [
|
||||
'name' => ['name']
|
||||
],
|
||||
'indexes' => [
|
||||
'ages' => ['age'],
|
||||
],
|
||||
];
|
||||
|
||||
// This is an alternate version of the same table that is structured the same
|
||||
// but has a non-serial Primary Key.
|
||||
$schema['test_people'] = array(
|
||||
$schema['test_people'] = [
|
||||
'description' => 'A duplicate version of the test table, used for additional tests.',
|
||||
'fields' => array(
|
||||
'name' => array(
|
||||
'fields' => [
|
||||
'name' => [
|
||||
'description' => "A person's name",
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'age' => array(
|
||||
],
|
||||
'age' => [
|
||||
'description' => "The person's age",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'job' => array(
|
||||
],
|
||||
'job' => [
|
||||
'description' => "The person's job",
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
'primary key' => array('job'),
|
||||
'indexes' => array(
|
||||
'ages' => array('age'),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['job'],
|
||||
'indexes' => [
|
||||
'ages' => ['age'],
|
||||
],
|
||||
];
|
||||
|
||||
$schema['test_people_copy'] = array(
|
||||
$schema['test_people_copy'] = [
|
||||
'description' => 'A duplicate version of the test_people table, used for additional tests.',
|
||||
'fields' => array(
|
||||
'name' => array(
|
||||
'fields' => [
|
||||
'name' => [
|
||||
'description' => "A person's name",
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'age' => array(
|
||||
],
|
||||
'age' => [
|
||||
'description' => "The person's age",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'job' => array(
|
||||
],
|
||||
'job' => [
|
||||
'description' => "The person's job",
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
'primary key' => array('job'),
|
||||
'indexes' => array(
|
||||
'ages' => array('age'),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['job'],
|
||||
'indexes' => [
|
||||
'ages' => ['age'],
|
||||
],
|
||||
];
|
||||
|
||||
$schema['test_one_blob'] = array(
|
||||
$schema['test_one_blob'] = [
|
||||
'description' => 'A simple table including a BLOB field for testing BLOB behavior.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'description' => 'Simple unique ID.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'blob1' => array(
|
||||
],
|
||||
'blob1' => [
|
||||
'description' => 'A BLOB field.',
|
||||
'type' => 'blob',
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
];
|
||||
|
||||
$schema['test_two_blobs'] = array(
|
||||
$schema['test_two_blobs'] = [
|
||||
'description' => 'A simple test table with two BLOB fields.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'description' => 'Simple unique ID.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'blob1' => array(
|
||||
],
|
||||
'blob1' => [
|
||||
'description' => 'A dummy BLOB field.',
|
||||
'type' => 'blob',
|
||||
),
|
||||
'blob2' => array(
|
||||
],
|
||||
'blob2' => [
|
||||
'description' => 'A second BLOB field.',
|
||||
'type' => 'blob'
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
];
|
||||
|
||||
$schema['test_task'] = array(
|
||||
$schema['test_task'] = [
|
||||
'description' => 'A task list for people in the test table.',
|
||||
'fields' => array(
|
||||
'tid' => array(
|
||||
'fields' => [
|
||||
'tid' => [
|
||||
'description' => 'Task ID, primary key.',
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'pid' => array(
|
||||
],
|
||||
'pid' => [
|
||||
'description' => 'The {test_people}.pid, foreign key for the test table.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'task' => array(
|
||||
],
|
||||
'task' => [
|
||||
'description' => 'The task to be completed.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'priority' => array(
|
||||
],
|
||||
'priority' => [
|
||||
'description' => 'The priority of the task.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'primary key' => array('tid'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['tid'],
|
||||
];
|
||||
|
||||
$schema['test_null'] = array(
|
||||
$schema['test_null'] = [
|
||||
'description' => 'Basic test table for NULL value handling.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
],
|
||||
'name' => [
|
||||
'description' => "A person's name.",
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
),
|
||||
'age' => array(
|
||||
],
|
||||
'age' => [
|
||||
'description' => "The person's age.",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => FALSE,
|
||||
'default' => 0),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
'unique keys' => array(
|
||||
'name' => array('name')
|
||||
),
|
||||
'indexes' => array(
|
||||
'ages' => array('age'),
|
||||
),
|
||||
);
|
||||
'default' => 0],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
'unique keys' => [
|
||||
'name' => ['name']
|
||||
],
|
||||
'indexes' => [
|
||||
'ages' => ['age'],
|
||||
],
|
||||
];
|
||||
|
||||
$schema['test_serialized'] = array(
|
||||
$schema['test_serialized'] = [
|
||||
'description' => 'Basic test table for NULL value handling.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'name' => array(
|
||||
],
|
||||
'name' => [
|
||||
'description' => "A person's name.",
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => FALSE,
|
||||
'default' => '',
|
||||
),
|
||||
'info' => array(
|
||||
],
|
||||
'info' => [
|
||||
'description' => "The person's data in serialized form.",
|
||||
'type' => 'blob',
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
'unique keys' => array(
|
||||
'name' => array('name')
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
'unique keys' => [
|
||||
'name' => ['name']
|
||||
],
|
||||
];
|
||||
|
||||
$schema['test_composite_primary'] = array(
|
||||
$schema['test_composite_primary'] = [
|
||||
'description' => 'Basic test table with a composite primary key',
|
||||
'fields' => array(
|
||||
'name' => array(
|
||||
'fields' => [
|
||||
'name' => [
|
||||
'description' => "A person's name",
|
||||
'type' => 'varchar',
|
||||
'length' => 50,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'binary' => TRUE,
|
||||
),
|
||||
'age' => array(
|
||||
],
|
||||
'age' => [
|
||||
'description' => "The person's age",
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'job' => array(
|
||||
],
|
||||
'job' => [
|
||||
'description' => "The person's job",
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => 'Undefined',
|
||||
),
|
||||
),
|
||||
'primary key' => array('name', 'age'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['name', 'age'],
|
||||
];
|
||||
|
||||
$schema['test_special_columns'] = array(
|
||||
$schema['test_special_columns'] = [
|
||||
'description' => 'A simple test table with special column names.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'description' => 'Simple unique ID.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'offset' => array(
|
||||
],
|
||||
'offset' => [
|
||||
'description' => 'A column with preserved name.',
|
||||
'type' => 'text',
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
];
|
||||
|
||||
$schema['TEST_UPPERCASE'] = $schema['test'];
|
||||
|
||||
|
|
|
@ -19,11 +19,11 @@ class DatabaseTestController {
|
|||
* @return \Symfony\Component\HttpFoundation\JsonResponse
|
||||
*/
|
||||
public function dbQueryTemporary() {
|
||||
$table_name = db_query_temporary('SELECT age FROM {test}', array());
|
||||
return new JsonResponse(array(
|
||||
$table_name = db_query_temporary('SELECT age FROM {test}', []);
|
||||
return new JsonResponse([
|
||||
'table_name' => $table_name,
|
||||
'row_count' => db_select($table_name)->countQuery()->execute()->fetchField(),
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,7 +37,7 @@ class DatabaseTestController {
|
|||
public function pagerQueryEven($limit) {
|
||||
$query = db_select('test', 't');
|
||||
$query
|
||||
->fields('t', array('name'))
|
||||
->fields('t', ['name'])
|
||||
->orderBy('age');
|
||||
|
||||
// This should result in 2 pages of results.
|
||||
|
@ -47,9 +47,9 @@ class DatabaseTestController {
|
|||
|
||||
$names = $query->execute()->fetchCol();
|
||||
|
||||
return new JsonResponse(array(
|
||||
return new JsonResponse([
|
||||
'names' => $names,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +63,7 @@ class DatabaseTestController {
|
|||
public function pagerQueryOdd($limit) {
|
||||
$query = db_select('test_task', 't');
|
||||
$query
|
||||
->fields('t', array('task'))
|
||||
->fields('t', ['task'])
|
||||
->orderBy('pid');
|
||||
|
||||
// This should result in 4 pages of results.
|
||||
|
@ -73,9 +73,9 @@ class DatabaseTestController {
|
|||
|
||||
$names = $query->execute()->fetchCol();
|
||||
|
||||
return new JsonResponse(array(
|
||||
return new JsonResponse([
|
||||
'names' => $names,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,16 +87,16 @@ class DatabaseTestController {
|
|||
* @return \Symfony\Component\HttpFoundation\JsonResponse
|
||||
*/
|
||||
public function testTablesort() {
|
||||
$header = array(
|
||||
'tid' => array('data' => t('Task ID'), 'field' => 'tid', 'sort' => 'desc'),
|
||||
'pid' => array('data' => t('Person ID'), 'field' => 'pid'),
|
||||
'task' => array('data' => t('Task'), 'field' => 'task'),
|
||||
'priority' => array('data' => t('Priority'), 'field' => 'priority', ),
|
||||
);
|
||||
$header = [
|
||||
'tid' => ['data' => t('Task ID'), 'field' => 'tid', 'sort' => 'desc'],
|
||||
'pid' => ['data' => t('Person ID'), 'field' => 'pid'],
|
||||
'task' => ['data' => t('Task'), 'field' => 'task'],
|
||||
'priority' => ['data' => t('Priority'), 'field' => 'priority', ],
|
||||
];
|
||||
|
||||
$query = db_select('test_task', 't');
|
||||
$query
|
||||
->fields('t', array('tid', 'pid', 'task', 'priority'));
|
||||
->fields('t', ['tid', 'pid', 'task', 'priority']);
|
||||
|
||||
$query = $query
|
||||
->extend('Drupal\Core\Database\Query\TableSortExtender')
|
||||
|
@ -105,9 +105,9 @@ class DatabaseTestController {
|
|||
// We need all the results at once to check the sort.
|
||||
$tasks = $query->execute()->fetchAll();
|
||||
|
||||
return new JsonResponse(array(
|
||||
return new JsonResponse([
|
||||
'tasks' => $tasks,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -119,16 +119,16 @@ class DatabaseTestController {
|
|||
* @return \Symfony\Component\HttpFoundation\JsonResponse
|
||||
*/
|
||||
public function testTablesortFirst() {
|
||||
$header = array(
|
||||
'tid' => array('data' => t('Task ID'), 'field' => 'tid', 'sort' => 'desc'),
|
||||
'pid' => array('data' => t('Person ID'), 'field' => 'pid'),
|
||||
'task' => array('data' => t('Task'), 'field' => 'task'),
|
||||
'priority' => array('data' => t('Priority'), 'field' => 'priority', ),
|
||||
);
|
||||
$header = [
|
||||
'tid' => ['data' => t('Task ID'), 'field' => 'tid', 'sort' => 'desc'],
|
||||
'pid' => ['data' => t('Person ID'), 'field' => 'pid'],
|
||||
'task' => ['data' => t('Task'), 'field' => 'task'],
|
||||
'priority' => ['data' => t('Priority'), 'field' => 'priority', ],
|
||||
];
|
||||
|
||||
$query = db_select('test_task', 't');
|
||||
$query
|
||||
->fields('t', array('tid', 'pid', 'task', 'priority'));
|
||||
->fields('t', ['tid', 'pid', 'task', 'priority']);
|
||||
|
||||
$query = $query
|
||||
->extend('Drupal\Core\Database\Query\TableSortExtender')
|
||||
|
@ -138,9 +138,9 @@ class DatabaseTestController {
|
|||
// We need all the results at once to check the sort.
|
||||
$tasks = $query->execute()->fetchAll();
|
||||
|
||||
return new JsonResponse(array(
|
||||
return new JsonResponse([
|
||||
'tasks' => $tasks,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ class DatabaseTestForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$header = array(
|
||||
'username' => array('data' => t('Username'), 'field' => 'u.name'),
|
||||
'status' => array('data' => t('Status'), 'field' => 'u.status'),
|
||||
);
|
||||
$header = [
|
||||
'username' => ['data' => t('Username'), 'field' => 'u.name'],
|
||||
'status' => ['data' => t('Status'), 'field' => 'u.status'],
|
||||
];
|
||||
|
||||
$query = db_select('users_field_data', 'u');
|
||||
$query->condition('u.uid', 0, '<>');
|
||||
|
@ -38,7 +38,7 @@ class DatabaseTestForm extends FormBase {
|
|||
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
||||
->extend('Drupal\Core\Database\Query\TableSortExtender');
|
||||
$query
|
||||
->fields('u', array('uid'))
|
||||
->fields('u', ['uid'])
|
||||
->limit(50)
|
||||
->orderByHeader($header)
|
||||
->setCountQuery($count_query);
|
||||
|
@ -46,22 +46,22 @@ class DatabaseTestForm extends FormBase {
|
|||
->execute()
|
||||
->fetchCol();
|
||||
|
||||
$options = array();
|
||||
$options = [];
|
||||
|
||||
foreach (User::loadMultiple($uids) as $account) {
|
||||
$options[$account->id()] = array(
|
||||
'title' => array('data' => array('#title' => $account->getUsername())),
|
||||
$options[$account->id()] = [
|
||||
'title' => ['data' => ['#title' => $account->getUsername()]],
|
||||
'username' => $account->getUsername(),
|
||||
'status' => $account->isActive() ? t('active') : t('blocked'),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
$form['accounts'] = array(
|
||||
$form['accounts'] = [
|
||||
'#type' => 'tableselect',
|
||||
'#header' => $header,
|
||||
'#options' => $options,
|
||||
'#empty' => t('No people available.'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ class TestPageDisplayVariantSubscriber implements EventSubscriberInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = array('onSelectPageDisplayVariant');
|
||||
public static function getSubscribedEvents() {
|
||||
$events[RenderEvents::SELECT_PAGE_DISPLAY_VARIANT][] = ['onSelectPageDisplayVariant'];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class TestDomainObjectViewSubscriber implements EventSubscriberInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
public static function getSubscribedEvents() {
|
||||
$events[KernelEvents::VIEW][] = ['onViewTestDomainObject'];
|
||||
|
||||
return $events;
|
||||
|
|
|
@ -12,7 +12,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
|
|||
* Implements hook_entity_base_field_info().
|
||||
*/
|
||||
function entity_reference_test_entity_base_field_info(EntityTypeInterface $entity_type) {
|
||||
$fields = array();
|
||||
$fields = [];
|
||||
|
||||
if ($entity_type->id() === 'entity_test') {
|
||||
$fields['user_role'] = BaseFieldDefinition::create('entity_reference')
|
||||
|
@ -33,10 +33,10 @@ function entity_reference_test_entity_base_field_info_alter(&$fields, EntityType
|
|||
// Allow user_id field to use configurable widget.
|
||||
$fields['user_id']
|
||||
->setSetting('handler', 'default')
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 0,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: test_entity_reference_group_by_empty_relationships
|
||||
label: ''
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: entity_test
|
||||
base_field: id
|
||||
core: '8'
|
||||
display:
|
||||
default:
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
cache:
|
||||
type: tag
|
||||
exposed_form:
|
||||
type: basic
|
||||
query:
|
||||
type: views_query
|
||||
options:
|
||||
disable_sql_rewrite: false
|
||||
distinct: false
|
||||
replica: false
|
||||
query_comment: ''
|
||||
query_tags: { }
|
||||
fields:
|
||||
name_1:
|
||||
id: name_1
|
||||
table: entity_test
|
||||
field: name
|
||||
entity_type: entity_test
|
||||
entity_field: name
|
||||
plugin_id: field
|
||||
relationship: none
|
||||
group_type: group
|
||||
group_column: value
|
||||
group_columns: { }
|
||||
group_rows: true
|
||||
exclude: false
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
name_2:
|
||||
id: name_2
|
||||
table: entity_test_mul_property_data
|
||||
field: name
|
||||
entity_type: entity_test_mul
|
||||
entity_field: name
|
||||
plugin_id: field
|
||||
relationship: reverse__entity_test_mul__field_data_test_unlimited
|
||||
group_type: group
|
||||
group_column: entity_id
|
||||
group_columns: { }
|
||||
group_rows: false
|
||||
exclude: false
|
||||
delta_limit: 0
|
||||
delta_offset: 0
|
||||
delta_reversed: false
|
||||
delta_first_last: false
|
||||
multi_type: separator
|
||||
sorts:
|
||||
name:
|
||||
table: entity_test
|
||||
field: name
|
||||
id: name
|
||||
entity_type: entity_test
|
||||
entity_field: field_test
|
||||
order: ASC
|
||||
plugin_id: standard
|
||||
pager:
|
||||
type: some
|
||||
style:
|
||||
type: table
|
||||
options:
|
||||
grouping: { }
|
||||
row_class: ''
|
||||
default_row_class: true
|
||||
override: true
|
||||
sticky: false
|
||||
caption: ''
|
||||
summary: ''
|
||||
description: ''
|
||||
columns:
|
||||
name_1: name_1
|
||||
name_2: name_2
|
||||
info:
|
||||
name_1:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
name_2:
|
||||
sortable: false
|
||||
default_sort_order: asc
|
||||
align: ''
|
||||
separator: ''
|
||||
empty_column: false
|
||||
responsive: ''
|
||||
default: '-1'
|
||||
empty_table: false
|
||||
row:
|
||||
type: fields
|
||||
options:
|
||||
inline: { }
|
||||
separator: ''
|
||||
hide_empty: false
|
||||
default_field_elements: true
|
||||
relationships:
|
||||
reverse__entity_test_mul__field_data_test_unlimited:
|
||||
id: reverse__entity_test_mul__field_data_test_unlimited
|
||||
table: entity_test
|
||||
field: reverse__entity_test_mul__field_data_test_unlimited
|
||||
entity_type: entity_test
|
||||
plugin_id: entity_reverse
|
||||
group_type: group
|
||||
required: false
|
||||
group_by: true
|
||||
display_plugin: block
|
||||
display_title: Master
|
||||
id: default
|
||||
position: 0
|
|
@ -27,19 +27,3 @@ entity_test.entity_test_bundle.*:
|
|||
description:
|
||||
type: text
|
||||
label: 'Description'
|
||||
|
||||
entity_test.entity_test_bundle.*.third_party.content_moderation:
|
||||
type: mapping
|
||||
label: 'Enable moderation states for this entity test type'
|
||||
mapping:
|
||||
enabled:
|
||||
type: boolean
|
||||
label: 'Moderation states enabled'
|
||||
allowed_moderation_states:
|
||||
type: sequence
|
||||
sequence:
|
||||
type: string
|
||||
label: 'Moderation state'
|
||||
default_moderation_state:
|
||||
type: string
|
||||
label: 'Moderation state for new entity test'
|
||||
|
|
|
@ -15,12 +15,12 @@ use Drupal\field\Entity\FieldConfig;
|
|||
function entity_test_install() {
|
||||
foreach (entity_test_entity_types() as $entity_type) {
|
||||
// Auto-create fields for testing.
|
||||
FieldStorageConfig::create(array(
|
||||
FieldStorageConfig::create([
|
||||
'entity_type' => $entity_type,
|
||||
'field_name' => 'field_test_text',
|
||||
'type' => 'text',
|
||||
'cardinality' => 1,
|
||||
))->save();
|
||||
])->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $entity_type,
|
||||
'field_name' => 'field_test_text',
|
||||
|
@ -30,7 +30,7 @@ function entity_test_install() {
|
|||
])->save();
|
||||
|
||||
entity_get_form_display($entity_type, $entity_type, 'default')
|
||||
->setComponent('field_test_text', array('type' => 'text_textfield'))
|
||||
->setComponent('field_test_text', ['type' => 'text_textfield'])
|
||||
->save();
|
||||
}
|
||||
}
|
||||
|
@ -40,17 +40,17 @@ function entity_test_install() {
|
|||
*/
|
||||
function entity_test_schema() {
|
||||
// Schema for simple entity.
|
||||
$schema['entity_test_example'] = array(
|
||||
$schema['entity_test_example'] = [
|
||||
'description' => 'Stores entity_test items.',
|
||||
'fields' => array(
|
||||
'id' => array(
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'type' => 'serial',
|
||||
'not null' => TRUE,
|
||||
'description' => 'Primary Key: Unique entity-test item ID.',
|
||||
),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['id'],
|
||||
];
|
||||
return $schema;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\ContentEntityInterface;
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
@ -53,7 +54,7 @@ const ENTITY_TEST_TYPES_ROUTING = 3;
|
|||
* List with entity_types.
|
||||
*/
|
||||
function entity_test_entity_types($filter = NULL) {
|
||||
$types = array();
|
||||
$types = [];
|
||||
if ($filter === NULL || $filter === ENTITY_TEST_TYPES_ROUTING) {
|
||||
$types[] = 'entity_test';
|
||||
}
|
||||
|
@ -92,9 +93,6 @@ function entity_test_entity_type_alter(array &$entity_types) {
|
|||
}
|
||||
}
|
||||
|
||||
// Allow entity_test_update tests to override the entity type definition.
|
||||
$entity_types['entity_test_update'] = $state->get('entity_test_update.entity_type', $entity_types['entity_test_update']);
|
||||
|
||||
// Allow entity_test_with_bundle tests to override the entity type definition.
|
||||
$entity_types['entity_test_with_bundle'] = $state->get('entity_test_with_bundle.entity_type', $entity_types['entity_test_with_bundle']);
|
||||
|
||||
|
@ -167,7 +165,7 @@ function entity_test_entity_base_field_info_alter(&$fields, EntityTypeInterface
|
|||
*/
|
||||
function entity_test_entity_field_storage_info(EntityTypeInterface $entity_type) {
|
||||
if ($entity_type->id() == 'entity_test_update') {
|
||||
return \Drupal::state()->get('entity_test_update.additional_field_storage_definitions', array());
|
||||
return \Drupal::state()->get('entity_test_update.additional_field_storage_definitions', []);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -184,8 +182,8 @@ function entity_test_entity_field_storage_info(EntityTypeInterface $entity_type)
|
|||
* 'entity_test'.
|
||||
*/
|
||||
function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity_test') {
|
||||
$bundles = \Drupal::state()->get($entity_type . '.bundles') ?: array($entity_type => array('label' => 'Entity Test Bundle'));
|
||||
$bundles += array($bundle => array('label' => $text ? $text : $bundle));
|
||||
$bundles = \Drupal::state()->get($entity_type . '.bundles') ?: [$entity_type => ['label' => 'Entity Test Bundle']];
|
||||
$bundles += [$bundle => ['label' => $text ? $text : $bundle]];
|
||||
\Drupal::state()->set($entity_type . '.bundles', $bundles);
|
||||
|
||||
\Drupal::entityManager()->onBundleCreate($bundle, $entity_type);
|
||||
|
@ -201,7 +199,7 @@ function entity_test_create_bundle($bundle, $text = NULL, $entity_type = 'entity
|
|||
* 'entity_test'.
|
||||
*/
|
||||
function entity_test_delete_bundle($bundle, $entity_type = 'entity_test') {
|
||||
$bundles = \Drupal::state()->get($entity_type . '.bundles') ?: array($entity_type => array('label' => 'Entity Test Bundle'));
|
||||
$bundles = \Drupal::state()->get($entity_type . '.bundles') ?: [$entity_type => ['label' => 'Entity Test Bundle']];
|
||||
unset($bundles[$bundle]);
|
||||
\Drupal::state()->set($entity_type . '.bundles', $bundles);
|
||||
|
||||
|
@ -212,11 +210,11 @@ function entity_test_delete_bundle($bundle, $entity_type = 'entity_test') {
|
|||
* Implements hook_entity_bundle_info().
|
||||
*/
|
||||
function entity_test_entity_bundle_info() {
|
||||
$bundles = array();
|
||||
$bundles = [];
|
||||
$entity_types = \Drupal::entityManager()->getDefinitions();
|
||||
foreach ($entity_types as $entity_type_id => $entity_type) {
|
||||
if ($entity_type->getProvider() == 'entity_test' && $entity_type_id != 'entity_test_with_bundle') {
|
||||
$bundles[$entity_type_id] = \Drupal::state()->get($entity_type_id . '.bundles') ?: array($entity_type_id => array('label' => 'Entity Test Bundle'));
|
||||
$bundles[$entity_type_id] = \Drupal::state()->get($entity_type_id . '.bundles') ?: [$entity_type_id => ['label' => 'Entity Test Bundle']];
|
||||
}
|
||||
}
|
||||
return $bundles;
|
||||
|
@ -229,18 +227,18 @@ function entity_test_entity_view_mode_info_alter(&$view_modes) {
|
|||
$entity_info = \Drupal::entityManager()->getDefinitions();
|
||||
foreach ($entity_info as $entity_type => $info) {
|
||||
if ($entity_info[$entity_type]->getProvider() == 'entity_test' && !isset($view_modes[$entity_type])) {
|
||||
$view_modes[$entity_type] = array(
|
||||
'full' => array(
|
||||
$view_modes[$entity_type] = [
|
||||
'full' => [
|
||||
'label' => t('Full object'),
|
||||
'status' => TRUE,
|
||||
'cache' => TRUE,
|
||||
),
|
||||
'teaser' => array(
|
||||
],
|
||||
'teaser' => [
|
||||
'label' => t('Teaser'),
|
||||
'status' => TRUE,
|
||||
'cache' => TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,12 +250,12 @@ function entity_test_entity_form_mode_info_alter(&$form_modes) {
|
|||
$entity_info = \Drupal::entityManager()->getDefinitions();
|
||||
foreach ($entity_info as $entity_type => $info) {
|
||||
if ($entity_info[$entity_type]->getProvider() == 'entity_test') {
|
||||
$form_modes[$entity_type] = array(
|
||||
'compact' => array(
|
||||
$form_modes[$entity_type] = [
|
||||
'compact' => [
|
||||
'label' => t('Compact version'),
|
||||
'status' => TRUE,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -266,24 +264,24 @@ function entity_test_entity_form_mode_info_alter(&$form_modes) {
|
|||
* Implements hook_entity_extra_field_info().
|
||||
*/
|
||||
function entity_test_entity_extra_field_info() {
|
||||
$extra['entity_test']['bundle_with_extra_fields'] = array(
|
||||
'display' => array(
|
||||
$extra['entity_test']['bundle_with_extra_fields'] = [
|
||||
'display' => [
|
||||
// Note: those extra fields do not currently display anything, they are
|
||||
// just used in \Drupal\Tests\field_ui\Kernel\EntityDisplayTest to test
|
||||
// the behavior of entity display objects.
|
||||
'display_extra_field' => array(
|
||||
'display_extra_field' => [
|
||||
'label' => t('Display extra field'),
|
||||
'description' => t('An extra field on the display side.'),
|
||||
'weight' => 5,
|
||||
'visible' => TRUE,
|
||||
),
|
||||
'display_extra_field_hidden' => array(
|
||||
],
|
||||
'display_extra_field_hidden' => [
|
||||
'label' => t('Display extra field (hidden)'),
|
||||
'description' => t('An extra field on the display side, hidden by default.'),
|
||||
'visible' => FALSE,
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
return $extra;
|
||||
}
|
||||
|
@ -412,6 +410,25 @@ function entity_test_entity_test_insert($entity) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_insert().
|
||||
*/
|
||||
function entity_test_entity_insert(EntityInterface $entity) {
|
||||
if ($entity->getEntityTypeId() == 'entity_test_mulrev' && $entity->label() == 'EntityLoadedRevisionTest') {
|
||||
$entity->setNewRevision(FALSE);
|
||||
$entity->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_update().
|
||||
*/
|
||||
function entity_test_entity_update(EntityInterface $entity) {
|
||||
if ($entity instanceof ContentEntityInterface) {
|
||||
\Drupal::state()->set('entity_test.loadedRevisionId', $entity->getLoadedRevisionId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_field_access().
|
||||
*
|
||||
|
@ -656,16 +673,16 @@ function entity_test_field_default_value(FieldableEntityInterface $entity, Field
|
|||
// that they are correctly passed.
|
||||
$string = $definition->getName() . '_' . $entity->language()->getId();
|
||||
// Return a "default value" with multiple items.
|
||||
return array(
|
||||
array(
|
||||
return [
|
||||
[
|
||||
'shape' => "shape:0:$string",
|
||||
'color' => "color:0:$string",
|
||||
),
|
||||
array(
|
||||
],
|
||||
[
|
||||
'shape' => "shape:1:$string",
|
||||
'color' => "color:1:$string",
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -695,7 +712,7 @@ function entity_test_entity_prepare_view($entity_type, array $entities, array $d
|
|||
// Add a dummy field item attribute on field_test_text if it exists.
|
||||
if ($entity->hasField('field_test_text') && $displays[$entity->bundle()]->getComponent('field_test_text')) {
|
||||
foreach ($entity->get('field_test_text') as $item) {
|
||||
$item->_attributes += array('data-field-item-attr' => 'foobar');
|
||||
$item->_attributes += ['data-field-item-attr' => 'foobar'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -704,7 +721,7 @@ function entity_test_entity_prepare_view($entity_type, array $entities, array $d
|
|||
foreach ($fields as $field) {
|
||||
if ($field->getType() === 'daterange') {
|
||||
$item = $entity->get($field->getName());
|
||||
$item->_attributes += array('data-field-item-attr' => 'foobar');
|
||||
$item->_attributes += ['data-field-item-attr' => 'foobar'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,40 +4,12 @@ namespace Drupal\entity_test\Controller;
|
|||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Controller\ControllerBase;
|
||||
use Drupal\Core\Entity\Query\QueryFactory;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
* Controller routines for entity_test routes.
|
||||
*/
|
||||
class EntityTestController extends ControllerBase {
|
||||
|
||||
/**
|
||||
* The entity query factory.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\Query\QueryFactory
|
||||
*/
|
||||
protected $entityQueryFactory;
|
||||
|
||||
/**
|
||||
* Constructs a new EntityTestController.
|
||||
*
|
||||
* @param \Drupal\Core\Entity\Query\QueryFactory $entity_query_factory
|
||||
* The entity query factory.
|
||||
*/
|
||||
public function __construct(QueryFactory $entity_query_factory) {
|
||||
$this->entityQueryFactory = $entity_query_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('entity.query')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an empty page.
|
||||
*
|
||||
|
@ -66,11 +38,10 @@ class EntityTestController extends ControllerBase {
|
|||
->getStorage($referenced_entity_type)
|
||||
->load($referenced_entity_id);
|
||||
if ($referenced_entity === NULL) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
$query = $this->entityQueryFactory
|
||||
->get('entity_test')
|
||||
$query = $this->entityTypeManager()->getStorage('entity_test')->getQuery()
|
||||
->condition($entity_reference_field_name . '.target_id', $referenced_entity_id);
|
||||
$entities = $this->entityManager()
|
||||
->getStorage('entity_test')
|
||||
|
@ -91,7 +62,7 @@ class EntityTestController extends ControllerBase {
|
|||
*/
|
||||
public function listEntitiesAlphabetically($entity_type_id) {
|
||||
$entity_type_definition = $this->entityManager()->getDefinition($entity_type_id);
|
||||
$query = $this->entityQueryFactory->get($entity_type_id);
|
||||
$query = $this->entityTypeManager()->getStorage($entity_type_id)->getQuery();
|
||||
|
||||
// Sort by label field, if any.
|
||||
if ($label_field = $entity_type_definition->getKey('label')) {
|
||||
|
|
|
@ -72,15 +72,15 @@ class EntityTest extends ContentEntityBase implements EntityOwnerInterface {
|
|||
->setDescription(t('The name of the test entity.'))
|
||||
->setTranslatable(TRUE)
|
||||
->setSetting('max_length', 32)
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
'weight' => -5,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -5,
|
||||
));
|
||||
]);
|
||||
|
||||
$fields['created'] = BaseFieldDefinition::create('created')
|
||||
->setLabel(t('Authored on'))
|
||||
|
@ -94,17 +94,17 @@ class EntityTest extends ContentEntityBase implements EntityOwnerInterface {
|
|||
->setSetting('handler', 'default')
|
||||
// Default EntityTest entities to have the root user as the owner, to
|
||||
// simplify testing.
|
||||
->setDefaultValue(array(0 => array('target_id' => 1)))
|
||||
->setDefaultValue([0 => ['target_id' => 1]])
|
||||
->setTranslatable(TRUE)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => -1,
|
||||
'settings' => array(
|
||||
'settings' => [
|
||||
'match_operator' => 'CONTAINS',
|
||||
'size' => '60',
|
||||
'placeholder' => '',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -53,39 +53,39 @@ class EntityTestBaseFieldDisplay extends EntityTest {
|
|||
|
||||
$fields['test_display_configurable'] = BaseFieldDefinition::create('text')
|
||||
->setLabel(t('Field with configurable display'))
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'type' => 'text_default',
|
||||
'weight' => 10,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('view', TRUE)
|
||||
->setDisplayOptions('form', array(
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'text_textfield',
|
||||
'weight' => 10,
|
||||
))
|
||||
])
|
||||
->setDisplayConfigurable('form', TRUE);
|
||||
|
||||
$fields['test_display_non_configurable'] = BaseFieldDefinition::create('text')
|
||||
->setLabel(t('Field with non-configurable display'))
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'type' => 'text_default',
|
||||
'weight' => 11,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'text_textfield',
|
||||
'weight' => 11,
|
||||
));
|
||||
]);
|
||||
|
||||
$fields['test_display_multiple'] = BaseFieldDefinition::create('text')
|
||||
->setLabel(t('A field with multiple values'))
|
||||
->setCardinality(FieldStorageDefinition::CARDINALITY_UNLIMITED)
|
||||
->setDisplayOptions('view', array(
|
||||
->setDisplayOptions('view', [
|
||||
'type' => 'text_default',
|
||||
'weight' => 12,
|
||||
))
|
||||
->setDisplayOptions('form', array(
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'text_textfield',
|
||||
'weight' => 12,
|
||||
));
|
||||
]);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -36,15 +36,15 @@ class EntityTestCompositeConstraint extends EntityTest {
|
|||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['name']->setDisplayOptions('form', array(
|
||||
$fields['name']->setDisplayOptions('form', [
|
||||
'type' => 'string',
|
||||
'weight' => 0,
|
||||
));
|
||||
]);
|
||||
|
||||
$fields['type']->setDisplayOptions('form', array(
|
||||
$fields['type']->setDisplayOptions('form', [
|
||||
'type' => 'entity_reference_autocomplete',
|
||||
'weight' => 0,
|
||||
));
|
||||
]);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -33,11 +33,11 @@ class EntityTestConstraintViolation extends EntityTest {
|
|||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['name']->setDisplayOptions('form', array(
|
||||
$fields['name']->setDisplayOptions('form', [
|
||||
'type' => 'string',
|
||||
'weight' => 0,
|
||||
));
|
||||
$fields['name']->addConstraint('FieldWidgetConstraint', array());
|
||||
]);
|
||||
$fields['name']->addConstraint('FieldWidgetConstraint', []);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,10 @@ class EntityTestMulChanged extends EntityTestMul implements EntityChangedInterfa
|
|||
->setDescription(t('The time that the entity was last edited.'))
|
||||
->setTranslatable(TRUE);
|
||||
|
||||
$fields['not_translatable'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(t('Non translatable'))
|
||||
->setDescription(t('A non-translatable string field'));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace Drupal\entity_test\Entity;
|
|||
* revision_data_table = "entity_test_mulrev_property_revision",
|
||||
* admin_permission = "administer entity_test content",
|
||||
* translatable = TRUE,
|
||||
* show_revision_ui = TRUE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\entity_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Entity\RevisionLogEntityTrait;
|
||||
use Drupal\Core\Entity\RevisionLogInterface;
|
||||
|
||||
/**
|
||||
* Defines the test entity class.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "entity_test_mulrev_chnged_revlog",
|
||||
* label = @Translation("Test entity - revisions log and data table"),
|
||||
* base_table = "entity_test_mulrev_changed_revlog",
|
||||
* revision_table = "entity_test_mulrev_changed_revlog_revision",
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* "bundle" = "type",
|
||||
* "revision" = "revision_id",
|
||||
* "label" = "name",
|
||||
* "langcode" = "langcode",
|
||||
* },
|
||||
* revision_metadata_keys = {
|
||||
* "revision_user" = "revision_user",
|
||||
* "revision_created" = "revision_created",
|
||||
* "revision_log_message" = "revision_log_message"
|
||||
* },
|
||||
* )
|
||||
*/
|
||||
class EntityTestMulRevChangedWithRevisionLog extends EntityTestMulRevChanged implements RevisionLogInterface {
|
||||
|
||||
use RevisionLogEntityTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
$fields += static::revisionLogBaseFieldDefinitions($entity_type);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\entity_test\Entity;
|
||||
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedTrait;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
||||
/**
|
||||
* Defines the test entity class.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "entity_test_mulrevpub",
|
||||
* label = @Translation("Test entity - revisions, data table, and published interface"),
|
||||
* handlers = {
|
||||
* "view_builder" = "Drupal\entity_test\EntityTestViewBuilder",
|
||||
* "access" = "Drupal\entity_test\EntityTestAccessControlHandler",
|
||||
* "form" = {
|
||||
* "default" = "Drupal\entity_test\EntityTestForm",
|
||||
* "delete" = "Drupal\entity_test\EntityTestDeleteForm"
|
||||
* },
|
||||
* "translation" = "Drupal\content_translation\ContentTranslationHandler",
|
||||
* "views_data" = "Drupal\views\EntityViewsData",
|
||||
* "route_provider" = {
|
||||
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
|
||||
* },
|
||||
* },
|
||||
* base_table = "entity_test_mulrevpub",
|
||||
* data_table = "entity_test_mulrevpub_property_data",
|
||||
* revision_table = "entity_test_mulrevpub_revision",
|
||||
* revision_data_table = "entity_test_mulrevpub_property_revision",
|
||||
* admin_permission = "administer entity_test content",
|
||||
* translatable = TRUE,
|
||||
* show_revision_ui = TRUE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* "bundle" = "type",
|
||||
* "revision" = "revision_id",
|
||||
* "label" = "name",
|
||||
* "langcode" = "langcode",
|
||||
* "published" = "status",
|
||||
* },
|
||||
* links = {
|
||||
* "add-form" = "/entity_test_mulrevpub/add",
|
||||
* "canonical" = "/entity_test_mulrevpub/manage/{entity_test_mulrevpub}",
|
||||
* "delete-form" = "/entity_test/delete/entity_test_mulrevpub/{entity_test_mulrevpub}",
|
||||
* "edit-form" = "/entity_test_mulrevpub/manage/{entity_test_mulrevpub}/edit",
|
||||
* "revision" = "/entity_test_mulrevpub/{entity_test_mulrevpub}/revision/{entity_test_mulrevpub_revision}/view",
|
||||
* }
|
||||
* )
|
||||
*/
|
||||
class EntityTestMulRevPub extends EntityTestMulRev implements EntityPublishedInterface {
|
||||
|
||||
use EntityPublishedTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
return parent::baseFieldDefinitions($entity_type) + EntityPublishedTrait::publishedBaseFieldDefinitions($entity_type);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
|
|||
* base_table = "entity_test_rev",
|
||||
* revision_table = "entity_test_rev_revision",
|
||||
* admin_permission = "administer entity_test content",
|
||||
* show_revision_ui = TRUE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
|
@ -53,13 +54,6 @@ class EntityTestRev extends EntityTest {
|
|||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
|
||||
$fields['revision_id'] = BaseFieldDefinition::create('integer')
|
||||
->setLabel(t('Revision ID'))
|
||||
->setDescription(t('The version id of the test entity.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setSetting('unsigned', TRUE);
|
||||
|
||||
$fields['langcode']->setRevisionable(TRUE);
|
||||
$fields['name']->setRevisionable(TRUE);
|
||||
$fields['user_id']->setRevisionable(TRUE);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ class EntityTestUpdate extends EntityTestRev {
|
|||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
$fields = parent::baseFieldDefinitions($entity_type);
|
||||
$fields += \Drupal::state()->get('entity_test_update.additional_base_field_definitions', array());
|
||||
$fields += \Drupal::state()->get('entity_test_update.additional_base_field_definitions', []);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ class EntityTestUpdate extends EntityTestRev {
|
|||
*/
|
||||
public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
|
||||
$fields = parent::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions);
|
||||
$fields += \Drupal::state()->get('entity_test_update.additional_bundle_field_definitions.' . $bundle, array());
|
||||
$fields += \Drupal::state()->get('entity_test_update.additional_bundle_field_definitions.' . $bundle, []);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,13 +45,13 @@ class EntityTestAccessControlHandler extends EntityAccessControlHandler {
|
|||
// Viewing the label of the 'entity_test_label' entity type is allowed.
|
||||
return AccessResult::allowed();
|
||||
}
|
||||
elseif (in_array($operation, array('view', 'view label'))) {
|
||||
elseif (in_array($operation, ['view', 'view label'])) {
|
||||
if (!$entity->isDefaultTranslation()) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'view test entity translations');
|
||||
}
|
||||
return AccessResult::allowedIfHasPermission($account, 'view test entity');
|
||||
}
|
||||
elseif (in_array($operation, array('update', 'delete'))) {
|
||||
elseif (in_array($operation, ['update', 'delete'])) {
|
||||
return AccessResult::allowedIfHasPermission($account, 'administer entity_test content');
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class EntityTestDefinitionSubscriber implements EventSubscriberInterface, Entity
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function __construct(StateInterface $state) {
|
||||
public function __construct(StateInterface $state) {
|
||||
$this->state = $state;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,11 +32,11 @@ class EntityTestForm extends ContentEntityForm {
|
|||
|
||||
// @todo: Is there a better way to check if an entity type is revisionable?
|
||||
if ($entity->getEntityType()->hasKey('revision') && !$entity->isNew()) {
|
||||
$form['revision'] = array(
|
||||
$form['revision'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Create new revision'),
|
||||
'#default_value' => $entity->isNewRevision(),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
return $form;
|
||||
|
@ -58,10 +58,10 @@ class EntityTestForm extends ContentEntityForm {
|
|||
$entity->save();
|
||||
|
||||
if ($is_new) {
|
||||
$message = t('%entity_type @id has been created.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()));
|
||||
$message = t('%entity_type @id has been created.', ['@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()]);
|
||||
}
|
||||
else {
|
||||
$message = t('%entity_type @id has been updated.', array('@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()));
|
||||
$message = t('%entity_type @id has been updated.', ['@id' => $entity->id(), '%entity_type' => $entity->getEntityTypeId()]);
|
||||
}
|
||||
drupal_set_message($message);
|
||||
|
||||
|
@ -69,7 +69,7 @@ class EntityTestForm extends ContentEntityForm {
|
|||
$entity_type = $entity->getEntityTypeId();
|
||||
$form_state->setRedirect(
|
||||
"entity.$entity_type.edit_form",
|
||||
array($entity_type => $entity->id())
|
||||
[$entity_type => $entity->id()]
|
||||
);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -18,18 +18,18 @@ class EntityTestViewBuilder extends EntityViewBuilder {
|
|||
parent::buildComponents($build, $entities, $displays, $view_mode);
|
||||
|
||||
foreach ($entities as $id => $entity) {
|
||||
$build[$id]['label'] = array(
|
||||
$build[$id]['label'] = [
|
||||
'#weight' => -100,
|
||||
'#plain_text' => $entity->label(),
|
||||
);
|
||||
$build[$id]['separator'] = array(
|
||||
];
|
||||
$build[$id]['separator'] = [
|
||||
'#weight' => -150,
|
||||
'#markup' => ' | ',
|
||||
);
|
||||
$build[$id]['view_mode'] = array(
|
||||
];
|
||||
$build[$id]['view_mode'] = [
|
||||
'#weight' => -200,
|
||||
'#plain_text' => $view_mode,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,16 +13,16 @@ class EntityTestLocalTasks extends DeriverBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDerivativeDefinitions($base_plugin_definition) {
|
||||
$this->derivatives = array();
|
||||
$this->derivatives = [];
|
||||
$types = entity_test_entity_types(ENTITY_TEST_TYPES_ROUTING);
|
||||
|
||||
foreach ($types as $entity_type) {
|
||||
$this->derivatives[$entity_type . '.canonical'] = array();
|
||||
$this->derivatives[$entity_type . '.canonical'] = [];
|
||||
$this->derivatives[$entity_type . '.canonical']['base_route'] = "entity.$entity_type.canonical";
|
||||
$this->derivatives[$entity_type . '.canonical']['route_name'] = "entity.$entity_type.canonical";
|
||||
$this->derivatives[$entity_type . '.canonical']['title'] = 'View';
|
||||
|
||||
$this->derivatives[$entity_type . '.edit'] = array();
|
||||
$this->derivatives[$entity_type . '.edit'] = [];
|
||||
$this->derivatives[$entity_type . '.edit']['base_route'] = "entity.$entity_type.canonical";
|
||||
$this->derivatives[$entity_type . '.edit']['route_name'] = "entity.$entity_type.edit_form";
|
||||
$this->derivatives[$entity_type . '.edit']['title'] = 'Edit';
|
||||
|
|
|
@ -46,14 +46,14 @@ class FieldTestItem extends FieldItemBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return array(
|
||||
'columns' => array(
|
||||
'value' => array(
|
||||
return [
|
||||
'columns' => [
|
||||
'value' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
),
|
||||
),
|
||||
);
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -21,9 +21,9 @@ class ShapeItem extends FieldItemBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function defaultStorageSettings() {
|
||||
return array(
|
||||
return [
|
||||
'foreign_key_name' => 'shape',
|
||||
) + parent::defaultStorageSettings();
|
||||
] + parent::defaultStorageSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,30 +43,30 @@ class ShapeItem extends FieldItemBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
$foreign_keys = array();
|
||||
$foreign_keys = [];
|
||||
// The 'foreign keys' key is not always used in tests.
|
||||
if ($field_definition->getSetting('foreign_key_name')) {
|
||||
$foreign_keys['foreign keys'] = array(
|
||||
$foreign_keys['foreign keys'] = [
|
||||
// This is a dummy foreign key definition, references a table that
|
||||
// doesn't exist, but that's not a problem.
|
||||
$field_definition->getSetting('foreign_key_name') => array(
|
||||
$field_definition->getSetting('foreign_key_name') => [
|
||||
'table' => $field_definition->getSetting('foreign_key_name'),
|
||||
'columns' => array($field_definition->getSetting('foreign_key_name') => 'id'),
|
||||
),
|
||||
);
|
||||
'columns' => [$field_definition->getSetting('foreign_key_name') => 'id'],
|
||||
],
|
||||
];
|
||||
}
|
||||
return array(
|
||||
'columns' => array(
|
||||
'shape' => array(
|
||||
return [
|
||||
'columns' => [
|
||||
'shape' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
),
|
||||
'color' => array(
|
||||
],
|
||||
'color' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 32,
|
||||
),
|
||||
),
|
||||
) + $foreign_keys;
|
||||
],
|
||||
],
|
||||
] + $foreign_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,7 +17,7 @@ use Drupal\Core\Form\FormStateInterface;
|
|||
* },
|
||||
* )
|
||||
*/
|
||||
class ShapeOnlyColorEditableWidget extends WidgetBase {
|
||||
class ShapeOnlyColorEditableWidget extends WidgetBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -18,13 +18,13 @@ class EntityTestRoutes {
|
|||
public function routes() {
|
||||
$types = entity_test_entity_types(ENTITY_TEST_TYPES_ROUTING);
|
||||
|
||||
$routes = array();
|
||||
$routes = [];
|
||||
foreach ($types as $entity_type_id) {
|
||||
$routes["entity.$entity_type_id.admin_form"] = new Route(
|
||||
"$entity_type_id/structure/{bundle}",
|
||||
array('_controller' => '\Drupal\entity_test\Controller\EntityTestController::testAdmin'),
|
||||
array('_permission' => 'administer entity_test content'),
|
||||
array('_admin_route' => TRUE)
|
||||
['_controller' => '\Drupal\entity_test\Controller\EntityTestController::testAdmin'],
|
||||
['_permission' => 'administer entity_test content'],
|
||||
['_admin_route' => TRUE]
|
||||
);
|
||||
}
|
||||
return $routes;
|
||||
|
|
|
@ -11,19 +11,19 @@ use Drupal\Core\Entity\EntityTypeInterface;
|
|||
* Implements hook_entity_base_field_info().
|
||||
*/
|
||||
function entity_test_extra_entity_base_field_info(EntityTypeInterface $entity_type) {
|
||||
return \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', array());
|
||||
return \Drupal::state()->get($entity_type->id() . '.additional_base_field_definitions', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_field_storage_info().
|
||||
*/
|
||||
function entity_test_extra_entity_field_storage_info(EntityTypeInterface $entity_type) {
|
||||
return \Drupal::state()->get($entity_type->id() . '.additional_field_storage_definitions', array());
|
||||
return \Drupal::state()->get($entity_type->id() . '.additional_field_storage_definitions', []);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_bundle_field_info().
|
||||
*/
|
||||
function entity_test_extra_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
|
||||
return \Drupal::state()->get($entity_type->id() . '.' . $bundle . '.additional_bundle_field_definitions', array());
|
||||
return \Drupal::state()->get($entity_type->id() . '.' . $bundle . '.additional_bundle_field_definitions', []);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
config:
|
||||
- field.storage.entity_test_update.field_test_configurable_field
|
||||
module:
|
||||
- entity_test_update
|
||||
id: entity_test_update.entity_test_update.field_test_configurable_field
|
||||
field_name: field_test_configurable_field
|
||||
entity_type: entity_test_update
|
||||
bundle: entity_test_update
|
||||
label: 'Test configurable field'
|
||||
description: ''
|
||||
required: false
|
||||
translatable: true
|
||||
default_value:
|
||||
-
|
||||
value1: { }
|
||||
default_value_callback: ''
|
||||
settings: { }
|
||||
field_type: multi_value_test
|
|
@ -0,0 +1,17 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies:
|
||||
module:
|
||||
- entity_test_update
|
||||
id: entity_test_update.field_test_configurable_field
|
||||
field_name: field_test_configurable_field
|
||||
entity_type: entity_test_update
|
||||
type: multi_value_test
|
||||
settings: { }
|
||||
module: entity_test_update
|
||||
locked: false
|
||||
cardinality: -1
|
||||
translatable: true
|
||||
indexes: { }
|
||||
persist_with_no_fields: false
|
||||
custom_storage: false
|
|
@ -0,0 +1,9 @@
|
|||
field.value.multi_value_test:
|
||||
type: mapping
|
||||
label: 'Default value'
|
||||
mapping:
|
||||
value1:
|
||||
type: sequence
|
||||
sequence:
|
||||
type: string
|
||||
label: 'First value'
|
|
@ -0,0 +1,6 @@
|
|||
name: 'Entity Update Test'
|
||||
type: module
|
||||
description: 'Provides an entity type for testing definition and schema updates.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides an entity type for testing definition and schema updates.
|
||||
*/
|
||||
|
||||
use Drupal\Core\Entity\EntityInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
use Drupal\entity_test_update\Entity\EntityTestUpdate;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
||||
/**
|
||||
* Implements hook_entity_base_field_info().
|
||||
*/
|
||||
function entity_test_update_entity_base_field_info(EntityTypeInterface $entity_type) {
|
||||
// Add a base field that will be used to test that fields added through
|
||||
// hook_entity_base_field_info() are handled correctly during a schema
|
||||
// conversion (e.g. from non-revisionable to revisionable).
|
||||
if ($entity_type->id() == 'entity_test_update') {
|
||||
$fields = [];
|
||||
$fields['test_entity_base_field_info'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Field added by hook_entity_base_field_info()'))
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_type_alter().
|
||||
*/
|
||||
function entity_test_update_entity_type_alter(array &$entity_types) {
|
||||
// Allow entity_test_update tests to override the entity type definition.
|
||||
$entity_types['entity_test_update'] = \Drupal::state()->get('entity_test_update.entity_type', $entity_types['entity_test_update']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_presave().
|
||||
*/
|
||||
function entity_test_update_entity_presave(EntityInterface $entity) {
|
||||
// Simulate an error during the save process of a test entity.
|
||||
if ($entity->getEntityTypeId() === 'entity_test_update' && \Drupal::state()->get('entity_test_update.throw_exception', FALSE)) {
|
||||
throw new \Exception('Peekaboo!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a given number of 'entity_test_update' entities.
|
||||
*
|
||||
* The 'drupal-8.0.0-rc1-filled.standard.entity_test_update.php.gz' db dump was
|
||||
* created with the following characteristics:
|
||||
* - Drupal 8.0.0-rc1 installed with the Standard profile;
|
||||
* - The 'entity_test_update' module enabled;
|
||||
* - 102 test entities created and saved.
|
||||
*
|
||||
* The 'drupal-8.0.0-rc1-filled.standard.entity_test_update_mul.php.gz' db dump
|
||||
* was created with the following characteristics:
|
||||
* - Drupal 8.0.0-rc1 installed with the Standard profile;
|
||||
* - Manually edited the annotation of the entity_test_update entity type in
|
||||
* order to make it translatable;
|
||||
* - The entity_test_update and Language module enabled;
|
||||
* - Romanian language added;
|
||||
* - 50 test entities created, translated and saved;
|
||||
* - The Content Translation module enabled and configured for our test entity
|
||||
* type. This was enabled after the first 50 entities were created in order
|
||||
* to have NULL values for its translation metadata fields
|
||||
* (e.g. content_translation_status);
|
||||
* - 52 more test entities (with the IDs 51 - 102) crated, translated and saved.
|
||||
*
|
||||
* @param int $start
|
||||
* (optional) The entity ID to start from. Defaults to 1.
|
||||
* @param int $end
|
||||
* (optional) The entity ID to end with. Defaults to 50.
|
||||
* @param bool $add_translation
|
||||
* (optional) Whether to create a translation for each entity. If the number
|
||||
* of entities is greater than 50, the default translation (en) of the 51st
|
||||
* entity and the 52nd translation (ro) are disabled through the
|
||||
* 'content_moderation_status' field. Defaults to FALSE.
|
||||
*
|
||||
* @see drupal-8.0.0-rc1-filled.standard.entity_test_update.php.gz
|
||||
* @see drupal-8.0.0-rc1-filled.standard.entity_test_update_mul.php.gz
|
||||
*/
|
||||
function _entity_test_update_create_test_entities($start = 1, $end = 50, $add_translation = FALSE) {
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
$entity = EntityTestUpdate::create([
|
||||
'id' => $i,
|
||||
'name' => $i,
|
||||
'test_single_property' => $i . ' - test single property',
|
||||
'test_multiple_properties' => [[
|
||||
'value1' => $i . ' - test multiple properties - value1',
|
||||
'value2' => $i . ' - test multiple properties - value2',
|
||||
]],
|
||||
'test_single_property_multiple_values' => [
|
||||
['value' => $i . ' - test single property multiple values 0'],
|
||||
['value' => $i . ' - test single property multiple values 1']
|
||||
],
|
||||
'test_multiple_properties_multiple_values' => [
|
||||
[
|
||||
'value1' => $i . ' - test multiple properties multiple values - value1 0',
|
||||
'value2' => $i . ' - test multiple properties multiple values - value2 0',
|
||||
],
|
||||
[
|
||||
'value1' => $i . ' - test multiple properties multiple values - value1 1',
|
||||
'value2' => $i . ' - test multiple properties multiple values - value2 1',
|
||||
]
|
||||
],
|
||||
'test_non_rev_field' => $i . ' - test non-revisionable field',
|
||||
'test_non_mul_field' => $i . ' - test non-translatable field',
|
||||
'test_non_mulrev_field' => $i . ' - test non-translatable and non-revisionable field',
|
||||
'field_test_configurable_field' => [
|
||||
[
|
||||
'value1' => $i . ' - field test configurable field - value1 0',
|
||||
'value2' => $i . ' - field test configurable field - value2 0',
|
||||
],
|
||||
[
|
||||
'value1' => $i . ' - field test configurable field - value1 1',
|
||||
'value2' => $i . ' - field test configurable field - value2 1',
|
||||
]
|
||||
],
|
||||
'test_entity_base_field_info' => $i . ' - test entity base field info',
|
||||
]);
|
||||
|
||||
if ($add_translation) {
|
||||
$entity->addTranslation('ro', [
|
||||
'name' => $i . ' - ro',
|
||||
'test_single_property' => $i . ' - test single property - ro',
|
||||
'test_multiple_properties' => [[
|
||||
'value1' => $i . ' - test multiple properties - value1 - ro',
|
||||
'value2' => $i . ' - test multiple properties - value2 - ro',
|
||||
]],
|
||||
'test_single_property_multiple_values' => [
|
||||
['value' => $i . ' - test single property multiple values 0 - ro'],
|
||||
['value' => $i . ' - test single property multiple values 1 - ro']
|
||||
],
|
||||
'test_multiple_properties_multiple_values' => [
|
||||
[
|
||||
'value1' => $i . ' - test multiple properties multiple values - value1 0 - ro',
|
||||
'value2' => $i . ' - test multiple properties multiple values - value2 0 - ro',
|
||||
],
|
||||
[
|
||||
'value1' => $i . ' - test multiple properties multiple values - value1 1 - ro',
|
||||
'value2' => $i . ' - test multiple properties multiple values - value2 1 - ro',
|
||||
]
|
||||
],
|
||||
'test_non_rev_field' => $i . ' - test non-revisionable field - ro',
|
||||
'field_test_configurable_field' => [
|
||||
[
|
||||
'value1' => $i . ' - field test configurable field - value1 0 - ro',
|
||||
'value2' => $i . ' - field test configurable field - value2 0 - ro',
|
||||
],
|
||||
[
|
||||
'value1' => $i . ' - field test configurable field - value1 1 - ro',
|
||||
'value2' => $i . ' - field test configurable field - value2 1 - ro',
|
||||
]
|
||||
],
|
||||
'test_entity_base_field_info' => $i . ' - test entity base field info - ro',
|
||||
]);
|
||||
|
||||
if ($i == 101) {
|
||||
$entity->getTranslation('en')->set('content_translation_status', FALSE);
|
||||
}
|
||||
if ($i == 102) {
|
||||
$entity->getTranslation('ro')->set('content_translation_status', FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
$entity->save();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\entity_test_update\Entity;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityBase;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\StringTranslation\TranslatableMarkup;
|
||||
|
||||
/**
|
||||
* Defines the test entity class for testing definition and schema updates.
|
||||
*
|
||||
* This entity type starts out non-revisionable and non-translatable, but during
|
||||
* an update test it can be made revisionable and translatable using the helper
|
||||
* methods from \Drupal\system\Tests\Entity\EntityDefinitionTestTrait.
|
||||
*
|
||||
* @ContentEntityType(
|
||||
* id = "entity_test_update",
|
||||
* label = @Translation("Test entity update"),
|
||||
* handlers = {
|
||||
* "storage_schema" = "Drupal\entity_test_update\EntityTestUpdateStorageSchema",
|
||||
* },
|
||||
* base_table = "entity_test_update",
|
||||
* persistent_cache = FALSE,
|
||||
* entity_keys = {
|
||||
* "id" = "id",
|
||||
* "uuid" = "uuid",
|
||||
* "bundle" = "type",
|
||||
* "label" = "name",
|
||||
* "langcode" = "langcode",
|
||||
* },
|
||||
* content_translation_ui_skip = TRUE,
|
||||
* )
|
||||
*/
|
||||
class EntityTestUpdate extends ContentEntityBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function preCreate(EntityStorageInterface $storage, array &$values) {
|
||||
parent::preCreate($storage, $values);
|
||||
if (empty($values['type'])) {
|
||||
$values['type'] = $storage->getEntityTypeId();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
||||
// This entity type is used for generating database dumps from Drupal
|
||||
// 8.0.0-rc1, which didn't have the entity key base fields defined in
|
||||
// the parent class (ContentEntityBase), so we have to duplicate them here.
|
||||
|
||||
$fields[$entity_type->getKey('id')] = BaseFieldDefinition::create('integer')
|
||||
->setLabel(new TranslatableMarkup('ID'))
|
||||
->setDescription(new TranslatableMarkup('The ID of the test entity.'))
|
||||
->setReadOnly(TRUE)
|
||||
->setSetting('unsigned', TRUE);
|
||||
|
||||
$fields[$entity_type->getKey('uuid')] = BaseFieldDefinition::create('uuid')
|
||||
->setLabel(new TranslatableMarkup('UUID'))
|
||||
->setDescription(new TranslatableMarkup('The UUID of the test entity.'))
|
||||
->setReadOnly(TRUE);
|
||||
|
||||
$fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Type'))
|
||||
->setDescription(new TranslatableMarkup('The bundle of the test entity.'))
|
||||
->setRequired(TRUE);
|
||||
|
||||
if ($entity_type->hasKey('revision')) {
|
||||
$fields[$entity_type->getKey('revision')] = BaseFieldDefinition::create('integer')
|
||||
->setLabel(new TranslatableMarkup('Revision ID'))
|
||||
->setReadOnly(TRUE)
|
||||
->setSetting('unsigned', TRUE);
|
||||
}
|
||||
|
||||
$fields[$entity_type->getKey('langcode')] = BaseFieldDefinition::create('language')
|
||||
->setLabel(new TranslatableMarkup('Language'));
|
||||
if ($entity_type->isRevisionable()) {
|
||||
$fields[$entity_type->getKey('langcode')]->setRevisionable(TRUE);
|
||||
}
|
||||
if ($entity_type->isTranslatable()) {
|
||||
$fields[$entity_type->getKey('langcode')]->setTranslatable(TRUE);
|
||||
}
|
||||
|
||||
$fields['name'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Name'))
|
||||
->setDescription(new TranslatableMarkup('The name of the test entity.'))
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE)
|
||||
->setSetting('max_length', 32)
|
||||
->setDisplayOptions('view', [
|
||||
'label' => 'hidden',
|
||||
'type' => 'string',
|
||||
'weight' => -5,
|
||||
])
|
||||
->setDisplayOptions('form', [
|
||||
'type' => 'string_textfield',
|
||||
'weight' => -5,
|
||||
]);
|
||||
|
||||
$fields['test_single_property'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Field with a single property'))
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['test_multiple_properties'] = BaseFieldDefinition::create('multi_value_test')
|
||||
->setLabel(new TranslatableMarkup('Field with multiple properties'))
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['test_single_property_multiple_values'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Field with a single property and multiple values'))
|
||||
->setCardinality(2)
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['test_multiple_properties_multiple_values'] = BaseFieldDefinition::create('multi_value_test')
|
||||
->setLabel(new TranslatableMarkup('Field with multiple properties and multiple values'))
|
||||
->setCardinality(2)
|
||||
->setTranslatable(TRUE)
|
||||
->setRevisionable(TRUE);
|
||||
|
||||
$fields['test_non_rev_field'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Non Revisionable Field'))
|
||||
->setDescription(new TranslatableMarkup('A non-revisionable test field.'))
|
||||
->setCardinality(1)
|
||||
->setRevisionable(FALSE)
|
||||
->setTranslatable(TRUE);
|
||||
|
||||
$fields['test_non_mul_field'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Non Translatable Field'))
|
||||
->setDescription(new TranslatableMarkup('A non-translatable test field.'))
|
||||
->setCardinality(1)
|
||||
->setRevisionable(TRUE)
|
||||
->setTranslatable(FALSE);
|
||||
|
||||
$fields['test_non_mulrev_field'] = BaseFieldDefinition::create('string')
|
||||
->setLabel(new TranslatableMarkup('Non Revisionable and Translatable Field'))
|
||||
->setDescription(new TranslatableMarkup('A non-revisionable and non-translatable test field.'))
|
||||
->setCardinality(1)
|
||||
->setRevisionable(FALSE)
|
||||
->setTranslatable(FALSE);
|
||||
|
||||
$fields += \Drupal::state()->get('entity_test_update.additional_base_field_definitions', []);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function bundleFieldDefinitions(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
|
||||
$fields = parent::bundleFieldDefinitions($entity_type, $bundle, $base_field_definitions);
|
||||
$fields += \Drupal::state()->get('entity_test_update.additional_bundle_field_definitions.' . $bundle, []);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\entity_test;
|
||||
namespace Drupal\entity_test_update;
|
||||
|
||||
use Drupal\Core\Entity\ContentEntityTypeInterface;
|
||||
use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
|
||||
|
@ -9,7 +9,7 @@ use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
|||
/**
|
||||
* Defines the entity_test_update storage_schema handler.
|
||||
*/
|
||||
class EntityTestStorageSchema extends SqlContentEntityStorageSchema {
|
||||
class EntityTestUpdateStorageSchema extends SqlContentEntityStorageSchema {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -18,7 +18,7 @@ class EntityTestStorageSchema extends SqlContentEntityStorageSchema {
|
|||
$schema = parent::getEntitySchema($entity_type, $reset);
|
||||
|
||||
if ($entity_type->id() == 'entity_test_update') {
|
||||
$schema[$entity_type->getBaseTable()]['indexes'] += \Drupal::state()->get('entity_test_update.additional_entity_indexes', array());
|
||||
$schema[$entity_type->getBaseTable()]['indexes'] += \Drupal::state()->get('entity_test_update.additional_entity_indexes', []);
|
||||
}
|
||||
return $schema;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\entity_test_update\Plugin\Field\FieldType;
|
||||
|
||||
use Drupal\Core\Field\FieldStorageDefinitionInterface;
|
||||
use Drupal\Core\TypedData\DataDefinition;
|
||||
use Drupal\Core\Field\FieldItemBase;
|
||||
|
||||
/**
|
||||
* Defines the 'multi_value_test' field type.
|
||||
*
|
||||
* @FieldType(
|
||||
* id = "multi_value_test",
|
||||
* label = @Translation("Multiple values test"),
|
||||
* description = @Translation("Another dummy field type."),
|
||||
* )
|
||||
*/
|
||||
class MultiValueTestItem extends FieldItemBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
|
||||
$properties['value1'] = DataDefinition::create('string')
|
||||
->setLabel(t('First value'));
|
||||
|
||||
$properties['value2'] = DataDefinition::create('string')
|
||||
->setLabel(t('Second value'));
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function schema(FieldStorageDefinitionInterface $field_definition) {
|
||||
return [
|
||||
'columns' => [
|
||||
'value1' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
],
|
||||
'value2' => [
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isEmpty() {
|
||||
$item = $this->getValue();
|
||||
return empty($item['value1']) && empty($item['value2']);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function mainPropertyName() {
|
||||
return 'value1';
|
||||
}
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ class TestLog implements LoggerInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function log($level, $message, array $context = array()) {
|
||||
public function log($level, $message, array $context = []) {
|
||||
$trigger = [
|
||||
'%type' => 'Exception',
|
||||
'@message' => 'Deforestation',
|
||||
|
|
|
@ -41,49 +41,49 @@ function system_form_form_test_alter_form_alter(&$form, FormStateInterface $form
|
|||
* Create a header and options array. Helper function for callbacks.
|
||||
*/
|
||||
function _form_test_tableselect_get_data() {
|
||||
$header = array(
|
||||
$header = [
|
||||
'one' => t('One'),
|
||||
'two' => t('Two'),
|
||||
'three' => t('Three'),
|
||||
'four' => t('Four'),
|
||||
);
|
||||
];
|
||||
|
||||
$options['row1'] = array(
|
||||
'title' => array('data' => array('#title' => t('row1'))),
|
||||
$options['row1'] = [
|
||||
'title' => ['data' => ['#title' => t('row1')]],
|
||||
'one' => 'row1col1',
|
||||
'two' => t('row1col2'),
|
||||
'three' => t('row1col3'),
|
||||
'four' => t('row1col4'),
|
||||
);
|
||||
];
|
||||
|
||||
$options['row2'] = array(
|
||||
'title' => array('data' => array('#title' => t('row2'))),
|
||||
$options['row2'] = [
|
||||
'title' => ['data' => ['#title' => t('row2')]],
|
||||
'one' => 'row2col1',
|
||||
'two' => t('row2col2'),
|
||||
'three' => t('row2col3'),
|
||||
'four' => t('row2col4'),
|
||||
);
|
||||
];
|
||||
|
||||
$options['row3'] = array(
|
||||
'title' => array('data' => array('#title' => t('row3'))),
|
||||
$options['row3'] = [
|
||||
'title' => ['data' => ['#title' => t('row3')]],
|
||||
'one' => 'row3col1',
|
||||
'two' => t('row3col2'),
|
||||
'three' => t('row3col3'),
|
||||
'four' => t('row3col4'),
|
||||
);
|
||||
];
|
||||
|
||||
return array($header, $options);
|
||||
return [$header, $options];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter() for the registration form.
|
||||
*/
|
||||
function form_test_form_user_register_form_alter(&$form, FormStateInterface $form_state) {
|
||||
$form['test_rebuild'] = array(
|
||||
$form['test_rebuild'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Rebuild'),
|
||||
'#submit' => array('form_test_user_register_form_rebuild'),
|
||||
);
|
||||
'#submit' => ['form_test_user_register_form_rebuild'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -16,7 +16,7 @@ class AutocompleteController {
|
|||
* A JSON response.
|
||||
*/
|
||||
public function autocomplete1() {
|
||||
return new JsonResponse(array('key' => 'value'));
|
||||
return new JsonResponse(['key' => 'value']);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class Callbacks {
|
|||
|
||||
if ($triggered) {
|
||||
// Output the element's value from $form_state.
|
||||
drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name'))));
|
||||
drupal_set_message(t('@label value: @value', ['@label' => $element['#title'], '@value' => $form_state->getValue('name')]));
|
||||
|
||||
// Trigger a form validation error to see our changes.
|
||||
$form_state->setErrorByName('');
|
||||
|
|
|
@ -20,11 +20,11 @@ class ConfirmFormArrayPathTestForm extends ConfirmFormTestForm {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCancelUrl() {
|
||||
return new Url('form_test.route6', array(), array(
|
||||
'query' => array(
|
||||
return new Url('form_test.route6', [], [
|
||||
'query' => [
|
||||
'destination' => 'admin/config',
|
||||
),
|
||||
));
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,7 +57,7 @@ class ConfirmFormTestForm extends ConfirmFormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['element'] = array('#markup' => '<p>The ConfirmFormTestForm::buildForm() method was used for this form.</p>');
|
||||
$form['element'] = ['#markup' => '<p>The ConfirmFormTestForm::buildForm() method was used for this form.</p>'];
|
||||
|
||||
return parent::buildForm($form, $form_state);
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@ class FormTestController extends ControllerBase {
|
|||
*/
|
||||
public function twoFormInstances() {
|
||||
$user = $this->currentUser();
|
||||
$values = array(
|
||||
$values = [
|
||||
'uid' => $user->id(),
|
||||
'name' => $user->getUsername(),
|
||||
'type' => 'page',
|
||||
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
|
||||
);
|
||||
];
|
||||
$node1 = $this->entityManager()->getStorage('node')->create($values);
|
||||
$node2 = clone($node1);
|
||||
$return['node_form_1'] = $this->entityFormBuilder()->getForm($node1);
|
||||
|
|
|
@ -39,8 +39,8 @@ class FormTestEventSubscriber implements EventSubscriberInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
$events[KernelEvents::REQUEST][] = array('onKernelRequest');
|
||||
$events[KernelEvents::RESPONSE][] = array('onKernelResponse');
|
||||
$events[KernelEvents::REQUEST][] = ['onKernelRequest'];
|
||||
$events[KernelEvents::RESPONSE][] = ['onKernelResponse'];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,16 +21,16 @@ class FormTestButtonClassForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['button'] = array(
|
||||
$form['button'] = [
|
||||
'#type' => 'button',
|
||||
'#value' => 'test',
|
||||
'#button_type' => 'foo',
|
||||
);
|
||||
$form['delete'] = array(
|
||||
];
|
||||
$form['delete'] = [
|
||||
'#type' => 'button',
|
||||
'#value' => 'Delete',
|
||||
'#button_type' => 'danger',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,65 +20,65 @@ class FormTestCheckboxForm extends FormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
// A required checkbox.
|
||||
$form['required_checkbox'] = array(
|
||||
$form['required_checkbox'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#required' => TRUE,
|
||||
'#title' => 'required_checkbox',
|
||||
);
|
||||
];
|
||||
|
||||
// A disabled checkbox should get its default value back.
|
||||
$form['disabled_checkbox_on'] = array(
|
||||
$form['disabled_checkbox_on'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#disabled' => TRUE,
|
||||
'#return_value' => 'disabled_checkbox_on',
|
||||
'#default_value' => 'disabled_checkbox_on',
|
||||
'#title' => 'disabled_checkbox_on',
|
||||
);
|
||||
$form['disabled_checkbox_off'] = array(
|
||||
];
|
||||
$form['disabled_checkbox_off'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#disabled' => TRUE,
|
||||
'#return_value' => 'disabled_checkbox_off',
|
||||
'#default_value' => NULL,
|
||||
'#title' => 'disabled_checkbox_off',
|
||||
);
|
||||
];
|
||||
|
||||
// A checkbox is active when #default_value == #return_value.
|
||||
$form['checkbox_on'] = array(
|
||||
$form['checkbox_on'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#return_value' => 'checkbox_on',
|
||||
'#default_value' => 'checkbox_on',
|
||||
'#title' => 'checkbox_on',
|
||||
);
|
||||
];
|
||||
|
||||
// But inactive in any other case.
|
||||
$form['checkbox_off'] = array(
|
||||
$form['checkbox_off'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#return_value' => 'checkbox_off',
|
||||
'#default_value' => 'checkbox_on',
|
||||
'#title' => 'checkbox_off',
|
||||
);
|
||||
];
|
||||
|
||||
// Checkboxes with a #return_value of '0' are supported.
|
||||
$form['zero_checkbox_on'] = array(
|
||||
$form['zero_checkbox_on'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#return_value' => '0',
|
||||
'#default_value' => '0',
|
||||
'#title' => 'zero_checkbox_on',
|
||||
);
|
||||
];
|
||||
|
||||
// In that case, passing a #default_value != '0'
|
||||
// means that the checkbox is off.
|
||||
$form['zero_checkbox_off'] = array(
|
||||
$form['zero_checkbox_off'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#return_value' => '0',
|
||||
'#default_value' => '1',
|
||||
'#title' => 'zero_checkbox_off',
|
||||
);
|
||||
];
|
||||
|
||||
$form['submit'] = array(
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -21,12 +21,12 @@ class FormTestCheckboxTypeJugglingForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $default_value = NULL, $return_value = NULL) {
|
||||
$form['checkbox'] = array(
|
||||
$form['checkbox'] = [
|
||||
'#title' => t('Checkbox'),
|
||||
'#type' => 'checkbox',
|
||||
'#return_value' => $return_value,
|
||||
'#default_value' => $default_value,
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,53 +24,53 @@ class FormTestCheckboxesRadiosForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state, $customize = FALSE) {
|
||||
// Expand #type checkboxes, setting custom element properties for some but not
|
||||
// all options.
|
||||
$form['checkboxes'] = array(
|
||||
$form['checkboxes'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => 'Checkboxes',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
0 => 'Zero',
|
||||
'foo' => 'Foo',
|
||||
1 => 'One',
|
||||
'bar' => $this->t('<em>Bar - checkboxes</em>'),
|
||||
'>' => "<em>Special Char</em><script>alert('checkboxes');</script>",
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
if ($customize) {
|
||||
$form['checkboxes'] += array(
|
||||
'foo' => array(
|
||||
$form['checkboxes'] += [
|
||||
'foo' => [
|
||||
'#description' => 'Enable to foo.',
|
||||
),
|
||||
1 => array(
|
||||
],
|
||||
1 => [
|
||||
'#weight' => 10,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
// Expand #type radios, setting custom element properties for some but not
|
||||
// all options.
|
||||
$form['radios'] = array(
|
||||
$form['radios'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => 'Radios',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
0 => 'Zero',
|
||||
'foo' => 'Foo',
|
||||
1 => 'One',
|
||||
'bar' => '<em>Bar - radios</em>',
|
||||
'>' => "<em>Special Char</em><script>alert('radios');</script>",
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
if ($customize) {
|
||||
$form['radios'] += array(
|
||||
'foo' => array(
|
||||
$form['radios'] += [
|
||||
'foo' => [
|
||||
'#description' => 'Enable to foo.',
|
||||
),
|
||||
1 => array(
|
||||
],
|
||||
1 => [
|
||||
'#weight' => 10,
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$form['submit'] = array('#type' => 'submit', '#value' => 'Submit');
|
||||
$form['submit'] = ['#type' => 'submit', '#value' => 'Submit'];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -23,27 +23,27 @@ class FormTestCheckboxesZeroForm extends FormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $json = TRUE) {
|
||||
$form_state->set('json', $json);
|
||||
$form['checkbox_off'] = array(
|
||||
$form['checkbox_off'] = [
|
||||
'#title' => t('Checkbox off'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array('foo', 'bar', 'baz'),
|
||||
);
|
||||
$form['checkbox_zero_default'] = array(
|
||||
'#options' => ['foo', 'bar', 'baz'],
|
||||
];
|
||||
$form['checkbox_zero_default'] = [
|
||||
'#title' => t('Zero default'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array('foo', 'bar', 'baz'),
|
||||
'#default_value' => array(0),
|
||||
);
|
||||
$form['checkbox_string_zero_default'] = array(
|
||||
'#options' => ['foo', 'bar', 'baz'],
|
||||
'#default_value' => [0],
|
||||
];
|
||||
$form['checkbox_string_zero_default'] = [
|
||||
'#title' => t('Zero default (string)'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array('foo', 'bar', 'baz'),
|
||||
'#default_value' => array('0'),
|
||||
);
|
||||
$form['submit'] = array(
|
||||
'#options' => ['foo', 'bar', 'baz'],
|
||||
'#default_value' => ['0'],
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Save',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ class FormTestClickedButtonForm extends FormBase {
|
|||
// submitted without any information identifying the button responsible for
|
||||
// the submission. In other browsers, the form is submitted as though the
|
||||
// first button were clicked.
|
||||
$form['text'] = array(
|
||||
$form['text'] = [
|
||||
'#title' => 'Text',
|
||||
'#type' => 'textfield',
|
||||
);
|
||||
];
|
||||
|
||||
// Loop through each path argument, adding buttons based on the information
|
||||
// in the argument. For example, if the path is
|
||||
|
@ -37,7 +37,7 @@ class FormTestClickedButtonForm extends FormBase {
|
|||
// 'image_button', and a 'button' with #access=FALSE. This enables form.test
|
||||
// to test a variety of combinations.
|
||||
$i = 0;
|
||||
$args = array($first, $second, $third);
|
||||
$args = [$first, $second, $third];
|
||||
foreach ($args as $arg) {
|
||||
$name = 'button' . ++$i;
|
||||
// 's', 'b', or 'i' in the argument define the button type wanted.
|
||||
|
@ -54,10 +54,10 @@ class FormTestClickedButtonForm extends FormBase {
|
|||
$type = NULL;
|
||||
}
|
||||
if (isset($type)) {
|
||||
$form[$name] = array(
|
||||
$form[$name] = [
|
||||
'#type' => $type,
|
||||
'#name' => $name,
|
||||
);
|
||||
];
|
||||
// Image buttons need a #src; the others need a #value.
|
||||
if ($type == 'image_button') {
|
||||
$form[$name]['#src'] = 'core/misc/druplicon.png';
|
||||
|
|
|
@ -22,14 +22,14 @@ class FormTestColorForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['color'] = array(
|
||||
$form['color'] = [
|
||||
'#type' => 'color',
|
||||
'#title' => 'Color',
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Submit',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,26 +23,26 @@ class FormTestDescriptionForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['form_textfield_test_description_before'] = array(
|
||||
$form['form_textfield_test_description_before'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Textfield test for description before element',
|
||||
'#description' => 'Textfield test for description before element',
|
||||
'#description_display' => 'before',
|
||||
);
|
||||
];
|
||||
|
||||
$form['form_textfield_test_description_after'] = array(
|
||||
$form['form_textfield_test_description_after'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Textfield test for description after element',
|
||||
'#description' => 'Textfield test for description after element',
|
||||
'#description_display' => 'after',
|
||||
);
|
||||
];
|
||||
|
||||
$form['form_textfield_test_description_invisible'] = array(
|
||||
$form['form_textfield_test_description_invisible'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Textfield test for visually-hidden description',
|
||||
'#description' => 'Textfield test for visually-hidden description',
|
||||
'#description_display' => 'invisible',
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -24,101 +24,101 @@ class FormTestDisabledElementsForm extends FormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
// Elements that take a simple default value.
|
||||
foreach (array('textfield', 'textarea', 'search', 'tel', 'hidden') as $type) {
|
||||
$form[$type] = array(
|
||||
foreach (['textfield', 'textarea', 'search', 'tel', 'hidden'] as $type) {
|
||||
$form[$type] = [
|
||||
'#type' => $type,
|
||||
'#title' => $type,
|
||||
'#default_value' => $type,
|
||||
'#test_hijack_value' => 'HIJACK',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Multiple values option elements.
|
||||
foreach (array('checkboxes', 'select') as $type) {
|
||||
$form[$type . '_multiple'] = array(
|
||||
foreach (['checkboxes', 'select'] as $type) {
|
||||
$form[$type . '_multiple'] = [
|
||||
'#type' => $type,
|
||||
'#title' => $type . ' (multiple)',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'test_1' => 'Test 1',
|
||||
'test_2' => 'Test 2',
|
||||
),
|
||||
],
|
||||
'#multiple' => TRUE,
|
||||
'#default_value' => array('test_2' => 'test_2'),
|
||||
'#default_value' => ['test_2' => 'test_2'],
|
||||
// The keys of #test_hijack_value need to match the #name of the control.
|
||||
// @see FormsTestCase::testDisabledElements()
|
||||
'#test_hijack_value' => $type == 'select' ? array('' => 'test_1') : array('test_1' => 'test_1'),
|
||||
'#test_hijack_value' => $type == 'select' ? ['' => 'test_1'] : ['test_1' => 'test_1'],
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Single values option elements.
|
||||
foreach (array('radios', 'select') as $type) {
|
||||
$form[$type . '_single'] = array(
|
||||
foreach (['radios', 'select'] as $type) {
|
||||
$form[$type . '_single'] = [
|
||||
'#type' => $type,
|
||||
'#title' => $type . ' (single)',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'test_1' => 'Test 1',
|
||||
'test_2' => 'Test 2',
|
||||
),
|
||||
],
|
||||
'#multiple' => FALSE,
|
||||
'#default_value' => 'test_2',
|
||||
'#test_hijack_value' => 'test_1',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Checkbox and radio.
|
||||
foreach (array('checkbox', 'radio') as $type) {
|
||||
$form[$type . '_unchecked'] = array(
|
||||
foreach (['checkbox', 'radio'] as $type) {
|
||||
$form[$type . '_unchecked'] = [
|
||||
'#type' => $type,
|
||||
'#title' => $type . ' (unchecked)',
|
||||
'#return_value' => 1,
|
||||
'#default_value' => 0,
|
||||
'#test_hijack_value' => 1,
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
$form[$type . '_checked'] = array(
|
||||
];
|
||||
$form[$type . '_checked'] = [
|
||||
'#type' => $type,
|
||||
'#title' => $type . ' (checked)',
|
||||
'#return_value' => 1,
|
||||
'#default_value' => 1,
|
||||
'#test_hijack_value' => NULL,
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Weight, number, range.
|
||||
foreach (array('weight', 'number', 'range') as $type) {
|
||||
$form[$type] = array(
|
||||
foreach (['weight', 'number', 'range'] as $type) {
|
||||
$form[$type] = [
|
||||
'#type' => $type,
|
||||
'#title' => $type,
|
||||
'#default_value' => 10,
|
||||
'#test_hijack_value' => 5,
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Color.
|
||||
$form['color'] = array(
|
||||
$form['color'] = [
|
||||
'#type' => 'color',
|
||||
'#title' => 'color',
|
||||
'#default_value' => '#0000ff',
|
||||
'#test_hijack_value' => '#ff0000',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
// The #disabled state should propagate to children.
|
||||
$form['disabled_container'] = array(
|
||||
$form['disabled_container'] = [
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
foreach (array('textfield', 'textarea', 'hidden', 'tel', 'url') as $type) {
|
||||
$form['disabled_container']['disabled_container_' . $type] = array(
|
||||
];
|
||||
foreach (['textfield', 'textarea', 'hidden', 'tel', 'url'] as $type) {
|
||||
$form['disabled_container']['disabled_container_' . $type] = [
|
||||
'#type' => $type,
|
||||
'#title' => $type,
|
||||
'#default_value' => $type,
|
||||
'#test_hijack_value' => 'HIJACK',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
// Date.
|
||||
|
@ -128,103 +128,103 @@ class FormTestDisabledElementsForm extends FormBase {
|
|||
// versions by encoding and decoding it again instead of hardcoding it.
|
||||
// See https://github.com/php/php-src/commit/fdb2709dd27c5987c2d2c8aaf0cdbebf9f17f643
|
||||
$expected = json_decode(json_encode($date), TRUE);
|
||||
$form['disabled_container']['disabled_container_datetime'] = array(
|
||||
$form['disabled_container']['disabled_container_datetime'] = [
|
||||
'#type' => 'datetime',
|
||||
'#title' => 'datetime',
|
||||
'#default_value' => $date,
|
||||
'#expected_value' => $expected,
|
||||
'#test_hijack_value' => new DrupalDateTime('1978-12-02 11:30:00', 'Europe/Berlin'),
|
||||
'#date_timezone' => 'Europe/Berlin',
|
||||
);
|
||||
];
|
||||
|
||||
$form['disabled_container']['disabled_container_date'] = array(
|
||||
$form['disabled_container']['disabled_container_date'] = [
|
||||
'#type' => 'date',
|
||||
'#title' => 'date',
|
||||
'#default_value' => '2001-01-13',
|
||||
'#expected_value' => '2001-01-13',
|
||||
'#test_hijack_value' => '2013-01-01',
|
||||
'#date_timezone' => 'Europe/Berlin',
|
||||
);
|
||||
];
|
||||
|
||||
|
||||
// Try to hijack the email field with a valid email.
|
||||
$form['disabled_container']['disabled_container_email'] = array(
|
||||
$form['disabled_container']['disabled_container_email'] = [
|
||||
'#type' => 'email',
|
||||
'#title' => 'email',
|
||||
'#default_value' => 'foo@example.com',
|
||||
'#test_hijack_value' => 'bar@example.com',
|
||||
);
|
||||
];
|
||||
|
||||
// Try to hijack the URL field with a valid URL.
|
||||
$form['disabled_container']['disabled_container_url'] = array(
|
||||
$form['disabled_container']['disabled_container_url'] = [
|
||||
'#type' => 'url',
|
||||
'#title' => 'url',
|
||||
'#default_value' => 'http://example.com',
|
||||
'#test_hijack_value' => 'http://example.com/foo',
|
||||
);
|
||||
];
|
||||
|
||||
// Text format.
|
||||
$form['text_format'] = array(
|
||||
$form['text_format'] = [
|
||||
'#type' => 'text_format',
|
||||
'#title' => 'Text format',
|
||||
'#disabled' => TRUE,
|
||||
'#default_value' => 'Text value',
|
||||
'#format' => 'plain_text',
|
||||
'#expected_value' => array(
|
||||
'#expected_value' => [
|
||||
'value' => 'Text value',
|
||||
'format' => 'plain_text',
|
||||
),
|
||||
'#test_hijack_value' => array(
|
||||
],
|
||||
'#test_hijack_value' => [
|
||||
'value' => 'HIJACK',
|
||||
'format' => 'filtered_html',
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
// Password fields.
|
||||
$form['password'] = array(
|
||||
$form['password'] = [
|
||||
'#type' => 'password',
|
||||
'#title' => 'Password',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
$form['password_confirm'] = array(
|
||||
];
|
||||
$form['password_confirm'] = [
|
||||
'#type' => 'password_confirm',
|
||||
'#title' => 'Password confirm',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
// Files.
|
||||
$form['file'] = array(
|
||||
$form['file'] = [
|
||||
'#type' => 'file',
|
||||
'#title' => 'File',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
$form['managed_file'] = array(
|
||||
];
|
||||
$form['managed_file'] = [
|
||||
'#type' => 'managed_file',
|
||||
'#title' => 'Managed file',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
// Buttons.
|
||||
$form['image_button'] = array(
|
||||
$form['image_button'] = [
|
||||
'#type' => 'image_button',
|
||||
'#value' => 'Image button',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
$form['button'] = array(
|
||||
];
|
||||
$form['button'] = [
|
||||
'#type' => 'button',
|
||||
'#value' => 'Button',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
$form['submit_disabled'] = array(
|
||||
];
|
||||
$form['submit_disabled'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Submit',
|
||||
'#disabled' => TRUE,
|
||||
);
|
||||
];
|
||||
|
||||
$form['submit'] = array(
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -22,21 +22,21 @@ class FormTestEmailForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['email'] = array(
|
||||
$form['email'] = [
|
||||
'#type' => 'email',
|
||||
'#title' => 'Email address',
|
||||
'#description' => 'An email address.',
|
||||
);
|
||||
$form['email_required'] = array(
|
||||
];
|
||||
$form['email_required'] = [
|
||||
'#type' => 'email',
|
||||
'#title' => 'Address',
|
||||
'#required' => TRUE,
|
||||
'#description' => 'A required email address field.',
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => 'Submit',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,12 +21,12 @@ class FormTestEmptySelectForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['empty_select'] = array(
|
||||
$form['empty_select'] = [
|
||||
'#type' => 'select',
|
||||
'#title' => t('Empty Select'),
|
||||
'#multiple' => FALSE,
|
||||
'#options' => NULL,
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,16 +22,16 @@ class FormTestFormStateValuesCleanAdvancedForm extends FormBase {
|
|||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
// Build an example form containing a managed file and a submit form element.
|
||||
$form['image'] = array(
|
||||
$form['image'] = [
|
||||
'#type' => 'managed_file',
|
||||
'#title' => t('Image'),
|
||||
'#upload_location' => 'public://',
|
||||
'#default_value' => 0,
|
||||
);
|
||||
$form['submit'] = array(
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,13 +24,13 @@ class FormTestFormStateValuesCleanForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
// Build an example form containing multiple submit and button elements; not
|
||||
// only on the top-level.
|
||||
$form = array('#tree' => TRUE);
|
||||
$form['foo'] = array('#type' => 'submit', '#value' => t('Submit'));
|
||||
$form['bar'] = array('#type' => 'submit', '#value' => t('Submit'));
|
||||
$form['beer'] = array('#type' => 'value', '#value' => 1000);
|
||||
$form['baz']['foo'] = array('#type' => 'button', '#value' => t('Submit'));
|
||||
$form['baz']['baz'] = array('#type' => 'submit', '#value' => t('Submit'));
|
||||
$form['baz']['beer'] = array('#type' => 'value', '#value' => 2000);
|
||||
$form = ['#tree' => TRUE];
|
||||
$form['foo'] = ['#type' => 'submit', '#value' => t('Submit')];
|
||||
$form['bar'] = ['#type' => 'submit', '#value' => t('Submit')];
|
||||
$form['beer'] = ['#type' => 'value', '#value' => 1000];
|
||||
$form['baz']['foo'] = ['#type' => 'button', '#value' => t('Submit')];
|
||||
$form['baz']['baz'] = ['#type' => 'submit', '#value' => t('Submit')];
|
||||
$form['baz']['beer'] = ['#type' => 'value', '#value' => 2000];
|
||||
|
||||
// Add an arbitrary element and manually set it to be cleaned.
|
||||
// Using $form_state->addCleanValueKey('wine'); didn't work here.
|
||||
|
|
|
@ -21,19 +21,19 @@ class FormTestGroupContainerForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['container'] = array(
|
||||
$form['container'] = [
|
||||
'#type' => 'container',
|
||||
);
|
||||
$form['meta'] = array(
|
||||
];
|
||||
$form['meta'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => 'Group element',
|
||||
'#open' => TRUE,
|
||||
'#group' => 'container',
|
||||
);
|
||||
$form['meta']['element'] = array(
|
||||
];
|
||||
$form['meta']['element'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Nest in details element',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,22 +21,22 @@ class FormTestGroupDetailsForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $required = FALSE) {
|
||||
$form['details'] = array(
|
||||
$form['details'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => 'Root element',
|
||||
'#open' => TRUE,
|
||||
'#required' => !empty($required),
|
||||
);
|
||||
$form['meta'] = array(
|
||||
];
|
||||
$form['meta'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => 'Group element',
|
||||
'#open' => TRUE,
|
||||
'#group' => 'details',
|
||||
);
|
||||
$form['meta']['element'] = array(
|
||||
];
|
||||
$form['meta']['element'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Nest in details element',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,20 +21,20 @@ class FormTestGroupFieldsetForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state, $required = FALSE) {
|
||||
$form['fieldset'] = array(
|
||||
$form['fieldset'] = [
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Fieldset',
|
||||
'#required' => !empty($required),
|
||||
);
|
||||
$form['meta'] = array(
|
||||
];
|
||||
$form['meta'] = [
|
||||
'#type' => 'container',
|
||||
'#title' => 'Group element',
|
||||
'#group' => 'fieldset',
|
||||
);
|
||||
$form['meta']['element'] = array(
|
||||
];
|
||||
$form['meta']['element'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Nest in container element',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,27 +21,27 @@ class FormTestGroupVerticalTabsForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['vertical_tabs'] = array(
|
||||
$form['vertical_tabs'] = [
|
||||
'#type' => 'vertical_tabs',
|
||||
);
|
||||
$form['meta'] = array(
|
||||
];
|
||||
$form['meta'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => 'First group element',
|
||||
'#group' => 'vertical_tabs',
|
||||
);
|
||||
$form['meta']['element'] = array(
|
||||
];
|
||||
$form['meta']['element'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'First nested element in details element',
|
||||
);
|
||||
$form['meta_2'] = array(
|
||||
];
|
||||
$form['meta_2'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => 'Second group element',
|
||||
'#group' => 'vertical_tabs',
|
||||
);
|
||||
$form['meta_2']['element_2'] = array(
|
||||
];
|
||||
$form['meta_2']['element_2'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Second nested element in details element',
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,18 +21,18 @@ class FormTestInputForgeryForm extends FormBase {
|
|||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
// For testing that a user can't submit a value not matching one of the
|
||||
// allowed options.
|
||||
$form['checkboxes'] = array(
|
||||
$form['checkboxes'] = [
|
||||
'#title' => t('Checkboxes'),
|
||||
'#type' => 'checkboxes',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'one' => 'One',
|
||||
'two' => 'Two',
|
||||
),
|
||||
);
|
||||
$form['submit'] = array(
|
||||
],
|
||||
];
|
||||
$form['submit'] = [
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Submit'),
|
||||
);
|
||||
];
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
|
|
@ -21,108 +21,108 @@ class FormTestLabelForm extends FormBase {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(array $form, FormStateInterface $form_state) {
|
||||
$form['form_checkboxes_test'] = array(
|
||||
$form['form_checkboxes_test'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Checkboxes test'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'first-checkbox' => t('First checkbox'),
|
||||
'second-checkbox' => t('Second checkbox'),
|
||||
'third-checkbox' => t('Third checkbox'),
|
||||
'0' => t('0'),
|
||||
),
|
||||
);
|
||||
$form['form_radios_test'] = array(
|
||||
],
|
||||
];
|
||||
$form['form_radios_test'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Radios test'),
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'first-radio' => t('First radio'),
|
||||
'second-radio' => t('Second radio'),
|
||||
'third-radio' => t('Third radio'),
|
||||
'0' => t('0'),
|
||||
),
|
||||
],
|
||||
// Test #field_prefix and #field_suffix placement.
|
||||
'#field_prefix' => '<span id="form-test-radios-field-prefix">' . t('Radios #field_prefix element') . '</span>',
|
||||
'#field_suffix' => '<span id="form-test-radios-field-suffix">' . t('Radios #field_suffix element') . '</span>',
|
||||
);
|
||||
$form['form_checkbox_test'] = array(
|
||||
];
|
||||
$form['form_checkbox_test'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Checkbox test'),
|
||||
);
|
||||
$form['form_textfield_test_title_and_required'] = array(
|
||||
];
|
||||
$form['form_textfield_test_title_and_required'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Textfield test for required with title'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['form_textfield_test_no_title_required'] = array(
|
||||
];
|
||||
$form['form_textfield_test_no_title_required'] = [
|
||||
'#type' => 'textfield',
|
||||
// We use an empty title, since not setting #title suppresses the label
|
||||
// and required marker.
|
||||
'#title' => '',
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['form_textfield_test_title'] = array(
|
||||
];
|
||||
$form['form_textfield_test_title'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Textfield test for title only'),
|
||||
// Not required.
|
||||
// Test #prefix and #suffix placement.
|
||||
'#prefix' => '<div id="form-test-textfield-title-prefix">' . t('Textfield #prefix element') . '</div>',
|
||||
'#suffix' => '<div id="form-test-textfield-title-suffix">' . t('Textfield #suffix element') . '</div>',
|
||||
);
|
||||
$form['form_textfield_test_title_after'] = array(
|
||||
];
|
||||
$form['form_textfield_test_title_after'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Textfield test for title after element'),
|
||||
'#title_display' => 'after',
|
||||
);
|
||||
$form['form_textfield_test_title_invisible'] = array(
|
||||
];
|
||||
$form['form_textfield_test_title_invisible'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Textfield test for invisible title'),
|
||||
'#title_display' => 'invisible',
|
||||
);
|
||||
];
|
||||
// Textfield test for title set not to display.
|
||||
$form['form_textfield_test_title_no_show'] = array(
|
||||
$form['form_textfield_test_title_no_show'] = [
|
||||
'#type' => 'textfield',
|
||||
);
|
||||
];
|
||||
// Checkboxes & radios with title as attribute.
|
||||
$form['form_checkboxes_title_attribute'] = array(
|
||||
$form['form_checkboxes_title_attribute'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => 'Checkboxes test',
|
||||
'#title_display' => 'attribute',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'first-checkbox' => 'First checkbox',
|
||||
'second-checkbox' => 'Second checkbox',
|
||||
),
|
||||
],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['form_radios_title_attribute'] = array(
|
||||
];
|
||||
$form['form_radios_title_attribute'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => 'Radios test',
|
||||
'#title_display' => 'attribute',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'first-radio' => 'First radio',
|
||||
'second-radio' => 'Second radio',
|
||||
),
|
||||
],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['form_checkboxes_title_invisible'] = array(
|
||||
];
|
||||
$form['form_checkboxes_title_invisible'] = [
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => 'Checkboxes test invisible',
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'first-checkbox' => 'First checkbox',
|
||||
'second-checkbox' => 'Second checkbox',
|
||||
),
|
||||
],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['form_radios_title_invisible'] = array(
|
||||
];
|
||||
$form['form_radios_title_invisible'] = [
|
||||
'#type' => 'radios',
|
||||
'#title' => 'Radios test invisible',
|
||||
'#title_display' => 'invisible',
|
||||
'#options' => array(
|
||||
'#options' => [
|
||||
'first-radio' => 'First radio',
|
||||
'second-radio' => 'Second radio',
|
||||
),
|
||||
],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue