Problem/Motivation

Neither EntityFormDisplay nor EntityViewDisplay have a label key, and as such their ::label() method returns NULL.

Proposed resolution

Implement ::label(), returning a string indicating which entity type, bundle, and view mode are represented.

Remaining tasks

Decide on the string to present and then use it in the Field UI.

User interface changes

Steps to check the label with the Layout builder module installed first:

Node:【Structure】->【Content types】->【Article】->【Manage Display】->【Default】/【Teaser】mode ->【 Use Layout Builder】->【Manage Layout】

User:【Configuration】->【Account Settings】->【Manage Display】->【Default】mode ->【 Use Layout Builder】->【Manage Layout】

API changes

Data model changes

CommentFileSizeAuthor
#66 2939931-nr-bot.txt144 bytesneeds-review-queue-bot
#61 interdiff_57-61.txt1.1 KBNeslee Canil Pinto
#61 2939931-61.patch5.09 KBNeslee Canil Pinto
#57 interdiff-2939931-56-57.txt1.68 KBmohit_aghera
#57 2939931-57.patch5.09 KBmohit_aghera
#56 interdiff_55-56.txt806 bytesnikitagupta
#56 2939931-56.patch3.42 KBnikitagupta
#55 interdiff_49-55.txt1.56 KBnikitagupta
#55 2939931-55.patch3.42 KBnikitagupta
#51 Screenshot 2020-10-12 at 11.28.10 PM.png36.58 KBanmolgoyal74
#49 interdiff_45-49.txt1.09 KBshaktik
#49 2939931-49.patch3.17 KBshaktik
#45 edit_layout_article_teaser.png48.37 KBnitesh624
#45 edit_layout_user.png40.5 KBnitesh624
#45 edit_layout_article.png48.37 KBnitesh624
#45 interdiff_30-40.txt792 bytesnitesh624
#45 2939931-45.patch3.2 KBnitesh624
#33 subtitle-exploration.png35.3 KBckrina
#32 2939931-31-label-before-after.png972.1 KBjungle
#30 2939931-30.patch3.19 KBjungle
#30 2939931-label-before-after.png791.71 KBjungle
#29 2939931-29.patch2.55 KBjungle
#29 raw-interdiff-15-29.txt622 bytesjungle
#26 Screenshot 2020-05-15 at 3.22.38 PM.png182.47 KBRkumar
#25 after-patch-apply.png131.05 KBshaktik
#25 removed-unuse-code-2939931-25.patch2.58 KBshaktik
#22 2939931-22.patch1.49 KBshaktik
#21 Screen Shot 2020-05-04 at 14.15.45.png118.26 KBshaktik
#16 after-node-artical-teaser.png95.97 KBjungle
#16 after-node-article-default.png95.63 KBjungle
#16 after-user-default.png92.19 KBjungle
#16 before-node-artical-teaser.png82.02 KBjungle
#16 before-node-article-default.png82.93 KBjungle
#16 before-user-default.png80.49 KBjungle
#15 2939931-15.patch2.54 KBjungle
#13 interdiff-11-13.txt1.22 KBjungle
#13 2939931-13.patch2.35 KBjungle
#11 2939931-11.patch2.22 KBheykarthikwithu
#4 2939931-enttiy_display_label-3.patch2.26 KBtim.plunkett
#2 2939931-entity_display_label-2.patch1.19 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

Status: Active » Needs review
FileSize
1.19 KB

Something like this?

jibran’s picture

Status: Needs review » Needs work

There is @todo left in \Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::label

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
2.26 KB

Yeah this was written before that got committed.
Here's an updated version.

jibran’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
@@ -247,6 +248,16 @@ public function id() {
+    return new TranslatableMarkup('@bundle @label', ['@bundle' => $bundle_label, '@label' => $target_entity_type->getPluralLabel()]);

Why can't we just concatenate these strings and not use TranslatableMarkup?

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs review

I'm not 100% sure that this is the correct way to do it. This is just copying from the experimental module.

1)
Should we continue concatenating it like this?
Since nodes are called "content items", for the node.article.default entity display this would result in Article content items.
But that would also be the same for node.article.teaser, node.article.rss, and any other view mode.
I just couldn't think of a good way to include the view mode in the label.

2)
Should this ignore the bundle if the entity type provides no bundles (aka, the bundle is the entity type, i.e. for the User entity?)
Currently I think the user entity display has the string User user entities, which is very not ideal.

3)
If we're sure that each part of the combined new string is already translatable, should we simply concatenate them instead of running them through t()/TranslatableMarkup again?
I think I know the answer to this one: yes
Because if it were a regular adjective noun pairing in English like "Article content", in Spanish it would be "Contenido del artículo".

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.

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.

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.

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

heykarthikwithu’s picture

Status: Needs work » Needs review
FileSize
2.22 KB

re-rolled the patch

jungle’s picture

Assigned: Unassigned » jungle
Status: Needs review » Needs work
Issue tags: -Needs reroll
  1. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -606,4 +607,14 @@ protected function getLogger() {
    +    $bundle_info = \Drupal::service('entity_type.bundle.info')->getBundleInfo($this->getTargetEntityTypeId());
    +    $bundle_label = $bundle_info[$this->getTargetBundle()]['label'];
    +    $target_entity_type = $this->entityTypeManager()->getDefinition($this->getTargetEntityTypeId());
    

    Call $this->entityTypeBundleInfo() intead of \Drupal::service('entity_type.bundle.info')

    Furthermore, the first two lines seem unnecessary, call $target_entity_type->getBundleLabel() directly.

  2. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -606,4 +607,14 @@ protected function getLogger() {
    +    return new TranslatableMarkup('@bundle @label', ['@bundle' => $bundle_label, '@label' => $target_entity_type->getPluralLabel()]);
    

    do not understand why calling $target_entity_type->getPluralLabel() here, should it be $target_entity_type->getLabel() ?

  3. Implement ::label(), returning a string indicating which entity type, bundle, and view mode is represented.

    -- from IS

    Where is the mode in the label?

jungle’s picture

Assigned: jungle » Unassigned
Status: Needs work » Needs review
FileSize
2.35 KB
1.22 KB

Addressed, #12.1,2,3

tim.plunkett’s picture

Status: Needs review » Needs work
Issue tags: +Needs screenshots

Let's get some real examples of what this change means for Layout Builder.
Before/After screenshots are needed.

jungle’s picture

FileSize
2.54 KB

Updating the patch first, interdiff ignored as the patch is small. screenshots coming soon.

  1. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -606,4 +607,20 @@ protected function getLogger() {
    +    if ($target_entity_type->getBundleOf() === NULL) {
    

    Tested that can not use getBundleOf() to distinguish whether it has bundles.

  2. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -606,4 +607,20 @@ protected function getLogger() {
    +      '@bundle' => $target_entity_type->getBundleLabel(),
    

    And can not get bundle label by calling getBundleLabel() too

jungle’s picture

Before

  • user with default view mode
  • node article with default view mode
  • node article with teaser view mode

After

  • user with default view mode

  • node article with default view mode

  • node article with teaser view mode

jungle’s picture

BTW, the display mode in use is its machine name, if it's necessary to display the label, entity_display.repository is the right service to continue with.

tim.plunkett’s picture

This issue was about adding the existing implementation for wider use in core. If you also want to change the implementation, this will need UX signoff.
Changing from "content items" back to "Content" is probably not ideal. Nor is using machine names in UI text.

jungle’s picture

Issue tags: +ux

+1 to use the label of display mode instead of its machine name

tim.plunkett’s picture

Version: 8.9.x-dev » 9.1.x-dev
Status: Needs review » Needs work
Issue tags: -ux +Needs usability review, +Usability
shaktik’s picture

Assigned: Unassigned » shaktik
FileSize
118.26 KB

the path did not apply success on Drupal 9.1, see screenshot.
patch fail

shaktik’s picture

shaktik’s picture

Status: Needs work » Needs review
neclimdul’s picture

Status: Needs review » Needs work
+++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php
@@ -365,18 +365,6 @@ protected function getRuntimeSections(FieldableEntityInterface $entity) {
-  /**
-   * {@inheritdoc}
-   *
-   * @todo Move this upstream in https://www.drupal.org/node/2939931.
-   */
-  public function label() {
-    $bundle_info = \Drupal::service('entity_type.bundle.info')->getBundleInfo($this->getTargetEntityTypeId());
-    $bundle_label = $bundle_info[$this->getTargetBundle()]['label'];
-    $target_entity_type = $this->entityTypeManager()->getDefinition($this->getTargetEntityTypeId());
-    return new TranslatableMarkup('@bundle @label', ['@bundle' => $bundle_label, '@label' => $target_entity_type->getPluralLabel()]);
-  }
-

this chunk was removed in the latest patch.

shaktik’s picture

Assigned: shaktik » Unassigned
Status: Needs work » Needs review
FileSize
2.58 KB
131.05 KB

Hi neclimdul,

Removed unused code, Kindly check.

Rkumar’s picture

Working fine for me.
For my side, it's ready to RTBC +1

jungle’s picture

Issue summary: View changes

BTW, this is not RTBC ready, There is a Needs usability review tag still.

jungle’s picture

Issue summary: View changes

Sorry, reverting the unintentional change made to IS

jungle’s picture

Rerolled a patch from #15 directly, as #25 has one coding standard violation.

Assigning to myself and making this issue reviewable for #3135889: Drupal Usability Meeting 2020-05-19.

jungle’s picture

Assigned: jungle » Unassigned
Issue summary: View changes
Status: Needs work » Needs review
FileSize
791.71 KB
3.19 KB

Changing from "content items" back to "Content" is probably not ideal. Nor is using machine names in UI text.

Using display mode label, instead of the machine name.

Updating IS

jungle’s picture

Hide files

jungle’s picture

Issue summary: View changes
FileSize
972.1 KB

Updating before-after image in IS

ckrina’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: -Needs usability review, -Usability
FileSize
35.3 KB

First, thanks everybody for your work! We reviewed this during today's weekly UX meeting and after a long discussion we've decided that this issue would ideally just add the view mode in parenthesis after the title. So this should ideally be:

Bundle title + current plural label + (View mode name in parenthesis)

So it would be like: Article content items (Teaser) or Category taxonomy terms (Default).

The reason behind it is that adding "Content:" before article has 2 backsides. First, it moves away the real item/title that makes reference to what we're editing (Bundle is more relevant here than the Entity type). Second, it makes confusing for someone without experience understanding the meaning of the label "Content" there. And adding "Entity type: Content" is too long.

Also, the _ideal_ solution should go through adding a new element below the title to add additional information. Like a subtitle or a tag. Here's a really really quick exploration that probably would need another issue + proper discussion:

larowlan credited sja112.

larowlan’s picture

Closed #3099612: EntityFormDisplay and EntityViewDisplay should implement label() as duplicate, assigning credit for folks over there

larowlan’s picture

Issue tags: +Needs tests

This makes a nice UX improvement, thanks!

  1. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -570,4 +571,39 @@ protected function getLogger() {
    +    // The target entity type has no bundles, such as the user entity.
    +    if ($target_entity_type->getBundleEntityType() === NULL) {
    

    Unfortunately, this isn't true.

    Entities can have bundles without having an entity bundle type, there's hook_entity_bundle_info and a corresponding alter hook.

    You need to use the entity_type.bundle.info service to ascertain if the entity supports bundles.

  2. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -570,4 +571,39 @@ protected function getLogger() {
    +    $bundle_info = $this->entityTypeBundleInfo()->getBundleInfo($target_entity_type_id);
    

    oh! and we already have that here too

There's a fair bit going on in that method now, so I think we need some test coverage - probably simpler to do as a kernel test

nitesh624’s picture

Assigned: Unassigned » nitesh624
nitesh624’s picture

@larowlan do we consider changing the things that mentioned in #33

jungle’s picture

@nitesh624, yes, #33 must be addressed which is the result of Usability review during the meeting #3135889: Drupal Usability Meeting 2020-05-19

neclimdul’s picture

Assigned: nitesh624 » Unassigned

I was really confused catching up trying to remember what I said until I realized there was another n name in the discussion talking about 33. Lol

jungle’s picture

Sorry, @neclimdul, I meant to reply @nitesh624. Blame me and dreditor :p hitting TAB after typing @n, dreditor autocompleted with your username. in #42. corrected/edited.

nitesh624’s picture

Changes done as per Drupal Usability Meeting 2020-05-19 in #33

Layout form for user

edit_layout_user

Layout form for article content type in default view mode

edit_layout_article default

Layout form for article content type in teaser view mode

edit_layout_article teaser

nitesh624’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Status: Needs review » Needs work

Thanks for those changes, they look good! Still NW for #39

shaktik’s picture

Status: Needs work » Needs review

Addressed, #39.1
Please check. #39 2 please suggest me for a test case in which kernel file or need to create new kernel test file?

shaktik’s picture

Status: Needs review » Needs work

The last submitted patch, 49: 2939931-49.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
36.58 KB

looks like unrelated failure.

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.

shaktik’s picture

patch #49 Applied on 9.2.x

tim.plunkett’s picture

Status: Needs review » Needs work

NW for tests

  1. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -571,4 +572,39 @@ protected function getLogger() {
    +    $mode_label = new TranslatableMarkup('Default');
    +    if ($mode !== 'default') {
    

    This can be moved to an `else` case

  2. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -571,4 +572,39 @@ protected function getLogger() {
    +      $modes = $this->displayContext === 'form' ? $entity_display_repository->getFormModes($target_entity_type_id) : $entity_display_repository->getViewModes($target_entity_type_id);
    +      $mode_label = $modes[$mode]['label'];
    

    Instead of retrieving ['label'] directly, this should call getFormModeOptions/getViewModeOptions

  3. +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php
    @@ -571,4 +572,39 @@ protected function getLogger() {
    +    $bundle_label = $bundle_info[$this->getTargetBundle()]['label'];
    ...
    +      '@bundle' => $bundle_label,
    

    No need for another local variable here

nikitagupta’s picture

nikitagupta’s picture

fixed the failed testcase.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
5.09 KB
1.68 KB

- Adding a few test cases to validate the title.
For the regular fieldable entity, I couldn't add it to testLayoutBuilderUitest case as it was interfering other test assertions because we have to put the page title block.

+++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
@@ -1235,6 +1236,26 @@ public function testBreadcrumb() {
+  public function testLayoutBuilderPageTitle() {
+    $this->drupalPlaceBlock('page_title_block');
+    $assert_session = $this->assertSession();
+
+    $this->drupalLogin($this->drupalCreateUser([
+      'configure any layout',
+      'administer node display',
+      'administer node fields',
+    ]));
+
+    // From the manage display page, go to manage the layout.
+    $this->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default");

- InstallUninstallTest::testInstallUninstall test case seems to be passing on local. It just takes a while to run all the test cases as there are approx 2700 assertions. Let's see how it goes.

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.

Kristen Pol’s picture

Thanks for the tests. Reviewed the interdiff.

  1. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -1235,6 +1236,26 @@ public function testBreadcrumb() {
    +   * Test to ensure that appropriate title exists on manage layout page.
    

    Nitpick: Consider slight rewording:

    Tests that the appropriate title exists on the manage layout page.

  2. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -1235,6 +1236,26 @@ public function testBreadcrumb() {
    +    $this->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default");
    

    Nitpick: Single quotes can be used instead of double quotes.

  3. +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php
    @@ -1235,6 +1236,26 @@ public function testBreadcrumb() {
    +    $assert_session->elementTextContains('css', '.page-title', 'Edit layout for Bundle with section field content items (Default)');
    

    This one seems a bit odd to me... we can only check via the CSS? I do see two examples (below) of something similar in other code but it feels awkward to me.

    KristenBackupMBP:drupal-9.2.x-dev admin$ grep -r elementTextContains . | grep css | grep page-title
    ./core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php:    $assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these test entity - revisions, data table, and published interface entities?');
    ./core/tests/Drupal/FunctionalTests/Entity/DeleteMultipleFormTest.php:    $assert->elementTextContains('css', '.page-title', 'Are you sure you want to delete these test entity - revisions entities?');
    
    
Kristen Pol’s picture

Status: Needs review » Needs work

Moving back to needs work for consideration of #59.

Neslee Canil Pinto’s picture

Status: Needs work » Needs review
FileSize
5.09 KB
1.1 KB

@Kristen Pol regarding 3rd point from #59 as you have posted the examples for it, i think we can use it for now until all of them will be removed. What do you think?

Kristen Pol’s picture

Thanks for the update. If we know of a better way to test it, then it would be nice to do it now and perhaps make a follow-up issue for those other places. But I'm not an expert on tests, so maybe someone else can chime in here.

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.

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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
FileSize
144 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

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.