Problem/Motivation

Media is one of the entities, which will be most of the times embedded into other entities.

Currently it's not possible to hide the media name in any display. Which means you have to override the template or preprocess the entity to remove the label. That's all not really handy.

Proposed resolution

Make media name configurable on manage display.

Remaining tasks

Do it.

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chr.fritsch created an issue. See original summary.

chr.fritsch’s picture

Status: Active » Needs review
FileSize
546 bytes

Just setDisplayConfigurable on true for the display context.

Status: Needs review » Needs work

The last submitted patch, 2: 2912298-2.patch, failed testing. View results

chr.fritsch’s picture

Status: Needs work » Needs review
FileSize
2.21 KB
1.3 KB

Ok, fixed the default config

phenaproxima’s picture

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

Discussed briefly with @alexpott and @chr.fritsch, and we decided this will need some sort of test to ensure that we don't accidentally regress the setting later. Something as simple as asserting that the base field is configurable (i.e., in a kernel test) would be sufficient.

chr.fritsch’s picture

Here is the test

The last submitted patch, 4: 2912298-4.patch, failed testing. View results

The last submitted patch, 6: 2912298-6-FAIL.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 6: 2912298-6.patch, failed testing. View results

chr.fritsch’s picture

Ok, now it should be fixed

Status: Needs review » Needs work

The last submitted patch, 10: 2912298-10-FAIL.patch, failed testing. View results

seanB’s picture

Status: Needs work » Reviewed & tested by the community
+++ b/core/modules/media/tests/src/Kernel/MediaTest.php
@@ -20,4 +20,16 @@ public function testEntity() {
+
...
+
...
+

Looks good. We might want to remove the empty lines but that could probably be done on commit. Or not..

phenaproxima’s picture

Cleaned it up.

Gábor Hojtsy’s picture

Hm, how is it shown before the patch? As a base field added to the display?

chr.fritsch’s picture

Before the patch, you were not able to configure the name field on the 'Manage display' page. That means all the logic, if the name should be displayed or not, were in the media.html.twig file.

Gábor Hojtsy’s picture

Ok let me do this question differently then :) How is that without changing that twig file, we get it configurable? This is media.html.twig:

<div{{ attributes }}>
  {#
    In the 'full' view mode the entity label is assumed to be displayed as the
    page title, so we do not display it here.
  #}
  {{ title_prefix }}
  {% if label and view_mode != 'full' %}
    <h2{{ title_attributes }}>
      {{ label }}
    </h2>
  {% endif %}
  {{ title_suffix }}

  {{ content }}
</div>
Gábor Hojtsy’s picture

@chr.fritsch rightfully pointed out that the Media class annotation connects the name media field to the label entity key and that leads to the label variable in twig being populated with name. The patch makes it configurable without needing to modify any templates as a consequence.

One more question from here:

+++ b/core/modules/media/src/Entity/Media.php
@@ -404,6 +404,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
       ->setDisplayConfigurable('form', TRUE)
+      ->setDisplayConfigurable('view', TRUE)

Is this enough as an "upgrade path" for existing sites? We'll definitely not update their active config, so no need to even look into adding the configurable name there, just wondering about whether this makes it possible to add it to the active config on sites that get updated.

chr.fritsch’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
2.83 KB

Yes, it is. The name field is already in the display. We don't change that. We just enable the name field to be configurable. So a cache clear is everything that needs to be done, to see the name field on 'Manage display'.

I rerolled the patch, because #2883813: Move File/Image media type into Standard once Media is stable landed. There is no interdiff, because only thing that changed were the path of the entity_view_display files.

chr.fritsch’s picture

Status: Needs review » Reviewed & tested by the community

Re-RTBC per #12

  • Gábor Hojtsy committed 342b492 on 8.5.x
    Issue #2912298 by chr.fritsch, phenaproxima: Make media name available...
Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Yay, ok, I got it finally. Superb. Committed.

rwam’s picture

Status: Fixed » Needs review
FileSize
6.15 KB

It would be great to have a patch for current 8.4.x too, because the provided patch failed on current version 8.4.0. So I've tried to create a patch for the 8.4.x branch.

Please have a look and sorry if I do something wrong.

Ciao
Ralf

Gábor Hojtsy’s picture

Status: Needs review » Needs work

I'm not 100% sure this is allowed on 8.4.x, would need to check with other committers. However the config should definitely not be in the standard profile in 8.4.x.

rwam’s picture

Hi, I take the config from the 8.5.x branch, so I thought it was ok. The code changes work on 8.4.0. Now I can manage display for the name.

rwam’s picture

You are right, the config should be situated in the module, so I create a new patch to handle this.

But then the 8.5.x branch should be adapted accordingly, shouldn't it?

Gábor Hojtsy’s picture

No, in 8.5.x the config is in the standard profile following #2883813: Move File/Image media type into Standard once Media is stable.

rwam’s picture

Status: Needs work » Needs review

Ah ok, I didn‘t noticed that. So please have a look at #25 for 8.4.x.

phenaproxima’s picture

Version: 8.5.x-dev » 8.4.x-dev

#25 will only apply to 8.4.x, and is not needed in 8.5.x as @Gábor Hojtsy points out, so I'm changing the branch.

phenaproxima’s picture

Issue tags: +Media Initiative

I think the patch looks good. I don't think I can RTBC, but if someone else can...

bdimaggio’s picture

Status: Needs review » Reviewed & tested by the community

Yep, tested with 8.4.2 and this works just as it should.

  • larowlan committed 7a8ffbf on 8.4.x
    Issue #2912298 by chr.fritsch, rwam, phenaproxima, Gábor Hojtsy: Make...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +DrupalSouth 2017

Committed as 7a8ffbf and pushed to 8.4.x

Status: Fixed » Closed (fixed)

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