Problem/Motivation

From #2831943: Use "rendered media" (not links) as default media field formatter; add modal to configure the used media view mode:

Proposed resolution

  • Change the label of "Bundles" in the Reference Type section to "Media types" to match what's used elsewhere (like admin/structure/media).
  • Make the purpose of "Sort by" more clear.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

xjm created an issue. See original summary.

xjm’s picture

wim leers’s picture

Issue tags: +Usability, +Media Initiative

+1, I still have no idea what the "Sort by" is for. The label is an easy fix.

wim leers’s picture

Status: Active » Needs review
StatusFileSize
new930 bytes
new21.56 KB

This is a problem in \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection, not in Media. We can solve this generically.

Here's a first iteration.

wim leers’s picture

Status: Needs review » Needs work
wim leers’s picture

Component: media system » entity system

Forgot to do this.

marcoscano’s picture

How about moving all secondary choices to a collapsed fieldset by default?

collapsed

collapsed

berdir’s picture

Title: Improve Entity Reference field settings UI for Media fields » Improve Entity Reference field settings UI
+++ b/core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php
@@ -130,7 +130,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
         '#type' => 'checkboxes',
-        '#title' => $this->t('Bundles'),
+        '#title' => $entity_type->getBundleLabel(),

Fully agree with this, quite likely we have existing issues about it, actually.

What happens if an entity type doesn't do this? In ctools, I ended up adding a fallback like \Drupal\ctools\Plugin\Deriver\EntityBundle::getEntityBundleLabel(). The core replacement for that also contains that method, maybe we could inline it into getBundleLabel()?

Removing for "for Media fields", because this is generic, even if we tried we couldn't really improve it only for Media :)

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.

xjm’s picture

Title: Improve Entity Reference field settings UI » Use the bundle label (e.g. "Media type") instead of "Bundles" in the Entity Reference field configuration

The current proposal of moving these advanced settings into yet another collapsed fieldset is actually sort of #1953568: Make the bundle settings for entity reference fields more visible.. We can:

  1. Move the bundle checkboxes to the top of the form for all entity reference fields, and stick everything else in "Advanced reference settings" which is collapsed by default. Or something like that. That's #1953568: Make the bundle settings for entity reference fields more visible..
  2. Get a description on the "Sort" field to answer the "Sort what, where?" question. (Needs issue.)
  3. Fix the "Bundles" field label for all entity reference fields to use the bundle label, with a sensible fallback. That can be this issue. What I don't get is why only Media fields seem to have this mislabeling; is it already being overridden for nodes, taxonomy, etc.? If so we should remove those overrides and let it use this dynamic default.
Bojhan’s picture

Priority: Normal » Major

I am going to mark this major, since Media is a big new functionality piece and most users who use it will be confronted with this difficult labeling.

My preference goes to the labeling in #4

vijaycs85’s picture

Status: Needs work » Needs review
StatusFileSize
new81.81 KB
new3.63 KB
new47.05 KB

#10.1 - Tried, but when we move out of handler_settings,
a. Can't move close to title, but above fieldset(ref attachment)
b. Saving bundle value to field config is not working.
#10.2 - Added description, but happy to update, if not clear.
#10.3 - Managed to remove bundle specific titles to be more consistent.

amateescu’s picture

Status: Needs review » Needs work

It looks like the patch in #12 contains some other patch that's not meant for this issue.

Looking at the @xjm's list from #10, it seems that we only need fix #10.3. There an existing one for #10.1 and we need to open a separate one for #10.2.

Also, #8 was not addressed.

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new3.1 KB

Agree with the separation of concerns proposed in #10.

So:
1)
#10.1 will be solved in #1953568: Make the bundle settings for entity reference fields more visible.

2)
I have opened #2927819: Clarify what "Sort by" on EntityReference field configuration form means for #10.2

3)
The patch attached intends to solve #10.3.
Re: #8, sorry for my noobiness, but I'm not fully confident I understand what the proposal is there. I have tried to address the fallback in the patch the same way ctools does, but I have the feeling that this is not what was being proposed. Can't think of anything else, please let me know if the suggestion was for something different and I just didn't get it :)

Sorry for not providing an interdiff, #12 has a lot of unrelated changes and it wouldn't make sense. This patch iterates on #4, with the suggestions from #8 and #10.3.

berdir’s picture

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

Ah, *this* is the issue where I suggested to add that logic directly in getBundleLabel().

This is also needed by #1932810: Add entity bundles condition plugin for entities with bundles, which needs that same chunk of code *twice*. Which is why I suggested to implement the fallback directly inside of that method. Of course then that's again out of scope and we'd end up doing yet another separate issue and postponing this. Maybe we can get feedback from a core maintainer on whether we're allowed to smuggle that addition in here?

Looks like we're not really testing those custom labels anywhere, because the new ones are different (plural, Available prefix), which I think is OK, but we should add a few assertText()'s in some hopefully already existing tests.

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new4.24 KB
new3.08 KB

Thanks for the feedback!

Something like this you mean?

berdir’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/EntityType.php
    @@ -677,7 +677,15 @@ public function getBundleOf() {
    +    // If there is no bundle label defined, try to provide some sensible
    +    // fallbacks.
    +    if (!empty($this->bundle_label)) {
    +      return (string) $this->bundle_label;
    +    }
    +    elseif ($bundle_entity_type_id = $this->getBundleEntityType()) {
    +      return (string) \Drupal::entityTypeManager()->getDefinition($bundle_entity_type_id)->getLabel();
    +    }
    +    return (string) $this->getLabel();
    

    Something like that, yes, but the last should be "$this_entity_type_label bundle", as a translatable string. E.g. if node would not define a bundle label or bundle entity type, we'd fall back to "Node bundle", your code would just return "Node".

  2. +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php
    @@ -94,6 +94,9 @@ public function testFieldAdminHandler() {
         // The base handler settings should be displayed.
         $entity_type_id = 'node';
    +    // Check that the type label is correctly displayed.
    +    $entity_type = \Drupal::entityTypeManager()->getDefinition($entity_type_id);
    +    $this->assertText($entity_type->getBundleLabel());
         $bundles = $this->container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id);
    

    we hardcode the entity type, so maybe we should also hardcode the expected label, makes the test easier to read IMHO?

marcoscano’s picture

StatusFileSize
new4.18 KB
new1.56 KB

Oh I see. Let's try this one then.

Thanks!

Status: Needs review » Needs work

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

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new4.18 KB
new636 bytes
xjm’s picture

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

This looks pretty good.

  1. +++ b/core/lib/Drupal/Core/Entity/EntityType.php
    @@ -677,7 +677,15 @@ public function getBundleOf() {
    +      return (string) \Drupal::entityTypeManager()->getDefinition($bundle_entity_type_id)->getLabel();
    

    My kneejerk here was that the entity type manager should be injected. Edit: Or is it already available somehow otherwise? Thoughts?

  2. Let's add tests for each of the three scenarios WRT bundle labeling.
  3. Can we create a couple screenshots of what this looks like for Media, Taxonomy, Node, and User reference fields? (And compare with HEAD if it's different.

Thanks!

berdir’s picture

1. This is an annotation class (=the plugin definition, not the plugin), we can't inject things there. This is also not the first case where we have this, see \Drupal\Core\Entity\EntityType::getBundleConfigDependency() for example. The only thing we could possible do is add a $this->getEntityTypeManager() wrapper, but it will still need to call out to \Drupal.

benjifisher’s picture

StatusFileSize
new70.19 KB
new88.54 KB
new68.19 KB
new83.39 KB

We looked at this issue during the weekly UX meeting. I missed most of the discussion, but I was able to make some screenshots.

Here are the screens for adding/editing a taxonomy term or a Media reference without any patch:
taxonomy term reference without the patch

media reference without the patch

Here are the screens for adding/editing a taxonomy term or a Media reference with the patch from #20:

media reference with the patch

taxonomy term reference with patch

marcoscano’s picture

Status: Needs work » Needs review
Issue tags: -Needs screenshots
StatusFileSize
new5.2 KB
new1.02 KB
new41.89 KB
new42.59 KB
new41.96 KB

Thanks @xjm, @Berdir and @benjifisher!

Here an updated patch with some tests.
I don't know how to test our intermediate fallback, suggestions welcome :)
But I was wondering that once Drupal\Core\Entity\EntityType::getLabel() is already covered by Drupal\Tests\Core\Entity\EntityTypeTest::testGetLabel(), and the bundle will also be an entity type, maybe that's implicitly covered?

@benjifisher uploaded before/after screenshots for Taxonomy Terms and Media in #23, so I'm just uploading here the remaining ones (Nodes and Users):

Nodes HEAD:

nodes before

Nodes with the patch:

nodes after

Users HEAD and with the patch (no change):

users no change

Status: Needs review » Needs work

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

amateescu’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/EntityType.php
    @@ -677,7 +677,15 @@ public function getBundleOf() {
    -    return (string) $this->bundle_label;
    ...
    +    return t('@type_label bundle', ['@type_label' => $this->getLabel()]);
    

    The return value of this method is documented to be a string (in \Drupal\Core\Entity\EntityTypeInterface::getBundleLabel) but now we might also return a TranslatableMarkup object, so the fallback is missing a (string) cast.

    Also, we should be using new TranslatableMarkup() directly instead of t() in non-procedural code.

  2. +++ b/core/modules/field/src/Tests/EntityReference/EntityReferenceAdminTest.php
    @@ -94,6 +94,8 @@ public function testFieldAdminHandler() {
    +    // Check that the type label is correctly displayed.
    +    $this->assertText('Content type');
    
    +++ b/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
    @@ -22,15 +22,6 @@ class NodeSelection extends DefaultSelection {
    -    $form['target_bundles']['#title'] = $this->t('Content types');
    

    The previous code was displaying the plural form of the bundle label, and the new code is displaying the singular form. Is that a concern that we might need to address?

marcoscano’s picture

StatusFileSize
new5.23 KB
new659 bytes

@amateescu thanks for the feedback!

This addresses #26.1.

Concerning

The previous code was displaying the plural form of the bundle label, and the new code is displaying the singular form. Is that a concern that we might need to address?

I was assuming that this was an intended (or at least expected) change, in favor of standardization and removing "special cases". IMHO the singular form is as understandable as the plural (and checkboxes already indicate you can select more than one), but that's just my opinion, I'm no UX expert :)

Thanks!

marcoscano’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

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

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new5.34 KB
new1.31 KB

Status: Needs review » Needs work

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

marcoscano’s picture

Status: Needs work » Needs review
StatusFileSize
new6.07 KB
new753 bytes
amateescu’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Ok, we have passing tests now so the patch looks ready to me.

The question from #26.2 is still outstanding, but maybe a committer can decide..

berdir’s picture

+++ b/core/modules/taxonomy/src/Plugin/EntityReferenceSelection/TermSelection.php
@@ -38,8 +38,6 @@ public function defaultConfiguration() {
 
-    $form['target_bundles']['#title'] = $this->t('Available Vocabularies');
-

Slightly different variations of plural forms even, yes :)

That change is fine with me, we all know that generic plural forms of labels are crazy complicated :)

xjm’s picture

This looks great to me. Thanks for the screenshots.

Saving issue credit.

  • xjm committed a4dd446 on 8.5.x
    Issue #2895001 by marcoscano, vijaycs85, Wim Leers, benjifisher, xjm,...
xjm’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +String change in 8.5.0

Oh regarding #26.2, I think the singular label is actually more correct/semantic, plus plural label translation stuff as mentioned.

Patch had:

FILE: ...dules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 6 | WARNING | [x] Unused use statement
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Fixed on commit with:

diff --git a/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php b/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
index 747cacaae7..2f26393c2e 100644
--- a/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
+++ b/core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php
@@ -3,7 +3,6 @@
 namespace Drupal\node\Plugin\EntityReferenceSelection;
 
 use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
-use Drupal\Core\Form\FormStateInterface;
 use Drupal\node\NodeInterface;
 
 /**

Committed and pushed to 8.5.x. Thanks!

jibran’s picture


  /**
   * Gets the label for the bundle.
   *
   * @return string|null
   *   The bundle label, or NULL if none exists.
   */
  public function getBundleLabel();

It can't be NULL anymore so this doc block needs update.

marcoscano’s picture

StatusFileSize
new535 bytes

Ouch. Too late for this?

jibran’s picture

Please create a followup.

Status: Fixed » Closed (fixed)

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