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
Comment | File | Size | Author |
---|---|---|---|
#66 | 2939931-nr-bot.txt | 144 bytes | needs-review-queue-bot |
#61 | interdiff_57-61.txt | 1.1 KB | Neslee Canil Pinto |
#61 | 2939931-61.patch | 5.09 KB | Neslee Canil Pinto |
#57 | interdiff-2939931-56-57.txt | 1.68 KB | mohit_aghera |
#57 | 2939931-57.patch | 5.09 KB | mohit_aghera |
Comments
Comment #2
tim.plunkettSomething like this?
Comment #3
jibranThere is @todo left in
\Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay::label
Comment #4
tim.plunkettYeah this was written before that got committed.
Here's an updated version.
Comment #5
jibranWhy can't we just concatenate these strings and not use
TranslatableMarkup
?Comment #6
tim.plunkettI'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".
Comment #10
jhedstromPatch no longer applies.
Comment #11
heykarthikwithure-rolled the patch
Comment #12
jungleCall
$this->entityTypeBundleInfo()
intead of\Drupal::service('entity_type.bundle.info')
Furthermore, the first two lines seem unnecessary, call
$target_entity_type->getBundleLabel()
directly.do not understand why calling
$target_entity_type->getPluralLabel()
here, should it be$target_entity_type->getLabel()
?Where is the mode in the label?
Comment #13
jungleAddressed, #12.1,2,3
Comment #14
tim.plunkettLet's get some real examples of what this change means for Layout Builder.
Before/After screenshots are needed.
Comment #15
jungleUpdating the patch first, interdiff ignored as the patch is small. screenshots coming soon.
Tested that can not use
getBundleOf()
to distinguish whether it has bundles.And can not get bundle label by calling getBundleLabel() too
Comment #16
jungleBefore
After
user with default view mode
Comment #17
jungleBTW, 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.Comment #18
tim.plunkettThis 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.
Comment #19
jungle+1 to use the label of display mode instead of its machine name
Comment #20
tim.plunkettComment #21
shaktikthe path did not apply success on Drupal 9.1, see screenshot.
Comment #22
shaktikComment #23
shaktikComment #24
neclimdulthis chunk was removed in the latest patch.
Comment #25
shaktikHi neclimdul,
Removed unused code, Kindly check.
Comment #26
Rkumar CreditAttribution: Rkumar as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedWorking fine for me.
For my side, it's ready to RTBC +1
Comment #27
jungleBTW, this is not RTBC ready, There is a
Needs usability review
tag still.Comment #28
jungleSorry, reverting the unintentional change made to IS
Comment #29
jungleRerolled 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.
Comment #30
jungleUsing display mode label, instead of the machine name.
Updating IS
Comment #31
jungleHide files
Comment #32
jungleUpdating before-after image in IS
Comment #33
ckrinaFirst, 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:
Comment #38
larowlanClosed #3099612: EntityFormDisplay and EntityViewDisplay should implement label() as duplicate, assigning credit for folks over there
Comment #39
larowlanThis makes a nice UX improvement, thanks!
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.
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
Comment #40
nitesh624Comment #41
nitesh624@larowlan do we consider changing the things that mentioned in #33
Comment #42
jungle@nitesh624, yes, #33 must be addressed which is the result of Usability review during the meeting #3135889: Drupal Usability Meeting 2020-05-19
Comment #43
neclimdulI 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
Comment #44
jungleSorry, @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.
Comment #45
nitesh624Changes done as per Drupal Usability Meeting 2020-05-19 in #33
Layout form for user
Layout form for article content type in default view mode
Layout form for article content type in teaser view mode
Comment #46
nitesh624Comment #47
tim.plunkettThanks for those changes, they look good! Still NW for #39
Comment #48
shaktikAddressed, #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?
Comment #49
shaktikComment #51
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedlooks like unrelated failure.
Comment #53
shaktikpatch #49 Applied on 9.2.x
Comment #54
tim.plunkettNW for tests
This can be moved to an `else` case
Instead of retrieving
['label']
directly, this should call getFormModeOptions/getViewModeOptionsNo need for another local variable here
Comment #55
nikitagupta CreditAttribution: nikitagupta at Srijan | A Material+ Company for Drupal India Association commentedAddressed #54.
Comment #56
nikitagupta CreditAttribution: nikitagupta at Srijan | A Material+ Company for Drupal India Association commentedfixed the failed testcase.
Comment #57
mohit_aghera CreditAttribution: mohit_aghera at QED42 commented- Adding a few test cases to validate the title.
For the regular fieldable entity, I couldn't add it to
testLayoutBuilderUi
test case as it was interfering other test assertions because we have to put the page title block.-
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.Comment #59
Kristen PolThanks for the tests. Reviewed the interdiff.
Nitpick: Consider slight rewording:
Tests that the appropriate title exists on the manage layout page.
Nitpick: Single quotes can be used instead of double quotes.
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.
Comment #60
Kristen PolMoving back to needs work for consideration of #59.
Comment #61
Neslee Canil Pinto@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?
Comment #62
Kristen PolThanks 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.
Comment #66
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe 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.