Problem/Motivation

Content entities are required to specify the view builder, to be able to view fields. This is for example needed to view configurable fields in views and soon also for the base fields as well: #2342045: Standard views base fields need to use same rendering as Field UI fields, for formatting, access checking, and translation consistency

Proposed resolution

1. Specify the view builder in ContentEntityType
2. refactor FieldItemBase::view()

Remaining tasks

User interface changes

API changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task
Issue priority Normal because nice tags improvement
Disruption Zero Disruption, Will not break any code

Comments

Anushka-mp’s picture

Title: Viewing fields requires a view builder. » Viewing configurable fields requires a view builder.
Anushka-mp’s picture

Status: Active » Needs review
StatusFileSize
new538 bytes

approach 1. added the view builder as a handler to the ContentEntityType::

berdir’s picture

Remember to also remove any occurence of "view_builder" = "Drupal\Core\Entity\EntityViewBuilder" from core.

Anushka-mp’s picture

view builder (EntityViewBuilder) removed from the User & File entities.

dawehner’s picture

Issue tags: +VDC

This is also kinda a blocker for views, isn't it?

olli’s picture

Does this work for shortcut and menulinkcontent which currently dont have a view_builder?

berdir’s picture

Title: Viewing configurable fields requires a view builder. » Viewing fields requires a view builder.
Issue summary: View changes
Issue tags: +DX (Developer Experience)

Updated issue summary a bit.

@dawehner: It's not a blocker, just a DX improvement, you can always specify it yourself, but you have to figure that out and find the right class and so on. And apparently our code relies on its existence.

dawehner’s picture

@berdir
Well, the point is the following: Let's assume you have an entity type with some base fields, but without any kind of view builder.
These views should be available in views, but well, the following code in FIeldItemList will simply fail:

    $view_builder = \Drupal::entityManager()->getViewBuilder($this->getEntity()->getEntityTypeId());
    return $view_builder->viewField($this, $display_options);

as long there is no view builder defined.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

I think this is ready to go.

dawehner’s picture

A beta eval would be nicel

Anushka-mp’s picture

Issue summary: View changes
Anushka-mp’s picture

Issue summary: View changes
Anushka-mp’s picture

Issue summary: View changes
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

It seems sensible to provide a default if we rely on it. I agree that this reduces fragility and improves DX with zero disruption. Committed 6fe3616 and pushed to 8.0.x. Thanks!

Thank you for adding the beta evaluation to the issue summary.

  • alexpott committed 6fe3616 on 8.0.x
    Issue #2446483 by Anushka-mp: Viewing fields requires a view builder
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.