Problem/Motivation

#2796173: Add experimental Field Layout module to allow entity view/form modes to switch between layouts adds an experimental module that extends and alters the EntityDisplay entity classes and forms.

It provides no additional paradigms or functionality other than enhancing the existing UI.

Proposed resolution

Once the module is approaching a stable release, merge it directly into those core classes instead of having an optional module, even one in the Standard profile.

Remaining tasks

N/A

User interface changes

N/A

API changes

Added EntityDisplayInterface::getDefaultRegion()
Added EntityViewDisplayInterface::getFieldFromBuild()
Added EntityViewDisplayInterface::setFieldOnBuild()

Data model changes

entity_view_display and enitty_form_display both get a layout_id (string) and layout_settings (array)

CommentFileSizeAuthor
#95 2844302-95.patch159.38 KBandypost
#95 interdiff.txt601 bytesandypost
#94 2844302-94.patch159.38 KBandypost
#94 interdiff.txt13.59 KBandypost
#92 2844302-92.patch156.21 KBtim_dj
#90 2844302-90.patch156.14 KBgrathbone
#89 2844302-89.patch156.14 KBgrathbone
#87 interdiff_2844302_86-87.txt912 bytesankithashetty
#87 2844302-87.patch161.07 KBankithashetty
#86 diff_reroll_2844302_82-86.txt29.81 KBankithashetty
#86 2844302-86.patch160.81 KBankithashetty
#85 2844302-85-8.9.x.patch129.5 KBpiggito
#82 2844302-82.patch158.2 KBdurgeshs
#82 interdiff_80-82.txt2.13 KBdurgeshs
#80 interdiff.2844302.79-80.txt24.92 KBaleevas
#80 2844302-80.patch156.66 KBaleevas
#79 interdiff.2844302.78-79.txt6.15 KBaleevas
#79 2844302-79.patch136.8 KBaleevas
#78 interdiff.2844302.61-78.txt109.4 KBaleevas
#78 2844302-78.patch132.66 KBaleevas
#75 interdiff_72-75.txt3.06 KBridhimaabrol24
#75 2844302-75.patch177.72 KBridhimaabrol24
#72 interdiff_71-72.txt971 bytesridhimaabrol24
#72 2844302-72.patch177.79 KBridhimaabrol24
#71 interdiff_69-71.txt1.22 KBridhimaabrol24
#71 2844302-71.patch177.75 KBridhimaabrol24
#69 2844302-69.patch177.07 KBridhimaabrol24
#68 interdiff-67-68.txt26.41 KBHardik_Patel_12
#68 2844302-68.patch178.88 KBHardik_Patel_12
#67 2844302-67.patch182.42 KBridhimaabrol24
#65 interdiff_62-65.txt3.53 KBravi.shankar
#65 2844302-65.patch205.5 KBravi.shankar
#62 2844302-field_layout-61.patch205.48 KBWeb-Beest
#60 interdiff-51-60.txt71.54 KBaleevas
#60 2844302-60.patch205.53 KBaleevas
#59 interdiff-51-59.txt71.39 KBaleevas
#59 2844302-59.patch205.52 KBaleevas
#50 2844302-field_layout-50.patch208.13 KBtim.plunkett
#52 2844302-field_layout-51.patch207.58 KBtim_dj
#46 field_layout-to-core-additional-patch-on-2844302-42.patch2.13 KBLennard Westerveld
#46 2844302-field_layout-46-8.6.10.patch203.85 KBLennard Westerveld
#45 2844302-field_layout-45-interdiff.txt867 bytestim.plunkett
#45 2844302-field_layout-45.patch206.31 KBtim.plunkett
addtional-patch-utf8.patch757 bytesLennard Westerveld
addtional-patch-utf8.patch773 bytesLennard Westerveld
addtional-patch.patch772 bytesLennard Westerveld
#42 2844302-field_layout-42.patch206.1 KBtim.plunkett
#29 2844302-field_layout-no_ui-29.patch132.21 KBtim.plunkett
#29 2844302-field_layout-no_ui-29-interdiff.txt2.83 KBtim.plunkett
#26 2844302-field_layout-no_ui-26-interdiff.txt15.43 KBtim.plunkett
#26 2844302-field_layout-no_ui-26.patch131.06 KBtim.plunkett
#20 2844302-field_layout-merge-20.patch173.58 KBtim.plunkett
#20 2844302-field_layout-merge-20-interdiff.txt4.64 KBtim.plunkett
#18 2844302-field_layout-merge-18.patch172.01 KBtim.plunkett
#18 2844302-field_layout-merge-18-interdiff.txt2.39 KBtim.plunkett
#17 2844302-field_layout-merge-17.patch171.93 KBtim.plunkett
#17 2844302-field_layout-merge-17-interdiff.txt1.71 KBtim.plunkett
#15 2844302-field_layout-merge-15.patch171.9 KBtim.plunkett
#12 2844302-field_layout-11.patch186.9 KBtim.plunkett
#8 2844302-field_layout-8.patch176.55 KBtim.plunkett
#5 2844302-field_layout-5.patch173.76 KBtim.plunkett
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

jibran’s picture

We need some kind of tag to track all the blocker. Maybe something like https://www.drupal.org/project/issues/search?issue_tags_op=all+of&issue_....

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Status: Needs work » Postponed

Those fails are from #2851635: DefaultSingleLazyPluginCollection retains stale instance IDs, working through them there. Back to postponed for now.

tim.plunkett’s picture

Status: Postponed » Needs review
FileSize
176.55 KB

Those went in.

tim.plunkett’s picture

Most "move this code from one place to another" patches would be small, thanks to the way handled git moves/copies.
However, in this case we are merging code into existing files. It can be hard to see where things ended up, so I've gone through the main files that are deleted to explain where they live now, or why it was removed completely.

  1. +++ /dev/null
    @@ -1,42 +0,0 @@
    -function field_layout_install() {
    ...
    -function field_layout_uninstall() {
    

    Since it can't be installed or uninstalled anymore, no need for this code!

  2. +++ /dev/null
    @@ -1,69 +0,0 @@
    -function field_layout_entity_type_alter(array &$entity_types) {
    

    No need to swap out the entity classes or form classes, the code was merged into the original classes.

  3. +++ /dev/null
    @@ -1,69 +0,0 @@
    -function field_layout_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
    

    This is now handled by \Drupal\Core\Entity\Entity\EntityViewDisplay::buildMultiple()

  4. +++ /dev/null
    @@ -1,69 +0,0 @@
    -function field_layout_form_alter(&$form, FormStateInterface $form_state, $form_id) {
    

    This is now handled by \Drupal\Core\Entity\Entity\EntityFormDisplay::buildForm()

  5. +++ /dev/null
    @@ -1,153 +0,0 @@
    -trait FieldLayoutEntityDisplayTrait {
    

    This was moved directly into \Drupal\Core\Entity\EntityDisplayBase

  6. +++ /dev/null
    @@ -1,153 +0,0 @@
    -class FieldLayoutBuilder implements ContainerInjectionInterface {
    ...
    -  public function buildView(array &$build, EntityDisplayWithLayoutInterface $display) {
    ...
    -  public function buildForm(array &$build, EntityDisplayWithLayoutInterface $display) {
    

    This was split into \Drupal\Core\Entity\Entity\EntityFormDisplay::applyLayout() and \Drupal\Core\Entity\Entity\EntityViewDisplay::applyLayout().

  7. +++ /dev/null
    @@ -1,177 +0,0 @@
    -trait FieldLayoutEntityDisplayFormTrait {
    

    This was merged directly into \Drupal\field_ui\Form\EntityDisplayFormBase

  8. +++ /dev/null
    @@ -1,76 +0,0 @@
    -class FieldLayoutTest extends BrowserTestBase {
    

    This test is obsoleted by the overlap between \Drupal\Tests\field_ui\Functional\EntityDisplayTest and \Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest

  9. +++ /dev/null
    @@ -1,266 +0,0 @@
    -class FieldLayoutTest extends JavascriptTestBase {
    

    This was merged into \Drupal\Tests\field_ui\FunctionalJavascript\EntityDisplayTest

  10. +++ /dev/null
    @@ -1,308 +0,0 @@
    -class FieldLayoutBuilderTest extends UnitTestCase {
    ...
    -   */
    

    This test was split into \Drupal\Tests\Core\Entity\Display\EntityViewDisplayTest and \Drupal\Tests\Core\Entity\Display\EntityFormDisplayTest

  11. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewDisplayTest.php
    @@ -138,31 +207,13 @@ public function testPreSave() {
    -    $this->container->get('module_installer')->uninstall(['field_layout']);
    -
    -    $entity_storage = $this->container->get('entity_type.manager')->getStorage('entity_view_display');
    -    $entity_display = $entity_storage->load('entity_test.entity_test.default');
    -
    -    // The dependencies have been updated.
    -    $expected['dependencies']['module'] = [
    -      'entity_test',
    -    ];
    -    // All field_layout settings were removed.
    -    unset($expected['third_party_settings']['field_layout']);
    -    // The field has returned to the default content region.
    -    $expected['content']['foo']['region'] = 'content';
    -    $this->assertEntityValues($expected, $entity_display->toArray());
    

    This tests uninstallation, which is no longer possible.

jibran’s picture

I think it is safe to say that we need some manual testing and some reviews from framework manager and sub-system maintainers.

  1. +++ b/core/composer.json
    @@ -96,7 +96,6 @@
    -        "drupal/field_layout": "self.version",
    
    @@ -107,7 +106,6 @@
    -        "drupal/layout_discovery": "self.version",
    

    It would be interesting to count the number of days in core for these modules when this issue is fixed.

  2. +++ b/core/modules/field/tests/src/Kernel/EntityReference/EntityReferenceFormatterTest.php
    @@ -188,11 +188,16 @@ public function testEntityFormatter() {
    +    ¶
    
    @@ -204,11 +209,16 @@ public function testEntityFormatter() {
    +    ¶
    

    Blank spaces.

  3. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewDisplayTest.php
    @@ -1,20 +1,97 @@
    +    $expected_markup = <<<'EOS'
    ...
    +EOS;
    

    Why not call it TIM? :P

  4. +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewDisplayTest.php
    @@ -1,20 +1,97 @@
    +    ¶
    ...
    +      ¶
    ...
    +      ¶
    ...
    +      ¶
    

    Blank spaces.

tim.plunkett’s picture

Yes, definitely will add all the "needs * review" tags, just wanted to get this more ready first.

Second, all of the trailing spaces are necessary because they're in the templates, and we are doing a strict comparison.

tim.plunkett’s picture

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
171.9 KB

No interdiff since it's a reroll.

tim.plunkett’s picture

Fixed getExtraFields()

tim.plunkett’s picture

Allow getFieldFromBuild() to work with references.

phenaproxima’s picture

This is a shallow review. I probably would have more questions if I did a deeper review, but overall it looks pretty good to me.

  1. +++ b/core/includes/theme.inc
    @@ -1702,6 +1702,19 @@ function template_preprocess_breadcrumb(&$variables) {
    +function template_preprocess_layout(&$variables) {
    

    Can $variables be type hinted?

  2. +++ b/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php
    @@ -128,4 +128,25 @@ public function getTargetBundle();
    +  /**
    +   * Gets the field's portion of the fully built entity display render array.
    +   *
    +   * @param string $field_name
    +   *   The field name.
    +   * @param array $build
    +   *   The full render array.
    +   *
    +   * @return array
    +   *   The portion of the render array corresponding to the given field name.
    +   */
    +  public function &getFieldFromBuild($field_name, array &$build);
    +
    +  /**
    +   * Gets the default region.
    +   *
    +   * @return string
    +   *   The default region for this display.
    +   */
    +  public function getDefaultRegion();
    

    Doesn't adding methods to the interface constitute a BC break, however unlikely?

  3. +++ b/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php
    @@ -213,6 +216,32 @@ public function processForm($element, FormStateInterface $form_state, $form) {
    +  public function applyLayout($element, FormStateInterface $form_state, $form) {
    

    Can $element and $form be type hinted?

  4. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -412,6 +441,18 @@ public function getHighestWeight() {
       /**
    +   * Gets the extra fields for this display.
    +   */
    +  protected function getExtraFields() {
    

    The doc comment is missing a @return.

  5. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -545,13 +586,112 @@ protected function getPluginRemovedDependencies(array $plugin_dependencies, arra
    +  public function setLayoutId($layout_id, array $layout_settings = []) {
    

    I think this is named very strangely. This is more what I would expect the signature of setLayout() to be, not setLayoutId(). IMHO we should remove setLayoutId() entirely, if we have the latitude to do that, and leave setLayout() only, with this signature and logic.

  6. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -545,13 +586,112 @@ protected function getPluginRemovedDependencies(array $plugin_dependencies, arra
    +    $this->setLayoutId($layout->getPluginId(), $layout->getConfiguration());
    +    return $this;
    

    Nit: setLayoutId() returns $this, so this can just directly return the result of setLayoutId().

  7. +++ b/core/lib/Drupal/Core/Entity/EntityViewBuilder.php
    @@ -399,13 +399,8 @@ public function viewField(FieldItemListInterface $items, $display_options = [])
    +    return $display->getFieldFromBuild($field_name, $build);
    

    Should this be returning by reference, to match getFieldFromBuild()'s return?

  8. +++ b/core/lib/Drupal/Core/Layout/Plugin/Layout/DefaultLayout.php
    @@ -0,0 +1,34 @@
    + *   description = @Translation("A layout with no markup"),
    

    Can this description be changed? It's misleading and sounds like nothing will be rendered at all. Maybe just "Renders everything in the layout in a single region without any wrapping markup" or similar.

  9. +++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php
    @@ -55,10 +66,13 @@
    +  public function __construct(FieldTypePluginManagerInterface $field_type_manager, PluginManagerBase $plugin_manager, LayoutPluginManagerInterface $layout_plugin_manager) {
    

    Should $layout_plugin_manager default to NULL to preserve BC? I think this is fine, personally, but I still thought I'd point it out.

  10. +++ b/core/modules/rdf/rdf.module
    @@ -502,7 +503,19 @@ function rdf_preprocess_comment(&$variables) {
    +function rdf_entity_display_build_alter(&$build, $context) {
    +  if (!($context['entity'] instanceof CommentInterface)) {
    +    return;
    +  }
    +
    +  $comment = $context['entity'];
    +  $rdf_metadata_attributes = [];
    +  $mapping = rdf_get_mapping('comment', $comment->bundle());
    

    Wat? Why is this here? It doesn't seem to be layout related...

  11. +++ b/core/modules/user/user.module
    @@ -392,13 +392,14 @@ function user_user_view(array &$build, UserInterface $account, EntityViewDisplay
    +function user_entity_display_build_alter(&$build, $context) {
    +  $account = $context['entity'];
    +  if ($account instanceof UserInterface && user_picture_enabled() && !empty($build['user_picture'])) {
    

    This also seems kind of strange. I'm not sure how it ties into the layout system changes.

tim.plunkett’s picture

Thanks for the review!

1/3 These sorts of functions (preprocess, #process callbacks) all use the same signature, and the others don't typehint the array.

2) This is the interface for an entity, it's an allowed change.

4) Fixed

5) If PHP supported method overloading, I'd have them both named setLayout().
@phenaproxima @EclipseGc @dawehner @msonnabaum and I discussed this more, and decided to leave the code as-is but rename setLayoutId() to setLayoutFromId().
Also I realized that @phenaproxima and I had this exact conversation the first time setLayoutId went in! (#2796173-104: Add experimental Field Layout module to allow entity view/form modes to switch between layouts, point 7)

6) True, but I think it's better to be explicit

7) viewField() didn't return by reference before, so no this is fine

8) I'm just removing the description. None of the other core layouts have them.

9) This is an entity handler AND a form, both of which are exempt from BC

10/11) So here's the thing.
Render arrays are explicitly not BC safe. It even says This means alter hook implementations may need to be updated.
hook_entity_view_alter() runs after the fields in the $build array have been relocated to their regions.
hook_entity_display_build_alter() runs directly BEFORE the layout code runs.
As such, I updated the only two problematic hook implementations.

tim.plunkett’s picture

Another option would be to move just the data model and API portion into the Entity subsystem, and move the Field UI changes to a follow-up.
Either way this is still blocked on #2834025: Mark Layout Discovery as a stable module.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php
    @@ -128,4 +128,25 @@ public function getTargetBundle();
    +   *
    +   * @return array
    +   *   The portion of the render array corresponding to the given field name.
    +   */
    +  public function &getFieldFromBuild($field_name, array &$build);
    

    I'm wondering whether we can document a bit why getFieldFromBuild returns a referece

  2. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -545,13 +590,112 @@ protected function getPluginRemovedDependencies(array $plugin_dependencies, arra
    +    // Ignore any extra fields from the list of field definitions. Field
    +    // definitions can have a non-configurable display, but all extra fields are
    +    // always displayed.
    +    $field_definitions = array_diff_key($this->getFieldDefinitions(), $this->getExtraFields());
    +
    +    $fields_to_exclude = array_filter($field_definitions, function (FieldDefinitionInterface $field_definition) {
    +      // Remove fields with a non-configurable display.
    +      return !$field_definition->isDisplayConfigurable($this->displayContext);
    +    });
    +    $components = array_diff_key($components, $fields_to_exclude);
    +
    +    // Only include fields present in the build.
    +    $components = array_intersect_key($components, $build);
    

    I was wondering whether it would be clearer to read when it would be something like: $components =

    array_filter($components, function ($component_id) {
      return isset($field_definitions) && !isset($extra_fields) && !$field_definition->isDisplayConfigurable() && isset($build);
    }, ARRAY_FILTER_USE_KEY);

    Then I was wondering though: Is the current implementation better O(*) wise? I would argue no, because isset() aka. a hashmap lookup by key is O(1), so the total complexity is O(N), which should be better than what it is now, see https://stackoverflow.com/questions/2473989/list-of-big-o-for-php-functions for a list of complexity time for all the various PHP functions.

tim.plunkett’s picture

1) Not really sure how best to do that.

2) I had this same thought. But ARRAY_FILTER_USE_KEY is 5.6.0 only, and I couldn't figure out how to do it otherwise, and I figured that the explicit steps of filtering with the comments was okay.

Also holy god, Big O. That is a question for another day.

dawehner’s picture

2) You could use \Zend\Stdlib\ArrayUtils::filter which we already ship with in core.

tim.plunkett’s picture

22.1
HEAD:

function mymodule_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  $build['my_field_name']['#title'] = t('New title');
}

Current patch:

function mymodule_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  $my_field = &$display->getFieldFromBuild('my_field_name', $build);
  $my_field['#title'] = t('New title');
}

Possible?

function mymodule_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  $my_field = $display->getFieldFromBuild('my_field_name', $build);
  $my_field['#title'] = t('New title');
  $display->SetFieldFromBuild('my_field_name', $my_field, $build);
}

I really don't care, but unless we magically solve #2846393: [PP-1] Investigate alternative approaches to moving fields in FieldLayoutBuilder::buildView(), we need a reliable way to locate the field within the build array.

22.2
The logic is a bit more complex there.
As a one-liner it'd be

      return isset($build[$component_id]) && (isset($extra_fields[$component_id]) || !isset($field_definitions[$component_id]) || $field_definitions[$component_id]->isDisplayConfigurable($this->displayContext));

But I find that completely inscrutable, so I chopped it up to this:

      // Only include fields present in the build.
      if (!isset($build[$component_id])) {
        return FALSE;
      }

      // Extra fields are always displayed.
      if (isset($extra_fields[$component_id])) {
        return TRUE;
      }

      // Only include fields with a configurable display.
      if (isset($field_definitions[$component_id])) {
        return $field_definitions[$component_id]->isDisplayConfigurable($this->displayContext);
      }

      // The origin of this field is unknown, include it in the list.
      return TRUE;

Didn't know we had ArrayUtils available!
It's in the zend-stdlib package, which seems to be brought in as a dependency of zend-feed, but not that we're using it explicitly don't we have to put it in composer.json directly?

Going to wait for that feedback before posting a new patch.

tim.plunkett’s picture

Title: Move Field Layout code directly into \Drupal\Core\Entity\EntityDisplayBase and Field UI » Move Field Layout data model and API directly into \Drupal\Core\Entity\EntityDisplayBase
Issue summary: View changes
FileSize
131.06 KB
15.43 KB

After some discussion with others, went with the getter/setter.

Until #2867960: Merge Component composer.json files to account for them during build is done, a core/lib/Drupal/Core/Entity/component.json to ensure zend-stdlibs is included will not be respected.
But, the switch is good to make. Using a single array_filter with several isset()s instead of one array_filter, one array_intersect_key, and two array_diff_key calls is much clearer.

Also, for now I've removed the Field UI changes.

tim.plunkett’s picture

Opened #2880746: [PP-1] Move Field Layout UI directly into Field UI as a follow-up and linked it from that issue.

tim.plunkett’s picture

Too greedy with that last patch.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/Display/EntityDisplayInterface.php
    @@ -129,19 +129,6 @@ public function getTargetBundle();
    -  public function &getFieldFromBuild($field_name, array &$build);
    
    +++ b/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php
    @@ -46,4 +46,37 @@ public function build(FieldableEntityInterface $entity);
    +  public function getFieldFromBuild($field_name, array $build);
    ...
    +  public function setFieldOnBuild($field_name, array $field_array, array &$build);
    

    <3

  2. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -600,22 +601,27 @@ protected function getPluginRemovedDependencies(array $plugin_dependencies, arra
    +    return ArrayUtils::filter($components, function ($component_id) use ($field_definitions, $extra_fields, $build) {
    ...
    +    }, ArrayUtils::ARRAY_FILTER_USE_KEY);
    

    Nice improvement, I like that.
    Let's put some todo here to not require the library when we are on php 5.6?

Eric_A’s picture

Until #2867960: Merge Component composer.json files to account for them during build is done, a core/lib/Drupal/Core/Entity/component.json to ensure zend-stdlibs is included will not be respected.

But that never stopped us from declaring dependencies in the components anyway. (And copying some to core/composer.json to make everything actually work...)

But it's probably most effective to get #2769841: Prefer caret over tilde in composer.json in first, now that it is RTBC...

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

larowlan’s picture

Issue tags: +DrupalSouth 2017

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
aleevas’s picture

Tried to reroll this up to 8.7, but here is too many conflicts in many files. Is it this issue still actual?

tim.plunkett’s picture

Status: Needs work » Active
Issue tags: -DrupalSouth 2017, -Needs reroll

I'm not 100% sure we want to do this anymore.
Setting back to active for now for discussion, not a patch.

AaronMcHale’s picture

Personally I'm of two minds, on one hand this is a useful module and totally makes sense, but on the other hand not everyone needs it so keeping it separate means the Field UI stays simpler (cleaner? not sure what the best word is) for those who don't need it.

Gábor Hojtsy’s picture

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
Status: Active » Needs review
FileSize
206.1 KB

Working on this again. This is both the API and UI move at once. It could likely be split up better, but first I want to get the whole thing passing and see if we can make things a bit smoother for Layout Builder.

andypost’s picture

It looks great, quickly skimmed and found only nitpick

+++ b/core/includes/theme.inc
@@ -1716,6 +1716,27 @@ function template_preprocess_breadcrumb(&$variables) {
+function template_preprocess_layout(&$variables) {

other issues are trying to kill includes so maybe better to move it to system.module?

Lennard Westerveld’s picture

Patch is working but we had some issue's while updating:
1. The view display settings are not updated to the new settings zo field_layout needs to have a upgrade path to the core functionality like:

  /* @var \Drupal\Core\Entity\EntityTypeManagerInterface $viewDisplayEntities */
  $entity_type_manager = \Drupal::service('entity_type.manager');
  $storage = $entity_type_manager->getStorage('entity_view_display');
  $entities = $storage->loadMultiple();
  foreach ($entities as $entity) {
    /* @var \Drupal\Core\Entity\Entity\EntityViewDisplay $entity */
    $layout_settings = $entity->getThirdPartySettings('field_layout');
    if (isset($layout_settings, $layout_settings['id'])) {
      $entity->setLayoutFromId($layout_settings['id'], $layout_settings['settings'] ?? []);
      $entity->save();
    }
  }

2. The dependentie on layout_discovery by default it breaks now selecting a new layout because layout.icon_builder cannot be found because it is not a default dependentie of core. Maybe we need to hide or make notice? when layout_discovery is not enabled?

3. Breaks parargaphs template or other templates where content.field_name is used (example paragraphs) because of the _layout structure is enabled on every EntityViewDisplay i would say that _layout only needs to be used when there is a layout selected other then default?

4. Also in field_ui is there still some old getThirdPartySettings that uses field_layout instead of the $display->getLayout see patch in new comment! (EDIT: i see that it it field_group contrib where this needs to change)

5. I see also a issue with entity_extra_field_info fields that uses hook_entity_view to insert there render array to the build but because it is moved to core now the order is not right i guess. _layout is already setup and later on the pseudo-fields is added to the render array. So that breaks the layout and shows the pseudo-fields below the layout parts.

6. How sure are we that this is going to move to core? (maybe better place in the meta issue?)

Kind regards,
Lennard Westerveld

tim.plunkett’s picture

#44
1) Agreed. Tagging for update path + tests
2) Fixed
3) This is similar to #2966592: Figure out a way to render fields on top level in templates. Needs fixing here, agreed.
4) n/a, it was in field_group
5) extra fields *should* be added with weight, if it's not that should be investigated
6) It's in core already as an experimental module. This is one option. The other is to mark the module as hidden and deprecate it fully. It could then be resurrected in contrib.

Here's a reroll and a fix for #44.2

Lennard Westerveld’s picture

Here is a patch of #45 for Drupal 8.6.10
With a additional patch for making the _layout optional only when not the default layout is selected that also can apply on 8.7.x #45 that fixes issues for templates that already created with for example `{{content.field_content}} ` not causing errors.

Status: Needs review » Needs work

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Lennard Westerveld’s picture

Issue tags: +Needs reroll

Needs reroll for 8.7.0 and 8.8.x

tim.plunkett’s picture

Status: Needs review » Needs work

The last submitted patch, 50: 2844302-field_layout-50.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

tim_dj’s picture

FileSize
207.58 KB

Reroll for 8.7.x

tim.plunkett’s picture

This isn't going in to 8.7 so there's no need to post rerolls for that.

AaronMcHale’s picture

Something that I've noticed, and it annoys me, is that when Layout Builder and Field Layout are installed, Field Layout is completely gone on the Manage Display tab, but not on the Manage Form Display tab.

Is that a Field Layout thing, or a Layout Builder thing? Because I actually find myself wanting to use both Field Layout and Layout Builder, just on different Entity Types.

So if that's a Field Layout thing, I'd like to suggest "fixing" that here so it doesn't happen.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Lennard Westerveld’s picture

So where are almost 1 year further, what are the plans? about this issue?

SKAUGHT’s picture

Issue tags: +Drupal 9

lots to do in the world.. status is needs work!

andypost’s picture

aleevas’s picture

I've tried to reroll patch from #52

aleevas’s picture

Was fixed coding standards

Web-Beest’s picture

I've applied the patch #60, but it fails (the patch works but Drupal then craps out).
In /core/lib/Drupal/Core/Entity/EntityDisplayBase.php in getPluginCollection() the DefaultSingleLazyPlugin class is used, but not imported.
Fixed by adding use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection;

Web-Beest’s picture

andypost’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php
    @@ -282,11 +284,78 @@ public function buildMultiple(array $entities) {
           \Drupal::moduleHandler()->alter('entity_display_build', $build_list[$id], $context);
    +      $this->applyLayout($build_list[$id]);
    

    probably layout should be applied before alter

  2. +++ b/core/modules/workspaces/config/install/core.entity_form_display.workspace.workspace.deploy.yml
    @@ -13,3 +13,5 @@ content: {  }
    +layout_settings: {  }
    \ No newline at end of file
    
    +++ b/core/profiles/demo_umami/config/install/core.entity_form_display.media.image.default.yml
    @@ -72,3 +72,5 @@ content:
    +layout_settings: {  }
    \ No newline at end of file
    
    +++ b/core/profiles/demo_umami/config/install/core.entity_form_display.node.recipe.default.yml
    @@ -179,3 +179,5 @@ content:
    +layout_settings: {  }
    \ No newline at end of file
    
    +++ b/core/profiles/demo_umami/config/install/core.entity_view_display.node.article.full.yml
    @@ -51,3 +51,5 @@ content:
    +layout_settings: {  }
    \ No newline at end of file
    
    +++ b/core/profiles/demo_umami/config/install/core.entity_view_display.node.page.default.yml
    @@ -31,3 +31,5 @@ content:
    +layout_settings: {  }
    \ No newline at end of file
    

    nitpick

Status: Needs review » Needs work

The last submitted patch, 62: 2844302-field_layout-61.patch, failed testing. View results

ravi.shankar’s picture

Here I have made changes as suggested in comment #63.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ridhimaabrol24’s picture

Reroll patch for Drupal 9.1

Hardik_Patel_12’s picture

Rerolled patch 9.1.x as patch #67 failed to apply.

ridhimaabrol24’s picture

ravi.shankar’s picture

Status: Needs review » Needs work

Back to Need Work as patch #69 didn't pass the tests.

ridhimaabrol24’s picture

ridhimaabrol24’s picture

ridhimaabrol24’s picture

Status: Needs work » Needs review
Hardik_Patel_12’s picture

Status: Needs review » Needs work

There are errors shown by test bot, which are as below.

/var/lib/drupalci/workspace/jenkins-drupal_patches-45340/source/core/lib/Drupal/Core/Entity/Display/EntityDisplayWithLayoutInterface.php ✗ 1 more
line 5	Unused use statement
/var/lib/drupalci/workspace/jenkins-drupal_patches-45340/source/core/lib/Drupal/Core/Entity/Entity/EntityFormDisplay.php ✗ 5 more
242	Line indented incorrectly; expected 8 spaces, found 7
244	Closing brace indented incorrectly; expected 7 spaces, found 8
371	Whitespace found at end of line
375	Expected 1 space before opening brace; found 0
385	Whitespace found at end of line
/var/lib/drupalci/workspace/jenkins-drupal_patches-45340/source/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php ✗ 8 more
303	Line indented incorrectly; expected 6 spaces, found 5
303	Closing brace indented incorrectly; expected 6 spaces, found 5
377	Whitespace found at end of line
378	Line indented incorrectly; expected 2 spaces, found 3
381	Expected 1 space before opening brace; found 0
390	Expected 1 blank line after function; 0 found
390	Whitespace found at end of line
391	The closing brace for the class must have an empty line before it
/var/lib/drupalci/workspace/jenkins-drupal_patches-45340/source/core/lib/Drupal/Core/Entity/EntityDisplayBase.php ✗ 2 more
612	Line indented incorrectly; expected 2 spaces, found 1
614	Closing brace indented incorrectly; expected 1 spaces, found 2
/var/lib/drupalci/workspace/jenkins-drupal_patches-45340/source/core/modules/node/tests/src/Kernel/SummaryLengthTest.php ✗ 1 more
114	Whitespace found at end of line
/var/lib/drupalci/workspace/jenkins-drupal_patches-45340/source/core/tests/Drupal/Tests/EntityViewTrait.php ✗ 4 more
12	Whitespace found at end of line
13	Line indented incorrectly; expected 2 spaces, found 3
22	Whitespace found at end of line
44	Whitespace found at end of line
ridhimaabrol24’s picture

Fixed coding standards mentioned in #74

ridhimaabrol24’s picture

Status: Needs work » Needs review
Sivaji_Ganesh_Jojodae’s picture

Issue tags: -Needs reroll
aleevas’s picture

Just re-rolled against 9.1
Let's see that test bot will say

aleevas’s picture

Next try

aleevas’s picture

Fixed coding standards issues and fixed wrong path for these tests in patch file:

core/tests/Drupal/Tests/Core/Entity/Display/EntityFormDisplayTest.php
core/tests/Drupal/Tests/Core/Entity/Display/EntityViewDisplayTest.php
durgeshs’s picture

Assigned: Unassigned » durgeshs
durgeshs’s picture

@aleevas,

#80 is applied on local.
I have removed some unused use statement, I tried to check test cases but there are failed a lot of test cases, need to work for test cases.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

piggito’s picture

FileSize
129.5 KB

I ported patch #82 for d8.9 for anyone else needing it.

ankithashetty’s picture

Status: Needs work » Needs review
FileSize
160.81 KB
29.81 KB

Rerolled the patch in #82 and tried to fix test failures.

Thanks!

ankithashetty’s picture

Fixing custom command failure errors in #86, thanks!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

grathbone’s picture

#87 was not applying, and when I rerolled it actually wouldn't work because of missing getLayout() in EntityDisplayBase. Ended up doing a mixture of the last instance with getLayout(), which was from #75, and the most recent rebase, #87.

Some other issues I ran into:

  • any displays that already exist and don't have layoutid or layoutsettings errored, so I added in defaults in their get methods.
  • exporting config doesn't seem to actually set layout id in some cases, can't figure out why
  • can't seem to figure out how to select the layout in the ui itself
grathbone’s picture

Amendment to my comment above (#89): fixing namespacing issue for an old Zend reference. New patch attached.

andypost’s picture

Status: Needs review » Needs work

Still needs proper reroll

tim_dj’s picture

reroll of #90 for 9.3.x

andypost’s picture

andypost’s picture

Status: Needs work » Needs review
FileSize
13.59 KB
159.38 KB

Fixed CS and some test failures, added few todos as not sure this methods are needed

andypost’s picture

FileSize
601 bytes
159.38 KB

fix more cs

Status: Needs review » Needs work

The last submitted patch, 95: 2844302-95.patch, failed testing. View results

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

coaston’s picture

Is there any progress ?

donquixote’s picture