Skip to content
Snippets Groups Projects
Commit 074c2b9b authored by christian.wiedemann's avatar christian.wiedemann
Browse files

Merge branch '3467656-' into '2.0.x'

Add test for field layout

See merge request !296
parents 5cab2636 bd0cfd60
No related branches found
No related tags found
No related merge requests found
Pipeline #364620 failed
......@@ -135,6 +135,8 @@ class ComponentLayout extends LayoutDefault implements ContainerFactoryPluginInt
// For layout builder we need to pass slots also
// direct to the build array. They are needed to generate contextual
// links and other surrounding markup.
// This makes field layout forms empty.
// Not sure how to handle this. Should we support field_layout?
$build[$region_name] = $regions[$region_name];
}
return $build;
......
uuid: 4576c853-ea9f-4154-adbb-f179f4a5b0ea
langcode: en
status: true
dependencies:
config:
- node.type.page
module:
- field_layout
- text
- ui_patterns
- ui_patterns_layouts
- ui_patterns_test
third_party_settings:
field_layout:
id: 'ui_patterns:ui_patterns_test:test_component'
settings:
label: ''
ui_patterns:
component_id: null
variant_id: null
slots: { }
props:
attributes:
source_id: attributes
source:
value: ''
string:
source_id: textfield
source:
value: ''
integer:
source_id: number
source:
value: ''
number:
source_id: number
source:
value: ''
url:
source_id: url
source:
value: ''
machine_name:
source_id: textfield
source:
value: ''
boolean:
source_id: checkbox
links:
source_id: menu
source:
menu: ''
level: '1'
depth: '0'
enum_integer:
source_id: select
source:
value: ''
enum_string:
source_id: select
source:
value: ''
enum_list:
source_id: checkboxes
list_string:
source_id: list_textarea
source:
value: ''
list_integer:
source_id: list_textarea
source:
value: ''
list_mixed:
source_id: list_textarea
source:
value: ''
attributes_implicit:
source_id: attributes
source:
value: ''
attributes_ui_patterns:
source_id: attributes
source:
value: ''
attributes_class:
source_id: attributes
source:
value: ''
_core:
default_config_hash: ewbd6G2uX456-bgwseM2Q-KQG3RkASoyHmTh-XR3oLU
id: node.page.default
targetEntityType: node
bundle: page
mode: default
content:
body:
type: text_textarea_with_summary
weight: 2
region: slot
settings:
rows: 9
summary_rows: 3
placeholder: ''
show_summary: false
third_party_settings: { }
path:
type: path
weight: 30
region: slot
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
weight: 15
region: slot
settings:
display_label: true
third_party_settings: { }
status:
type: boolean_checkbox
weight: 120
region: slot
settings:
display_label: true
third_party_settings: { }
sticky:
type: boolean_checkbox
weight: 16
region: slot
settings:
display_label: true
third_party_settings: { }
title:
type: string_textfield
weight: 0
region: slot
settings:
size: 60
placeholder: ''
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 5
region: slot
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }
uuid: 8c6d8afa-58a4-4702-8078-d56aad9370cc
langcode: en
status: true
dependencies:
module:
- field_layout
- text
- ui_patterns
- ui_patterns_layouts
- ui_patterns_test
- user
third_party_settings:
field_layout:
id: 'ui_patterns:ui_patterns_test:test_component'
settings:
label: ''
ui_patterns:
component_id: null
variant_id: null
slots: { }
props:
attributes:
source_id: attributes
source:
value: ''
string:
source_id: textfield
source:
value: asdf
integer:
source_id: number
source:
value: ''
number:
source_id: number
source:
value: ''
url:
source_id: url
source:
value: ''
machine_name:
source_id: textfield
source:
value: ''
boolean:
source_id: checkbox
links:
source_id: menu
source:
menu: ''
level: '1'
depth: '0'
enum_integer:
source_id: select
source:
value: ''
enum_string:
source_id: select
source:
value: ''
enum_list:
source_id: checkboxes
list_string:
source_id: list_textarea
source:
value: ''
list_integer:
source_id: list_textarea
source:
value: ''
list_mixed:
source_id: list_textarea
source:
value: ''
attributes_implicit:
source_id: attributes
source:
value: ''
attributes_ui_patterns:
source_id: attributes
source:
value: ''
attributes_class:
source_id: attributes
source:
value: ''
_core:
default_config_hash: br6izr-iGEu--JvNbCJNtOBpRnxpFLXfoV5y61U9Nqc
id: node.page.full
targetEntityType: node
bundle: page
mode: default
content:
field_text_1:
type: text_default
label: above
settings: { }
third_party_settings: { }
weight: 0
region: slot
hidden:
comment: true
field_image: true
field_tags: true
links: true
<?php
namespace Drupal\Tests\ui_patterns_layouts\Functional;
use Drupal\Tests\ui_patterns\Functional\UiPatternsFunctionalTestBase;
use Drupal\Tests\ui_patterns\Traits\TestDataTrait;
/**
* Test components rendering as layouts.
*
* @group ui_patterns_layouts
*/
class FieldLayoutRenderTest extends UiPatternsFunctionalTestBase {
use TestDataTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'ui_patterns',
'ui_patterns_test',
'ui_patterns_layouts',
'field_ui',
'field_layout',
'block',
];
/**
* Test the form and the existence of the.
*/
public function testContextInForm(): void {
$assert_session = $this->assertSession();
$config_import = $this->loadConfigFixture(__DIR__ . '/../../fixtures/config/core.entity_view_display.node.page.full.field_layout.yml');
$ui_patterns_config = &$config_import['third_party_settings']['field_layout']['settings']['ui_patterns'];
$test_data = $this->loadTestDataFixture();
$test_set = $test_data->getTestSet('context_exists_default');
$this->createTestContentContentType();
$ui_patterns_config = $this->buildUiPatternsConfig($test_set);
$this->importConfigFixture(
'core.entity_view_display.node.page.default',
$config_import
);
$this->drupalGet('admin/structure/types/manage/page/display');
$assert_session->statusCodeEquals(200);
$assert_session->elementTextEquals('css', '.context-exists', $test_set['output']['props']['string']['value']);
}
/**
* Tests preview and output of props.
*/
public function testRenderProps(): void {
$assert_session = $this->assertSession();
$config_import = $this->loadConfigFixture(__DIR__ . '/../../fixtures/config/core.entity_view_display.node.page.full.field_layout.yml');
$ui_patterns_config = &$config_import['third_party_settings']['field_layout']['settings']['ui_patterns'];
$test_data = $this->loadTestDataFixture();
$tests = [
$test_data->getTestSet('context_exists_default'),
$test_data->getTestSet('func_attributes_empty'),
$test_data->getTestSet('func_attributes_default'),
$test_data->getTestSet('textfield_default'),
$test_data->getTestSet('token_default'),
];
foreach ($tests as $test_set) {
$node = $this->createTestContentNode('page', $test_set['entity'] ?? []);
$ui_patterns_config = $this->buildUiPatternsConfig($test_set);
$ui_patterns_config = &$config_import['third_party_settings']['field_layout']['settings']['ui_patterns'];
$this->importConfigFixture(
'core.entity_view_display.node.page.default',
$config_import
);
$component_id = str_replace('_', '-', explode(':', $test_set['component']['component_id'])[1]);
$this->drupalGet('node/' . $node->id());
$assert_session->statusCodeEquals(200);
$assert_session->elementExists('css', '.ui-patterns-' . $component_id);
$this->validateRenderedComponent($test_set);
$node->delete();
}
}
/**
* Tests preview and output of slots.
*/
public function testRenderSlots(): void {
$node = $this->createTestContentNode('page', ['field_text_1' => ['value' => 'field_text_1 value']]);
$config_import = $this->loadConfigFixture(__DIR__ . '/../../fixtures/config/core.entity_view_display.node.page.full.field_layout.yml');
$this->importConfigFixture(
'core.entity_view_display.node.page.default',
$config_import
);
$assert_session = $this->assertSession();
$this->drupalGet('node/' . $node->id());
$assert_session->elementExists('css', '.ui-patterns-test-component');
$assert_session->elementTextContains('css', '.ui-patterns-slots-slot', 'field_text_1 value');
}
/**
* Tests render forms inside a layout.
*/
public function testRenderForm(): void {
$node = $this->createTestContentNode('page', ['field_text_1' => ['value' => 'field_text_1 value']]);
$config_import = $this->loadConfigFixture(__DIR__ . '/../../fixtures/config/core.entity_form_display.node.page.default.yml');
$this->importConfigFixture(
'core.entity_form_display.node.page.default',
$config_import
);
$this->drupalGet('node/' . $node->id() . '/edit');
$assert_session = $this->assertSession();
$assert_session->elementExists('css', '.field--name-body');
$assert_session->elementExists('css', '.ui-patterns-test-component');
}
}
......@@ -75,11 +75,13 @@ class LayoutBuilderRenderTest extends UiPatternsFunctionalTestBase {
);
$this->drupalGet('admin/structure/types/manage/page/display/full/layout');
$assert_session->statusCodeEquals(200);
$assert_session->elementExists('css', '.layout-builder-block');
$component_id = str_replace('_', '-', explode(':', $test_set['component']['component_id'])[1]);
$assert_session->elementExists('css', '.ui-patterns-' . $component_id);
$this->drupalGet('node/' . $node->id());
$assert_session->statusCodeEquals(200);
$assert_session->elementExists('css', '.ui-patterns-' . $component_id);
$this->validateRenderedComponent($test_set);
$node->delete();
}
......
......@@ -7,6 +7,12 @@
declare(strict_types=1);
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\EntityContext;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
/**
* Implements hook_element_info_alter().
*/
......@@ -16,3 +22,17 @@ function ui_patterns_layouts_element_info_alter(array &$types) :void {
["Drupal\ui_patterns_layouts\Element\ComponentAlterer", "processLayoutBuilderRegions"]);
}
}
/**
* Implements hook_entity_view_alter().
*
* Field layout is not adding entity information to the layout.
* We need to add it in another step.
*/
function ui_patterns_layouts_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display):void {
if (isset($build['_field_layout']['#ui_patterns']) &&
isset($build['_field_layout']['#source_contexts'])) {
$build['_field_layout']['#source_contexts']['entity'] = EntityContext::fromEntity($entity);
$build['_field_layout']['#source_contexts']['bundle'] = new Context(ContextDefinition::create('string'), $entity->bundle() ?? "");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment