Problem/Motivation
The seven theme tries to include some CSS inside a form alter that affects all media forms:
/**
* Implements hook_form_BASE_FORM_ID_alter() for \Drupal\media\MediaForm.
*/
function seven_form_media_form_alter(&$form, FormStateInterface $form_state) {
// @todo Revisit after https://www.drupal.org/node/2892304 is in. It
// introduces a footer region to these forms which will allow for us to
// display a top border over the published checkbox by defining a
// media-edit-form.html.twig template the same way node does.
$form['#attached']['library'][] = 'seven/media-form';
}
However, it is possible that a site is using Media Entity 1.x instead of core Media, so this library won't be available in that case.
Proposed resolution
Only include the core CSS library if we are using core Media, not contrib.
Comments
Comment #2
woprrr commentedHere the patch to solve this problem and unsure we are in MediaForm (CORE) context only to attach this.
Comment #3
woprrr commentedComment #4
woprrr commentedOOps !! forget MediaForm use. sorry for noise.
Comment #5
michaelb commentedPath #4 is working.
Comment #6
marcoscanoThis issue comes from #2863431: Change "Save and keep un-/published" buttons for media module and I can confirm without the patch sites using Media Entity 1.x + Drupal 8.4.x will have warnings in the watchdog:
User warning: The following theme is missing from the file system: media in drupal_get_filename() (line 248 of /var/www/html/core/includes/bootstrap.inc)In the new patch I have just reworded the comment a little bit to make it more explicit.
Also, the issue previously mentioned on the @todo (#2892304: Introduce footer region to ContentEntityForm) landed in 8.5, so we should remove all this stuff in 8.5 now. Do we need another issue for that or can we use this same one? In any case, I'm uploading a basic patch against 8.5.x, only removing the cruft and adding the checkbox to the footer region. I believe more work could follow to have the twig template done, but this could probably live in a follow-up? (not sure if one aiming to improve media forms exists already)
Comment #7
manuel garcia commentedPatch looks good to me.
As far as the @todo for the footer region, I think doing it as a new issue makes sense.
Comment #8
seanbNice work! I also think this issue should just contain the fix for 8.4, and we should create a separate issue to do the cleanup shown in the 8.5 patch. I created #2916784: Remove temporary seven theme workaround for media forms to fix this.
Comment #9
marcoscanoThanks @Manuel Garcia!
@seanB you are fast man!!! :) I was going to post that I had created #2916786: Stop adding specific CSS to Media form and use ContentEntityForm regions instead, but you were quicker. Which one do we close? :)
Comment #10
seanbYours has a patch, I'll close mine :)
Comment #11
marcoscanoOK then :)
Thanks!
Comment #12
seanbRTBC for the 8.4 patch.
Comment #13
xjmI think the approach here makes sense -- however, I'm not sure it's safe to backport this to a patch release. Someone could be relying on the library being there in Seven. What happens in particular when the library is missing with Media Entity 1.x?
Maybe we could commit the current patch to 8.5.x, but use an approach for 8.4.x that just fixes the alter hook internally to only fire if the Media module is installed? That would remove the issue when the contrib module is installed without risking disruption to production sites.
Comment #14
woprrr commentedHii @xjm
I think that patch only fire on Media module (core) context because we check what instance of MediaForm are currently used. If we use MediaForm (core) the instance of MediaForm match with "Drupal\media\MediaForm" only not with "Drupal\media_entity\MediaForm" used by Media Entity (contrib).
But I understand your opinion for 8.4 branch, here the patch for 8.4
Comment #15
xjmYep, #14 is along the lines of what I was thinking, thanks!
Probably we could commit that patch to both branches, and then use #2916786: Stop adding specific CSS to Media form and use ContentEntityForm regions instead as the followup to remove it in 8.5.x. I've postponed the other issue for now.
Leaving at NR for someone else to review/+1 #14 so that I could potentially commit it (since it was my suggestion).
Comment #16
seanbThere is actually a media contrib module for D8, so sites that installed the Media contrib module will still have the problem when we only check if media is installed.
I think that is why it's safer to check the form instance.
Comment #17
woprrr commentedI'm agree @seanB to me InstanceOf object is more precise but is installed offert same results (I have tested again to be sure in two sites on production).
@xjm +1 That sound great ! Soon as possible to merge it onto 8.4.
Ready to RTBC ? if @seanB accept usage of "is installed" for 8.4 only ?
Comment #18
idebr commentedThe duplicate issue #2916786: Stop adding specific CSS to Media form and use ContentEntityForm regions instead fixed this issue by removing the dependency on the media/form library altogether, since there is no actual dependency strictly speaking. That approach would fix this issue and can be committed to both 8.4.x and 8.5.x
Comment #19
idebr commentedI looked for an existing issue related to Seven, but could not find any. Should this not be in the Seven component?
Comment #20
woprrr commentedHii @idebr,
This issue and patch associated are to unblock fast the situation and avoid all blockers for media / media_entity user.
Like @xjm say :
We need to merge it first and then remove completely this dependency if needed.
Comment #21
seanbAs explained in #16 I think the 2916741-8.4.x-6.patch patch is the one we should probably commit in stead of the #14 patch.
Are there any other concerns we need to address? Otherwise, we can probably go back to RTBC and unblock #2916786: Stop adding specific CSS to Media form and use ContentEntityForm regions instead for 8.5?
Comment #22
woprrr commentedAs seen with @xjm on wednesday and today with @seanB on slack, the proposal would be to perform a double check to reduce the problems around this test. I get the variable before the test for questions of readability of the code.
What do you think of this approach ? @xjm
Comment #23
seanbThere is no real need for
$media_is_enabled, so let's drop the extra variable.Besides that, I think this addresses #13 and #16.
Comment #24
woprrr commented@seanB this extra variable is only here to lisibility :/ this part of code this very long méthod call in condition make me sad and primary symptom of bad code smell. I can change that if you think this is unecessary but for these reasons I think we can add this variable and have better clarity of what we need to test here
1/ media is enable
2/ media is instanceof mediaType
Comment #25
woprrr commentedIn any case I will not make a hard point the issue blocks too much so I change.
Comment #26
seanbThank you! Now let's hope this is acceptable for 8.4 since it solves a really annoying error for sites using media_entity 1.x.
Comment #27
larowlanThis issue is in. So we should revisit it here.
Thanks
Comment #28
seanb#2916786: Stop adding specific CSS to Media form and use ContentEntityForm regions instead does the proper cleanup, but we can't add this to 8.4 as per #13.
The patch in this issue is to fix the message below when using media 1.x for 8.4 only:
User warning: The following theme is missing from the file system: media in drupal_get_filename() (line 248 of /var/www/html/core/includes/bootstrap.inc)Comment #29
larowlanAdded credit for @xjm and @seanB for reviews/mentoring.
Thanks for clarifying @seanB
Comment #31
larowlanCommitted as 88f92b2 and pushed to 8.4.x.
Comment #33
merilainen commentedThis is not in 8.5.x?
Comment #34
alexpottThe followup did not make it into 8.5.x / 8.6.x - #2916786: Stop adding specific CSS to Media form and use ContentEntityForm regions instead - so we still have the problem there. Let's commit this to 8.6.x and 8.5.x and then remove the code in #2916786: Stop adding specific CSS to Media form and use ContentEntityForm regions instead if we can. I'm not sure why we only commit this to 8.4.x - doesn't really make sense to me.
I will commit this in 24hrs unless someone gives a good reason as to why not.
Comment #36
alexpottComment #38
alexpottOk so the 8.6.x alpha got in the way and it means that we can't backport this to 8.5.x.
Committed and pushed 3764218018 to 8.7.x and e0ea889653 to 8.6.x. Thanks!