Problem/Motivation

#1875974: Abstract 'component type' specific code out of EntityDisplay sought to entirely refactor how fields are handled for EntityDisplay objects.
This is still desirable, but is a huge effort with tricky BC concerns.

Proposed resolution

In the meantime, the iterative step is to add native support for placing block plugins within an entity display.
Block plugins are a \Drupal\Core\Block concept, separate from the block.module

Remaining tasks

Write update path and tests

User interface changes

Yes

API changes

API additions only

Data model changes

Yes

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new42.17 KB
tim.plunkett’s picture

jonathanshaw’s picture

Thanks Tim! Obviously a huge win for sitebuilders here. Goodbye to a whole class of clunky contrib modules to achieve a very common use case.

swentel’s picture

Awesome. Tested it and works like a charm!

Only quickly scanned the code, looks fine to me.

+++ b/core/modules/field_ui/src/Form/EntityViewDisplayEditForm.php
@@ -83,6 +94,242 @@ protected function buildExtraFieldRow($field_id, $extra_field) {
+      // the new settings fro the next rebuild.

nitpick: missing 'm' in fro

Don't want to set it to needs work for now for missing things (e.g. config dependencies, post update hook to update entity displays) so more people can look at it.

dawehner’s picture

Just some quick comments ...

  1. +++ b/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php
    @@ -46,4 +46,45 @@ public function build(FieldableEntityInterface $entity);
    +   * @return array|null
    +   *   The array of display options, keyed by block name.
    ...
    +   *
    +   * @return \Drupal\Core\Block\BlockPluginInterface
    +   *   The instantiated block plugin.
    +   */
    +  public function getBlock($name);
    

    These methods names are weird ... given that one returns an object and the other one an array of configuration.

  2. +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php
    @@ -263,6 +308,23 @@ public function buildMultiple(array $entities) {
    +
    +        if ($block instanceof ContextAwarePluginInterface) {
    +          $contexts = \Drupal::service('context.repository')->getRuntimeContexts($block->getContextMapping());
    +          \Drupal::service('context.handler')->applyContextMapping($block, $contexts);
    +        }
    

    I'm wondering whether we could pass in the current rendered entity as context. With that we would have to rely less on block runtime contexts

groovedork’s picture

This is great, but as a sitebuilder I would prefer a solution described here, as it has a number of advantages:
- It offers a clean workaround for the problem that the title is not a field.
- It allows for fields to be placed in any of the theme's regions. This would be extremely valuable, and would allow much more flexibilty than this solution offers.

jonathanshaw’s picture

#7 no reason not to have both? They're not way duplicates AFAIK.

tim.plunkett’s picture

That other issue is an interesting idea, but as jonathanshaw points out it is not conflicting with this one.

groovedork’s picture

It may not conflict technically, but they do overlap functionally. Both systems could be used to place blocks in between fields.

Energy to work on Drupal may not be infinite. If energy could be redirected, then I propose to redirect it towards the solution that solves more problems (title does not behave like a field) and offers greater flexibility (mix blocks and fields into any region).

This solution, while wonderful in its own right, could lead to lethargy and slowdown in the development of a solution that I believe would be better, and also covers this use case.

tim.plunkett’s picture

Please comment on the other issue to encourage others to work on it, and stop derailing my efforts here. Thanks!

groovedork’s picture

Ok, sorry.

tim.plunkett’s picture

Issue summary: View changes
Issue tags: +Needs usability review
StatusFileSize
new6.96 KB
new43.21 KB

#5
The typo was "for" :)
What do you mean config dependencies?
Adding update path to IS

#6
1) Agreed. Renamed to match the corresponding method, this is now getBlockComponents()
2) We can pass that in as an available context, but we still need to get the mappings for runtime.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new513 bytes
new43.71 KB
Bojhan’s picture

What? :D

What is a block field?

manuel garcia’s picture

Status: Needs work » Needs review
StatusFileSize
new517 bytes
new44.21 KB

Totally love this idea :)

This should fix the failing test.

manuel garcia’s picture

Status: Needs work » Needs review

OK thats a new failing test, but I've just run it locally and it passes... random failure?

swentel’s picture

@tim.plunkett

What do you mean config dependencies?

Nevermind that one, completely wrong in my mind :)

swentel’s picture

@tim.plunkett actually, I do remember again re: (config) dependencies. If you add a block in the entity display, a dependency should be added (module I guess) depending on the module that provides that plugin ? Probably in EntityDisplayBase::calculateDependencies ?

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.

tim.plunkett’s picture

StatusFileSize
new44.13 KB

Not sure that we need this still with the Layout Builder work, but here's a reroll anyway.

Status: Needs review » Needs work

The last submitted patch, 24: 2878685-block-field_ui-24.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new44.17 KB

Even more changes to reroll for, from yesterday!

Bojhan’s picture

Issue tags: -Needs usability review

I am going to remove the "Needs usability review" tag.

This looks like a fine direction. I am a bit worried that with "Add block field" we leave out the ability to add "non-block" fields, and that no one knows what a "block" field is. But thats purely a labeling thing.

For the form itself, can you add screenshot of various block configs and how they look embedded in the table?

tim.plunkett’s picture

Here's the Recent Content, Branding, and Menu (initial state and open details) blocks.

jian he’s picture

The patch #26 works great. My question is: Can we display the block title as the field label if "Display title" enabled in block setting?

andypost’s picture

Some blocks can't be placed - main content, site branding

andypost’s picture

Makes sense to have separate issue to discus UX visibility conditions for blocks

andypost’s picture

@tim.plunkett btw maybe do abstraction in #1875974: Abstract 'component type' specific code out of EntityDisplay

  1. +++ b/core/lib/Drupal/Core/Entity/Display/EntityViewDisplayInterface.php
    @@ -46,4 +46,45 @@ public function build(FieldableEntityInterface $entity);
    +  public function getBlockComponents();
    ...
    +  public function getBlock($name);
    ...
    +  public function removeBlock($name);
    ...
    +  public function setBlockComponent($name, array $block_info);
    

    They looks like duplicate of "components"

  2. +++ b/core/lib/Drupal/Core/Entity/Entity/EntityViewDisplay.php
    @@ -263,9 +308,26 @@ public function buildMultiple(array $entities) {
    -      foreach ($this->getComponents() as $name => $options) {
    +      foreach ($this->getComponents() + $this->getBlockComponents() as $name => $options) {
    

    basically components needs derivative types - fields, sections, blocks, extra fields

jonathanshaw’s picture

Following up the UX comments in #27

"I am a bit worried that with "Add block field" we leave out the ability to add "non-block" fields, and that no one knows what a "block" field is. "

Perhaps it should be "Add block" not "Add block field".

Other contrib may also want to add things here, and field group already does. But this is the first time in core so there's no pre-established pattern. Perhaps rather than having a different button for each thing that can be added, the pattern should be a dropbutton here condensing them.

I'm not sure whether this should be done as part of this issue or separate, and if separate whether it should follow after this issue (abstracting out the add functionality) or precede this issue.

Eventually after #1875974: Abstract 'component type' specific code out of EntityDisplay the buttons could be generated dynamically based on component plugin metadata, but the UX pattern can be established independent of this.

andypost’s picture

@jonathanshaw it could be done as selection of type in modalif there will be more then 10 types, but not clear how this action link with dropdown may look like

jian he’s picture

Issue tags: +Needs reroll
jian he’s picture

Issue tags: -Needs reroll
StatusFileSize
new44.28 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 36: 2878685-block-field_ui-36.patch, failed testing. View results

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

Status: Needs work » Needs review
StatusFileSize
new44.05 KB
new580 bytes

Fixed

Status: Needs review » Needs work

The last submitted patch, 40: 2878685-block-field_ui-40.patch, failed testing. View results

tedbow’s picture

Issue summary: View changes
StatusFileSize
new93.57 KB
new43.07 KB
new40.54 KB
new155.68 KB

When this patch is used with Layout builder enabled the field blocks are available which leads to weird behaviour and UX.

I tested it on user manage display admin/config/people/accounts/display/default. I did a clean install and then enabled layout builder

  1. The content field blocks where showing up for some reason and also duplicated
    content blocks duplicated
  2. The user field blocks show up

    but sense all the field blocks show up regardless of whether they view configurable which kind makes that field property useless. Because it doesn't mean what it use to.
  3. also if you have placed a field like picture it is kind of weird next to the non-block field
    the label is exactly the same

    but then they have pretty much have the same settings just in a different form

Should the layout builder itself exclude field blocks from this list?

tim.plunkett’s picture

I'm not even sure we want to do this still. Don't ask me why I bothered to reroll it...

swentel’s picture

I'm not even sure we want to do this still. Don't ask me why I bothered to reroll it...

Yeah, I would just close this too :)

tedbow’s picture

Status: Needs work » Closed (outdated)

Ok closing as outdated because you could now just use Layout Builder to get this functionality and more