Closed (fixed)
Project:
Drupal core
Version:
8.1.x-dev
Component:
views.module
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
14 Jan 2016 at 00:08 UTC
Updated:
8 Mar 2016 at 10:41 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
lokapujyaNot sure how to begin writing a test for this since it needs ImageFieldTestBase and views.
Comment #3
lokapujyaStarted creating a web test extending ViewTestBase. But, possibly if an image field is added to views.view.test_field_get_entity.yml then it will get tested by ViewEntityDependenciesTest.
Comment #4
lokapujyaOops.
Comment #5
lokapujyaThis is a "test-only" patch that shows the problem.
Comment #8
dawehnerIsn't the underlying problem that this class
\Drupal\image\Plugin\Field\FieldFormatter\ImageFormatterdoesn't have config dependencies?Comment #9
lokapujyaYeah, but the parent issue is adding the dependencies; Even with that patch, this still happens.
I'm guessing it's because the parent issue only deals with preview_image_style. The view has image_style.Nevermind, not true. The other patch does handle image_style also.Comment #10
lokapujyaCould the dependencies belong here: core/modules/views/src/Plugin/views/field/Field.php ?
Comment #11
lokapujyaComment #12
lokapujyaThe attached interdiff code will set up the dependency; But, then when deleting the image style, the whole view will get deleted. The views field configuration doesn't currently support onDependencyRemoval() (because it extends from FieldPluginBase unlike ImageFormatter which extends from PluginSettingsBase.) I think the views field needs to somehow implement onDependencyRemoval() if this is going to work.
Comment #13
dawehnerWell yeah, this is how fields behave at the moment as well, but it will worn you that removing that image style will also drop the views.
Comment #15
claudiu.cristeaOK, then what happens with the Views field when its image style gets deleted? With this patch the entire view will be deleted. You must implement onDependencyRemoval() and define an action when the image style gets deleted. Maybe disabling the field? This is what happens, by default, on entity displays.
Let's go with short array syntax.
???
Short array syntax. Also entity_create() is deprecated. Use FieldStorageConfig::create();
s/array()/[]
[] array syntax. Use FieldConfig::create() instead of entity_create().
EntityFormDisplay::create().
s/array()/[]
EntityViewDisplay::create().
Extraline.
s/array()/[]
s/array()/[]
drupal_realpath() is deprectared. Use $this->container->get('file_system')->realpath($image->uri)
Add newline.
Comment #16
lokapujya1: I tried implementing onDependenceRemoval but Drupal never invoked it. Should class Field implement some interface such as PluginSettingsInterface? I'm not sure. Also, I noticed the dependency went into the "Deleted Configuration", not the "Updated Configuration". Don't know what determines that.
2-4: done
7: removed it; The display on the entity was not necessary for testing the views field.
5-13: The helper functions are copied code from core/modules/image/src/Tests/ImageFieldTestBase.php. Not changing yet, because possibly there is a way to share the code among the 2 tests if that code ends up actually being needed. If it is needed then we should def make those changes.
Comment #18
anavarreI don't see how this cannot be major. If you have a view on the homepage with images, then if you get bitten by this bug your site is visually down.
Comment #19
lokapujyaWell, I chose a priority of Normal because you need to delete an image style to cause the problem.
The test in the last patch is failing -even with calculateDependencies()- because the dependencies were not being calculated when creating the view. Also, the view has to be created after the field is created or the plugin type will be "broken".
Comment #20
lokapujyaLast patch wasn't rebased. Interdiff is still good.
Comment #21
dawehnerIMHO we should init the formatter, and then call
calculateDependencies()Using that we solve a lot more potential issues, without having to hardcode anything.Comment #22
lokapujyaThat sounds interesting, what does it mean to "init the formatter"?
Comment #23
dawehnerSomething like this:
Comment #24
lokapujyaI don't get it. settingsForm() loads a form to configure settings for the formatter? or that's just an example usage of the formatter? What needs to be done with the formatter? and is this all happening inside calculateDependencies()?
Comment #25
lokapujyaI initially thought you meant that calculateDependencies could be called on the formatters instead of the field, but I don' think thats possible.
Comment #26
dawehner@lokapujya
No worries, I just went and implemented what I had in mind.
Comment #27
dawehner@alexpott suggested an alternative
Comment #28
claudiu.cristea@dawehner, I worked in the same way but you're faster. However, I'm posting my test that shows this patch is incomplete.
PS: And I think we should replace
\Drupal\views\Tests\DependenciesTestin favour of this because is more faster.EDIT: This patch introduces also a base kernel test for Views. I know that it's somehow unrelated but it's, let's say, a "side effect".
Comment #30
lokapujyause Drupal\KernelTests\KernelTestBase;
I think. But that new test doesn't run.
Comment #31
claudiu.cristeaNeeds review. I followed the same strategy as in the case of entity displays: unresolved dependencies are causing the field disabling or, in the case of views, field removing.
Comment #33
claudiu.cristeaSimplified, fixed test.
Comment #34
claudiu.cristeaDiscussed on IRC with @dawehner and @Berdir that the reaction on dependency removal needs to be handled in a general case issue for Views, taking into account multiple aspects (like filters cannot be removed because it would be a security issue). That should most probably be handled in #2468045: When deleting a content type field, users do not realize the related View also is deleted. I'm reverting the changes to only allow dependency computing.
Comment #35
claudiu.cristeaSmall fix in test.
Comment #36
lokapujyaAdding interdiff to help review.
Comment #37
lokapujyaWhat's the goal here? to be more generic?
Eventually, we might not want to delete the view. Is there a way to verify that the view is in the configuration deletes dependency list?
Comment #38
claudiu.cristeaJust avoid code duplication.
See #34. Right now the view is deleted also in other similar scenarios. We stick to that and after we fix all the cases in a generic fix.
Comment #39
lokapujyaWhat I meant is that the webtest verified that a warning showed up when deleting from the UI. The new test only checks that the view was deleted. I guess if it got deleted it's safe to assume it was in the "configuration deletes" and would have thrown a warning.
checks that it was a dependency.
asserts that it was deleted and not updated.
so that case is covered?
Comment #40
lokapujyaWhy a new class with same name as existing class?
isn't this the same as base class?
Comment #41
dawehnerNote: While this is also about getting rid of duplicate code, just naming things properly (by having a method) helps to understand the code already.
Let's have some actually helpful test class name, maybe we could move it to image module instead?
I know we had a different issue for that already, but I'm totally fine with doing it here.
Comment #42
claudiu.cristea@lokapujya,
Well, the UI passes the control to the API. So testing the API is just fine.
But we test that the image style is in the View's dependency list. And, yes, if it's there is well known that will be deleted when the style gets deleted. And we test that later.
Well, it's the same case as the base class: KernelTestBase. The new one, that we're introducing here, will replace the old one. I'm also deprecating the old one in favour of this.
No. We are extending \Drupal\KernelTests\KernelTestBase, not \Drupal\views\Tests\ViewKernelTestBase.
Yes, I've discussed with @dawehner on IRC and decided for ViewsConfigDependenciesIntegrationTest. The idea is that, in the future, we can add other tests in this class that are testing the dependencies with other modules.
Comment #43
claudiu.cristeaNot ready.
Comment #44
lokapujyaI wonder why we need to set these items.
Comment #45
claudiu.cristea@lokapujya
This is how \Drupal\Core\Field\FormatterPluginManager is getting the instance. See \Drupal\Core\Field\FormatterPluginManager::getInstance().
Added update path and test for it.
Comment #46
lokapujyaYeah, but aren't those the defaults. No big deal, just confused me a little.
Comment #47
lokapujyaSo we are now handling any dependencies on views field formatters (not just image styles.) Currently in Core, image styles are the only configuration that be affected.
Comment #48
lokapujyaComment #49
lokapujyaComment #50
lokapujyaComment #51
lokapujyaComment #52
lokapujyaComment #53
lokapujyaComment #54
lokapujyaWe should move the "Add the module" comment inside the if() because it implies that it's only adding module, or expand the comment by adding " and it's dependencies."
Comment #55
dawehnerSure, why not.
Comment #56
lokapujyaComment #57
dawehnerLooks alright for me now.
Comment #58
lokapujyaNew title?: Enforce formatter dependencies on views fields.
Comment #59
catchLike the new title. Going to try to review this today.
Comment #60
catchWhat happens if the update runs and the dependency is already missing? Will it just not add the dependency or will there be errors from the update?
Comment #61
dawehner@catch
I guess you talk about the case where the dependency is already there.
Well, this would not be distinct from the case where users in the UI saves the view twice, it recalculates the dependency again, and sets it into the configuration.
Comment #62
claudiu.cristea@catch, I don't understand the question from #60.
Comment #63
catchSorry wasn't very clear at all.
I mean what happens if we get here and the dependency (i.e. image style) has already been deleted?
Or to put it differently, do we need test coverage for image_style: missing_image_style?
Comment #64
dawehnerSo do you argue for emptying
$this->dependenciesfirst?Comment #65
catchNo I don't think we need a code change at all (i.e. it should just skip over the dependent thing it can't find), I'd just like test coverage to confirm that.
Comment #66
claudiu.cristeaVoilà
Comment #67
lokapujyaAn existing view with a missing dependency will continue to get the fatal error.
Comment #68
lokapujya*Not saying we should fix it, just stating what happens.
Comment #69
catchclaudiu.cristea thanks! Sorry I didn't ask for it very well.
@lokapujya yeah not sure that's fixable - just wanted to make sure the update itself didn't error due to the same condition.
Comment #70
catchSorry one more question.
This would be a problem if a class subclasses Field and also uses PluginDependencyTrait - do we know if that's definitely not happening anywhere in contrib?
Much more minor but adding the protected method to the base class is something we'd not normally do in in a patch release, fine for 8.1.x though.
Comment #71
catchComment #72
dawehnerRegarding #70.1
This is not a problem, if I understand it correctly, see https://3v4l.org/UYgcq
So the alternative is an
_getFormatterInstancemethod?Comment #74
catchI was thinking of http://php.net/manual/en/language.oop5.traits.php#language.oop5.traits.c... - but I might be mis-remembering and this only happens if the trait conflicts with a method name in the subclass rather than re-using the same trait directly. Sorry for the confusion.
Yep with an @internal note - but that bit we should do after an 8.1.x commit - which I've just done. So moving to CNW for 8.0.x.
Comment #75
catchSlightly happier status...
Comment #76
lokapujyaComment #77
claudiu.cristeaI'm RTBCing here only the patch port.
I'm not very sure we need to point here when this method was added. IMO, we should only add
@internal. Or, maybe, as comment "Should not be used in user code.". @catch, please correct this at commit if it's case. Anyway, if remains, the comment should be 1 line only.Comment #78
dawehnerLet's move to 8.1.x first
Comment #79
dawehnerLet's move to 8.1.
Comment #80
catchThis is in 8.1.x already.
Comment #81
dawehnerUPs.
Comment #82
alexpottThis config is missing a UUID... nice way of creating old config pre an API change though...
Why is this change relevant?
Let's create a version for 8.2.x / 8.1.x first.
Let's try to get this in 8.1.x... in general we're trying not to commit things with update functions to 8.0.x and as 8.1.x is in beta it feels an ideal time to get this fixed.
This is not really about just image styles right - it is about any formatter dependency afaics.
Comment #83
alexpottLol I didn't realise that this was already in 8.1.x. Given this has an upgrade function and we're in 8.1.x-beta I think it is best to not put this in 8.0.x.
Going to put back to rtbc for catch's opinion...
This looks weird in an 8.1.x patch... :)
Comment #84
alexpottAlso we should at least get a followup to fix the hook_update_N description as this is presented to the user and I believe it is currently misleading.
Comment #85
dawehnerThis is needed because
\Drupal\Core\Plugin\PluginDependencyTraitrequires it.Comment #86
catchI'm happy leaving this at 8.1.x
To be honest I have no idea what to do about update function defgroups. If this goes into 8.0.x, then the degroup is correct in the 8.1.x patch too (since it's the same update and should run on an 8.0.x database), if it doesn't, then we could make it 8.1.x. But also it's added prior to 8.1.0, so in fact will never run on a newly installed 8.1.0 site.
I don't really feel like figuring that all out here, so should we just mark this fixed but open a new issue for upgrade defgroups? Or #2624318: [meta] 8.1.x upgrade path might be that issue.
Comment #87
alexpottSo let's mark this closed and open a followup to fix the update text as mentioned in #82.5
Comment #88
alexpottCreated #2683263: Update text for views_post_update_image_style_dependencies() wrong