The following review and action items is the result of discussion between @catch, @alexpott, @seanB, @phenaproxima, and myself. Most of it is followup stuff. Enjoy!

Remove from patch into "must" or "should" followups

These things should be removed from the patch so that they can be reviewed on their own without blocking the issue. Each should be mentioned in the change record with a link to the followup issue.

In the case of some parts, we might reduce the scope and add the rest back later; in other cases, the functionality might not need to be in core. But we'll discuss each in a dedicated issue. Be sure to add the notes below to the applicable summaries.

  1. Token integration. media_token_info(), test coverage, etc. This is a "must" followup because it is required for pathauto support. From @catch:

    do we really need tokens for vid and uuid, even node doesn’t provide uuid.

    This is done in #8 and the follow-up has been filed: #2877378: Add token replacements for Media.

  2. Actions integration, including all test coverage for it, configuration, SaveMedia action, etc. This should be a "Should" followup since we are unsure how much contrib needs this. There should also be a related followup for generic entity actions (as per tstoeckler's suggestion early on the issue). From @catch:

    The actions are in config/optional but the only thing they depend on is media and system therefore they are always going to be installed. If they are there they should be in config/install.

    Also, in particular:

    SaveMedia::execute() is weird setting changed to 0

    This was copied over from node and may not be needed?
    @catch also notes that the action itself is weird and might not be needed even if we add the media actions in core.
    This is done in #6 and the follow-up has been filed: #2877383: Add action support to Media module.

  3. Remove forced validation in Media::preSave() and file a followup to discuss presave validation for Media and/or for entities in general ("Should"): #2877397: Determine when and if media items should validate themselves
    This is done in #19
  4. Remove full view mode and "tricky" template title handling. There are many valid usecases for this, but it doesn't necessarily need to be in core. Add a "Could" followup note to discuss whether it should be in core: #2877400: Find a way to make title handling generic in entity templates
    This is done in #19, but reverted. See #25 through #27.

Other followups to file

  1. File a dedicated, postponed Media Entity followup for #2696555: On the entity form of revisionable entities, make "create new revision" and "revision log" configurable and add it under "Should" on the roadmap: #2878110: [PP-1] Make revision log and "create new revision" configurable for media items
  2. File a "Must" followup to fix Media Entity tests for #2827014: Throw an exception when testing status code or response headers in functional JavaScript tests. From @alexpott:

    The problematic test is MediaUiJavascriptTest - there are 4 calls to $assert_session->statusCodeEquals() - 3 of which can be removed but the last needs replacing with an assertion on something like "The media type %name has been updated." being on the page

    The follow-up has been filed: #2878112: Fix Media JavaScript tests to account for changes in JavascriptTestBase

  3. File a "Must" followup to review JS tests. From @alexpott:

    there's new code to wait for stuff that's not being used. This might mean that they currently have random errors.

    The follow-up has been filed: #2878113: Find possible random errors in Media's JavaScript tests

  4. File a "Should" followup to discuss the use of <article>:

    Twig templates use ? https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article - I don't think that media items should wrapped in that.

    phenaproxima: Open to suggestions here, but not sure what a more appropriate tag would be.

    seanB: It’s either this, or a plain old div I believe. I think perfectly described that a media item is a ‘self-contained composition in a document’ and ‘independently distributable or reusable’.

    alexpott: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/article the aria roles that are related really do not make me think this is at all related to what is in media and when you put a media entity on a node using entity reference it's going to be wrapped in article tags - inside another article - seems weird.

    This follow-up has been filed: #2878115: Make the HTML wrapper tag for media items more semantically correct

  5. The ongoing saga of Media::updateThumbnail() which has been discussed at length on the issue and at the DDD sprint. Mark the darn thing explicitly internal and file a followup to discuss it more ("Should"). Someone should go through the whole issue, the DDD spreadsheet, the DDD agenda/notes, this review's notes, etc. and collect all feedback about it and put it in the followup: #2878119: Whether queued or not, update the media thumbnail and metadata before beginning the entity save database transaction

Things to fix in the patch

  1. @naveenvalecha changed "tempstore" to "temp store" in the patch, however:
    [ibnsina:drupal | Wed 08:25:38] $ grep -r "tempstore" * | wc -l
          75
    [ibnsina:drupal | Wed 08:25:45] $ grep -r "temp store" * | wc -l
          17
    

    So let's use "tempstore" for now.
    This is done

  2. Fix the summary of Media:getThumbnailUri(). It gets the thumbnail's URI, not the media entity's. Also explicitly mark the method internal. @todo also check the issue for other discussion of this method.
    This is done in #19 and #21
  3. Rename Media:sourceFileChanged() to Media::has/isSourceFileChanged() (which?) and explicitly mark it @internal.
    This is done in #19
  4. In In path_entity_base_field_info() fix the in_array() usage to be strict to avoid bugs.
    This is done in #19
  5. Change \Drupal\media\MediaAccessControlHandler::checkCreateAccess() to allow users with 'administer media' to create (and add tests).
    This is done in #19
  6. Constructs an ImageFormatter object. C&P error; should be MediaThumbnailFormatter.
    This is done in #19
  7. Mark Media::updateThumbnail() @internal explicitly and add an @todo referencing the followup to be added above.
    This is done in #19
  8. Add an @todo to the template with <article> referencing the followup to be added above.
    This is done in #19
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

xjm created an issue. See original summary.

xjm’s picture

xjm’s picture

Issue summary: View changes
xjm’s picture

Issue summary: View changes
xjm’s picture

Issue summary: View changes
phenaproxima’s picture

Okay. The three patches I'm attaching (and will need to move into the appropriate follow-up, when it's filed):

  • 2877346-6.patch: This is #2831274: Bring Media entity module to core as Media module, #389, with the actions stuff ripped out. Ran all tests locally before rolling this, and they passed. Yowza!
  • interdiff--2831274-389--2877346-6.txt: The interdiff showing what code was removed in 2877346-6.patch.
  • 2877346-6--restore-media-actions.patch: The reverse of the interdiff. It will restore media actions to the core Media module.
phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

Another pass, now:

  • 2877346-8.patch: Again, this is #2831274: Bring Media entity module to core as Media module, #389, with tokens ripped out. Again, ran all tests locally before rolling.
  • interdiff-2877346-6-8.txt: A normal interdiff showing what changed between #6 and this patch.
  • 2877346-8--restore-media-tokens.patch: The reverse of the interdiff. It restores tokens to the core Media module.
phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

phenaproxima’s picture

phenaproxima’s picture

phenaproxima’s picture

phenaproxima’s picture

phenaproxima’s picture

phenaproxima’s picture

phenaproxima’s picture

seanB’s picture

Status: Active » Needs review
FileSize
234.64 KB
9.1 KB

Based on #8.

  • Removed validation in Media::Presave()
  • Removed full view mode
  • The tempstore change was already fixed?
  • Added @internal to Media:getThumbnailUri()
  • Renamed sourceFieldChanged to hasSourceFieldChanged and added @internal
  • The in_array() call in path_entity_base_field_info is changed to strict.
  • Changed MediaAccessControlHandler::checkCreateAccess to allow users with 'administer media' permission. And added test.
  • Marked Media::updateThumbnail() @internal and added @todo
  • Added @todo to the media.html.twig template
seanB’s picture

Issue summary: View changes
seanB’s picture

Missed the summary of Media:getThumbnailUri().

The last submitted patch, 19: 2877346-19.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 21: 2877346-21.patch, failed testing.

seanB’s picture

The failures seem to be caused by:
- Removing preSave validation (easy to fix).
- Removing the full view mode (at least that's what it looks like). This seems to cause issues in the cache tags tests. Still investigating this...

Wim Leers’s picture

+++ b/core/modules/media/src/MediaAccessControlHandler.php
@@ -54,6 +54,9 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
+    if ($account->hasPermission('administer media')) {
+      return AccessResult::allowed()->cachePerPermissions();
+    }
     return AccessResult::allowedIfHasPermission($account, 'create media');

Change this to:

return AccessResult::allowedIfHasPermission($account, ['administer media', 'create media'],
 'OR');

The reason the cache tags test is failing is that \Drupal\system\Tests\Entity\EntityCacheTagsTestBase::selectViewMode() selects the non-existent default view mode. The media entity currently does not include any entity view display config entities, but it should. If it only is supposed to support a teaser view mode (which is what it looks like based on changes in #19), then it should include a core.entity_view_display.media.teaser.yml file in its config/install directory.

Basically, \Drupal\system\Tests\Entity\EntityWithUriCacheTagsTestBase::testEntityUri() is requesting the canonical URL of the entity, and is then verifying in the render cache that the appropriate render cache item exists. To determine the CID for this render cache item, it must know the view mode that is used to render the HTML for the canonical URL.

Even if I hardcode selectViewMode() to return 'teaser', it fails. This is probably because Media uses the default EntityViewBuilder, which means it still defaults to the full view mode (see the signature of \Drupal\Core\Entity\EntityViewBuilder::view()). But you removed full… Yet hardcoding it to return 'full' also fails.

IOW: strange things are happening with rendering the HTML response for the canonical Media URL. You need to figure out which view mode/entity view display it uses, if any.

seanB’s picture

Status: Needs work » Needs review
FileSize
234.53 KB
6.14 KB

Added back the full view mode. Discussed this with phenaproxima on IRC. The main reasons:

  • Since media has a detail page, it makes sense to use a full view mode for that. As WimLeers pointed out, \Drupal\Core\Entity\EntityViewBuilder::view() uses 'full' view mode as a default. We could try to work around that, but that doesn't seem to make sense.
  • Taxonomy has a full view mode is well, referencing media could be viewed as a similar type of reference.

Also fixed the AccessResult::allowedIfHasPermissions check in MediaAccessControlHandler and removed the tests for media validation in PreSave (since we removed the validation).

phenaproxima’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Thanks, @seanB!

To reiterate: after reading @Wim Leers' comment in #25 and discussing with @seanB on IRC, we realized that removing the Full view mode is probably not a good idea because of the stuff that breaks when we remove it. Which isn't stuff we devised, and is not in Media's province.

So we have decided to do as the Taxonomy module does and ship with the Full view mode. There's precedent in core (i.e., taxonomy), and we can discuss whether or not we should remove the Full view mode for Media when and if core no longer implicitly expects it to be there.

It seems to me that all feedback has been addressed. Home stretch!

The last submitted patch, 6: 2877346-6--restore-media-actions.patch, failed testing.

The last submitted patch, 8: 2877346-8--restore-media-tokens.patch, failed testing.

phenaproxima’s picture

Rewrote the doc comment for Media::getThumbnailUri(), since it was confusing and contained a few errors.

phenaproxima’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

I have moved the patch from #30 to #2831274-391: Bring Media entity module to core as Media module. All feedback from this issue is now addressed (I confirmed each point), so I am closing it out.