Update Composer, update everything
This commit is contained in:
parent
ea3e94409f
commit
dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions
|
@ -5,4 +5,4 @@ package: Core (Experimental)
|
|||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- layout_discovery
|
||||
- drupal:layout_discovery
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
use Drupal\Core\Cache\Cache;
|
||||
use Drupal\Core\Entity\Display\EntityDisplayInterface;
|
||||
use Drupal\Core\Entity\Entity\EntityFormDisplay;
|
||||
use Drupal\Core\Entity\Entity\EntityViewDisplay;
|
||||
use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface;
|
||||
|
@ -15,8 +16,10 @@ use Drupal\field_layout\Display\EntityDisplayWithLayoutInterface;
|
|||
*/
|
||||
function field_layout_install() {
|
||||
// Ensure each entity display has a layout.
|
||||
$entity_save = function (EntityDisplayWithLayoutInterface $entity) {
|
||||
$entity->ensureLayout()->save();
|
||||
$entity_save = function (EntityDisplayInterface $entity) {
|
||||
if ($entity instanceof EntityDisplayWithLayoutInterface) {
|
||||
$entity->ensureLayout()->save();
|
||||
}
|
||||
};
|
||||
array_map($entity_save, EntityViewDisplay::loadMultiple());
|
||||
array_map($entity_save, EntityFormDisplay::loadMultiple());
|
||||
|
@ -31,8 +34,10 @@ function field_layout_install() {
|
|||
function field_layout_uninstall() {
|
||||
// Reset each entity display to use the one-column layout to best approximate
|
||||
// the absence of layouts.
|
||||
$entity_save = function (EntityDisplayWithLayoutInterface $entity) {
|
||||
$entity->setLayoutId('layout_onecol')->save();
|
||||
$entity_save = function (EntityDisplayInterface $entity) {
|
||||
if ($entity instanceof EntityDisplayWithLayoutInterface) {
|
||||
$entity->setLayoutId('layout_onecol')->save();
|
||||
}
|
||||
};
|
||||
array_map($entity_save, EntityViewDisplay::loadMultiple());
|
||||
array_map($entity_save, EntityFormDisplay::loadMultiple());
|
||||
|
|
|
@ -50,8 +50,7 @@ function field_layout_entity_type_alter(array &$entity_types) {
|
|||
*/
|
||||
function field_layout_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
|
||||
if ($display instanceof EntityDisplayWithLayoutInterface) {
|
||||
\Drupal::classResolver()->getInstanceFromDefinition(FieldLayoutBuilder::class)
|
||||
->buildView($build, $display);
|
||||
\Drupal::classResolver(FieldLayoutBuilder::class)->buildView($build, $display);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,8 +61,7 @@ function field_layout_form_alter(&$form, FormStateInterface $form_state, $form_i
|
|||
$form_object = $form_state->getFormObject();
|
||||
if ($form_object instanceof ContentEntityFormInterface && $display = $form_object->getFormDisplay($form_state)) {
|
||||
if ($display instanceof EntityDisplayWithLayoutInterface) {
|
||||
\Drupal::classResolver()->getInstanceFromDefinition(FieldLayoutBuilder::class)
|
||||
->buildForm($form, $display);
|
||||
\Drupal::classResolver(FieldLayoutBuilder::class)->buildForm($form, $display);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,12 +67,15 @@ class FieldLayoutBuilder implements ContainerInjectionInterface {
|
|||
$regions = array_fill_keys($layout_definition->getRegionNames(), []);
|
||||
|
||||
foreach ($fields as $name => $field) {
|
||||
// Move the field from the top-level of $build into a region-specific
|
||||
// section.
|
||||
// If the region is controlled by the layout, move the field from the
|
||||
// top-level of $build into a region-specific section. Custom regions
|
||||
// could be set by other code at run-time; these should be ignored.
|
||||
// @todo Ideally the array structure would remain unchanged, see
|
||||
// https://www.drupal.org/node/2846393.
|
||||
$regions[$field['region']][$name] = $build[$name];
|
||||
unset($build[$name]);
|
||||
if (isset($regions[$field['region']])) {
|
||||
$regions[$field['region']][$name] = $build[$name];
|
||||
unset($build[$name]);
|
||||
}
|
||||
}
|
||||
// Ensure this will not conflict with any existing array elements by
|
||||
// prefixing with an underscore.
|
||||
|
@ -103,7 +106,7 @@ class FieldLayoutBuilder implements ContainerInjectionInterface {
|
|||
// avoids breaking hook_form_alter() implementations by not actually
|
||||
// moving the field in the form structure. If a #group is already set,
|
||||
// do not overwrite it.
|
||||
if (!isset($build[$name]['#group'])) {
|
||||
if (isset($regions[$field['region']]) && !isset($build[$name]['#group'])) {
|
||||
$build[$name]['#group'] = $field['region'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,8 @@ trait FieldLayoutEntityDisplayFormTrait {
|
|||
'#tree' => TRUE,
|
||||
];
|
||||
|
||||
$form['field_layouts']['settings_wrapper']['icon'] = $layout_plugin->getPluginDefinition()->getIcon();
|
||||
|
||||
if ($layout_plugin instanceof PluginFormInterface) {
|
||||
$form['field_layouts']['settings_wrapper']['layout_settings'] = [];
|
||||
$subform_state = SubformState::createForSubform($form['field_layouts']['settings_wrapper']['layout_settings'], $form, $form_state);
|
||||
|
|
|
@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Edit form for the EntityFormDisplay entity type.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class FieldLayoutEntityFormDisplayEditForm extends EntityFormDisplayEditForm {
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
|||
|
||||
/**
|
||||
* Edit form for the EntityViewDisplay entity type.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class FieldLayoutEntityViewDisplayEditForm extends EntityViewDisplayEditForm {
|
||||
|
||||
|
|
|
@ -5,4 +5,4 @@ core: 8.x
|
|||
package: Testing
|
||||
version: VERSION
|
||||
dependencies:
|
||||
- entity_test
|
||||
- drupal:entity_test
|
||||
|
|
|
@ -28,9 +28,9 @@ class FieldLayoutTest extends BrowserTestBase {
|
|||
$this->createNode([
|
||||
'type' => 'article',
|
||||
'title' => 'The node title',
|
||||
'body' => [[
|
||||
'value' => 'The node body',
|
||||
]],
|
||||
'body' => [
|
||||
['value' => 'The node body'],
|
||||
],
|
||||
]);
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
'access administration pages',
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
namespace Drupal\Tests\field_layout\FunctionalJavascript;
|
||||
|
||||
use Drupal\entity_test\Entity\EntityTest;
|
||||
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
|
||||
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
|
||||
|
||||
/**
|
||||
* Tests using field layout for entity displays.
|
||||
*
|
||||
* @group field_layout
|
||||
*/
|
||||
class FieldLayoutTest extends JavascriptTestBase {
|
||||
class FieldLayoutTest extends WebDriverTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -25,9 +25,9 @@ class FieldLayoutTest extends JavascriptTestBase {
|
|||
|
||||
$entity = EntityTest::create([
|
||||
'name' => 'The name for this entity',
|
||||
'field_test_text' => [[
|
||||
'value' => 'The field test text value',
|
||||
]],
|
||||
'field_test_text' => [
|
||||
['value' => 'The field test text value'],
|
||||
],
|
||||
]);
|
||||
$entity->save();
|
||||
$this->drupalLogin($this->drupalCreateUser([
|
||||
|
@ -100,12 +100,15 @@ class FieldLayoutTest extends JavascriptTestBase {
|
|||
// After a refresh the new regions are still there.
|
||||
$this->drupalGet('entity_test/structure/entity_test/form-display');
|
||||
$this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles());
|
||||
$this->assertSession()->waitForElement('css', '.tabledrag-handle');
|
||||
$id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();
|
||||
|
||||
// Drag the field to the second region.
|
||||
$field_test_text_row = $this->getSession()->getPage()->find('css', '#field-test-text');
|
||||
$second_region_row = $this->getSession()->getPage()->find('css', '.region-second-message');
|
||||
$field_test_text_row->find('css', '.handle')->dragTo($second_region_row);
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
$this->assertSession()->waitForElement('css', "[name='form_build_id']:not([value='$id'])");
|
||||
$this->submitForm([], 'Save');
|
||||
$this->assertSession()->pageTextContains('Your settings have been saved.');
|
||||
|
||||
|
@ -158,6 +161,8 @@ class FieldLayoutTest extends JavascriptTestBase {
|
|||
// After a refresh the new regions are still there.
|
||||
$this->drupalGet('entity_test/structure/entity_test/display');
|
||||
$this->assertEquals(['Top', 'First', 'Second', 'Bottom', 'Disabled'], $this->getRegionTitles());
|
||||
$this->assertSession()->waitForElement('css', '.tabledrag-handle');
|
||||
$id = $this->getSession()->getPage()->find('css', '[name="form_build_id"]')->getValue();
|
||||
|
||||
// Drag the field to the first region.
|
||||
$this->assertTrue($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
|
||||
|
@ -166,6 +171,7 @@ class FieldLayoutTest extends JavascriptTestBase {
|
|||
$field_test_text_row->find('css', '.handle')->dragTo($first_region_row);
|
||||
$this->assertSession()->assertWaitOnAjaxRequest();
|
||||
$this->assertFalse($this->assertSession()->optionExists('fields[field_test_text][region]', 'hidden')->isSelected());
|
||||
$this->assertSession()->waitForElement('css', "[name='form_build_id']:not([value='$id'])");
|
||||
$this->submitForm([], 'Save');
|
||||
$this->assertSession()->pageTextContains('Your settings have been saved.');
|
||||
|
||||
|
@ -233,6 +239,40 @@ class FieldLayoutTest extends JavascriptTestBase {
|
|||
$this->assertSession()->pageTextContains('Blah: Test text');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests changing the formatter and region at the same time.
|
||||
*/
|
||||
public function testChangingFormatterAndRegion() {
|
||||
$assert_session = $this->assertSession();
|
||||
$page = $this->getSession()->getPage();
|
||||
|
||||
// Add the test field to the content region.
|
||||
$this->drupalGet('entity_test/structure/entity_test/display');
|
||||
$page->find('css', '#field-test-text .handle')->dragTo($page->find('css', '.region-content-message'));
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
$page->pressButton('Save');
|
||||
$assert_session->fieldValueEquals('fields[field_test_text][region]', 'content');
|
||||
$assert_session->fieldValueEquals('fields[field_test_text][type]', 'text_default');
|
||||
|
||||
// Switch the layout to two columns.
|
||||
$this->click('#edit-field-layouts');
|
||||
$page->selectFieldOption('field_layout', 'layout_twocol');
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
$page->pressButton('Save');
|
||||
$assert_session->fieldValueEquals('fields[field_test_text][region]', 'first');
|
||||
|
||||
// Change the formatter and move to another region.
|
||||
$page->selectFieldOption('fields[field_test_text][type]', 'text_trimmed');
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
$page->find('css', '#field-test-text .handle')->dragTo($page->find('css', '.region-second-message'));
|
||||
$assert_session->assertWaitOnAjaxRequest();
|
||||
$page->pressButton('Save');
|
||||
|
||||
// Assert that both the formatter and region change are persisted.
|
||||
$assert_session->fieldValueEquals('fields[field_test_text][region]', 'second');
|
||||
$assert_session->fieldValueEquals('fields[field_test_text][type]', 'text_trimmed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the region titles on the page.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\field_layout\Kernel;
|
||||
|
||||
use Drupal\Tests\layout_builder\Kernel\LayoutBuilderCompatibilityTestBase;
|
||||
|
||||
/**
|
||||
* @group field_layout
|
||||
*/
|
||||
class FieldLayoutUninstallTest extends LayoutBuilderCompatibilityTestBase {
|
||||
|
||||
/**
|
||||
* Ensures field layout can be uninstalled with layout builder enabled.
|
||||
*/
|
||||
public function testFieldLayoutUninstall() {
|
||||
// Setup user schema so user hook uninstall hook doesn't break.
|
||||
$this->installSchema('user', 'users_data');
|
||||
|
||||
// Setup layout builder and same displays.
|
||||
$this->installLayoutBuilder();
|
||||
|
||||
// Ensure install hook can handle displays without a layout.
|
||||
$this->container->get('module_installer')->install(['field_layout']);
|
||||
|
||||
// Ensure uninstall hook can handle displays without a layout.
|
||||
$this->container->get('module_installer')->uninstall(['field_layout']);
|
||||
}
|
||||
|
||||
}
|
|
@ -93,6 +93,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
|
|||
'test1' => [
|
||||
'#markup' => 'Test1',
|
||||
],
|
||||
'test2' => [
|
||||
'#markup' => 'Test2',
|
||||
],
|
||||
'non_configurable_field' => [
|
||||
'#markup' => 'Non-configurable',
|
||||
],
|
||||
|
@ -111,6 +114,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
|
|||
'test1' => [
|
||||
'region' => 'right',
|
||||
],
|
||||
'test2' => [
|
||||
'region' => 'unknown_region',
|
||||
],
|
||||
'non_configurable_field' => [
|
||||
'region' => 'left',
|
||||
],
|
||||
|
@ -120,6 +126,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
|
|||
]);
|
||||
|
||||
$expected = [
|
||||
'test2' => [
|
||||
'#markup' => 'Test2',
|
||||
],
|
||||
'non_configurable_field' => [
|
||||
'#markup' => 'Non-configurable',
|
||||
],
|
||||
|
@ -169,6 +178,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
|
|||
'#markup' => 'Test2',
|
||||
'#group' => 'existing_group',
|
||||
],
|
||||
'test3' => [
|
||||
'#markup' => 'Test3',
|
||||
],
|
||||
'field_layout' => [
|
||||
'#markup' => 'Field created through the UI happens to be named "Layout"',
|
||||
],
|
||||
|
@ -190,6 +202,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
|
|||
'test2' => [
|
||||
'region' => 'left',
|
||||
],
|
||||
'test3' => [
|
||||
'region' => 'unknown_region',
|
||||
],
|
||||
'field_layout' => [
|
||||
'region' => 'right',
|
||||
],
|
||||
|
@ -207,6 +222,9 @@ class FieldLayoutBuilderTest extends UnitTestCase {
|
|||
'#markup' => 'Test2',
|
||||
'#group' => 'existing_group',
|
||||
],
|
||||
'test3' => [
|
||||
'#markup' => 'Test3',
|
||||
],
|
||||
'field_layout' => [
|
||||
'#markup' => 'Field created through the UI happens to be named "Layout"',
|
||||
'#group' => 'right',
|
||||
|
|
Reference in a new issue