Closed (fixed)
Project:
Entity Browser
Version:
8.x-1.x-dev
Component:
Widget plugins
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
25 Oct 2016 at 15:01 UTC
Updated:
14 Dec 2017 at 13:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
marcoscanoWould it be too disruptive to add a generic method on the interface, allowing widgets to define their visibility in any context? This way we solve not only this need, but any need where someone needs to check if a given widget is available or not.
This is a WIP (but functional) patch. If the approach looks good, I can finish it, adding tests, DI, etc.
Also, how can we retrieve the entity browser from inside the selector plugin?
looks awful, but I couldn't figure out how to do it otherwise... :)
Comment #5
marcoscanoLet's validate the approach, the tests will probably need to be updated if that's the case
Comment #6
zerolab commentedA quick test on the current build works wonderfully, thank you!
Now for the module gatekeepers for the approach.
Comment #7
slashrsm commentedLooks good. Few comments:
Let's add this.
I'd rename this to
access()to be consistent with the rest of Drupal. Also return AccessResult or bool (based on the argument) - another step to be more consistent with the rest of Drupal.Comment #8
primsi commentedShould \Drupal\entity_browser\Plugin\EntityBrowser\WidgetSelector\DropDown also have this check?
Comment #9
zerolab commentedHere's a rerolled patch with DI and
\Drupal\entity_browser\Plugin\EntityBrowser\WidgetSelector\DropDownincluded.Comment #10
zerolab commentedMissed the interdiff
Comment #11
OlgaRabodzei commentedThe patch from #9 works fine for me. Thank You, Dan!
Comment #12
slashrsm commentedNeeds docblock with @param entries etc.
This breaks BC since it will break any plugins that extend this classes. We'd need to do this in non BC breaking way.
We could introduce a new interface that would allow plugins to opt-in to this feature.
The entity browser should be available in the form state object.
ARRAY_FILTER_USE_KEYis PHP 5.6 only. As much as I would like to use it Drupal still supports PHP >= 5.5.9.It would be nicer to get AccessResult result object and add it into the render array using
#access. This will, among other things, ensure that any cache metadata is preserved.Comment #13
svendecabooterUpdated patch which tries to fix the remarks mentioned above.
This patch provides an easier way to get to the entity browser object, based on the remarks by slashrsm.
This fixes the BC problem.
Test coverage still needs to added.
Comment #14
slashrsm commentedReroll, review, minor change, tests.
Comment #15
slashrsm commentedAnd interdiff.
Comment #16
berdirthis could be an issue with caching, because views doesn't seem to have a way to return access cacheablity metadata. permissions/roles are covered by the default user.permissions cache context, but in case of a more complicated access plugin, this might be a problem.
But not much we can do about it here, except marking it as completely uncacheable. Which in most cases isn't really an issue as it won't be cached anyway.
this also loses cacheablity metadata if a plugin actually does add it.
The whole $return_as_object stuff was mostly added for BC.
I'd actually vote to just always return an access result object like for example route access checks do. Then implementation are more obviously reminded to apply cacheablity metadata prperly.
Alternatively, to make the BC impact minimal, we could optionally support the existing \Drupal\Core\Access\AccessibleInterface, although that won't allow us to do the always-return-access-result-object thing.
this could then add some weird cache context that we can look for in the response. except not sure if phantomjs even allows to look at headers.
Comment #17
slashrsm commentedI am totally fine with always returning an object. Since this is just being added we do not need to introduce any BC layer. Changed that, added the cache metadata check in the test. Also fixed another problem that I found: if the first widget was not accessible it was still displayed.
Comment #19
slashrsm commentedMeh...
Comment #20
slashrsm commentedImplemented access() for the EntityForm widget too.
Comment #21
slashrsm commentedReroll.
Comment #22
berdirWe've been using this for months now and I reviewed it before, lets commit this :)
Comment #26
slashrsm commentedCommitted. Big thanks!