Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
An additional AccessPlugin that checks if the user has access to (selected) entity/ies for the route.
A solution suggested for #1857256: Convert the taxonomy listing and feed at /taxonomy/term/%term to Views. Presently taxonomy/term/%taxonomy_term checks entity->access view replacing it with a view requires doing the same. A generic solution to check access to entities in route.
Comment | File | Size | Author |
---|---|---|---|
#62 | 2029509-62.patch | 784 bytes | damiankloip |
#59 | vdc-2029509.patch | 36.19 KB | dawehner |
#54 | vdc-2029509-54.patch | 36.23 KB | dawehner |
#50 | vdc-2029509-38-50.interdiff.txt | 1.38 KB | ekes |
#50 | vdc-2029509-50.patch | 36.65 KB | ekes |
Comments
Comment #1
dawehnerAdditional to that we also need a argument validator plugin which checks access to an entity.
Comment #2
dawehnerJust tracking some work.
Comment #3
ekes CreditAttribution: ekes commentedA part-of-the-way point patch. Knowns:
Working: A generic entity argument handler with access to entity check; and where appropriate bundle filter option.
Needs work: Extending for user and taxonomy cases which allow more options. Needs tests.
Looks ugly: The 'entity:derivative' name given caused both the '#visible' form handling, and the ajax save to break. str_replace(':', '-' ... and vice versa is a pretty ugly work-around.
Comment #4
ekes CreditAttribution: ekes commentedAdding: multiple ID handling; and porting taxonomy term ID and creating a taxonomy term name.
Remaining: user and node original argument handling. Node should be a swap out replacement. Presently user validator has some direct database accessing code; but looks like it could (should) be replaced with entity loading methods by the same pattern as Taxonomy Term.
Comment #5
ekes CreditAttribution: ekes commentedChanged so taxonomy term view uses new filter. So existing tests on view should pass.
Comment #7
ekes CreditAttribution: ekes commentedThe exceptions causing the fail above are entity type menu_item. Which has bundles; but seems to have no field definition (so no bundel_label etc.)
The
::baseFieldDefinitions()
returns an empty array for::getStorageController('menu_link')
. Is it that the information is being called incorrectly; or as it seems that the information is not there?[Follow-up asking question on issue making the bundles]
Comment #8
ekes CreditAttribution: ekes commentedAddition of a empty check, and default text, for any cases like this where there are bundles to select from but they don't have a general bundle type name.
Comment #9
ekes CreditAttribution: ekes commentedComment #10
Berdirmenu links have not yet been converted to NG, that's why they have no field definitions.
Comment #11
dawehnerImpressive work! I guess tests for the test entity would be helpful.
The DerivativeBase which just landed this week really helps to simplify a lot of the code.
There should be a comment why this is needed.
What about using the entity manager to load the entities?
The best thing is probably to use the entity interface. Here the documentation should contain the full namespace, but the method just the "EntityInterface", which then is added as use statement.
Comment #12
ekes CreditAttribution: ekes commentedChanges for suggestions above. Plus missed t().
Still to do: tests for the test entity.
Comment #13
dawehnerHere are some unit tests... I will continue with a review tomorrow.
Comment #15
dawehnerOpened a new follow up for the ':': #2035345: Reconsider whether to use ':' as separator for derivative plugins and fixed some minor stuff.
I consider this as major as it pretty much blocks all major conversions.
Comment #16
dawehnerchange title.
Comment #17
damiankloip CreditAttribution: damiankloip commentedValidates
We can remove this; provider will get added during discovery.
We should use the ContainerDerivativeInterface and inject the entity manager and translation manager. See \Drupal\views\Plugin\Derivative\ViewsEntityRow or something.
Seems like this is liable to break pretty easily. I know we are talking about chnaging the separator, but do you think we should change this to a double '--' or something atleast?
We are using these similar things a few times, worth encode/decode type methods?
Yes, I think we should :)
Validates
Seems overkill, can't we just try 1000, or even just 3 or something?
These tests could make use a data provider? I guess the result of validation varies too much for each case?
Would be good if a case for TRUE was tested too.
Comment #18
dawehner.
Comment #19
ekes CreditAttribution: ekes commentedComment #20
ekes CreditAttribution: ekes commentedStarting on #17. Patch moves to ContainerDerivativeInterface. Posted just for check point.
Other issues raised make sense. Although I seem to recall some reason str_replace() wasn't put into it's own function; but probably was nothing. Shall get there next.
Comment #21
ekes CreditAttribution: ekes commentedIt's also done in two classes several times in
Drupal\views\Plugin\views\argument\ArgumentPluginBase
, but also once inDrupal\views\Plugin\views\argument_validator\Entity
. So then static method(s) onArgumentPluginBase
?Comment #22
ekes CreditAttribution: ekes commentedTurns out we don't need to. If the argument fits all the entity validation is never called.
Comment #23
ekes CreditAttribution: ekes commentedChanges from #17 with notes as above and:
The validation would be different each time, so it would be another test anyway if I understand the way that dataProvider works. As can be seen by what is done now within the test to check for when access is true for 1,2 and 1+2.
Here it's not working to hard, it's only one: just between 100 and 1000, which aren't valid entity IDs.
Comment #24
dawehnerRemoved the 'needs tests' tag.
What about using static:: instead so you can override it in a sub-class if needed
Let's add @param's here.
I try to understand why we need three '-' here, is this done to be 100% sure?
Comment #25
dawehnerbtw. Thank you for working so hard on that issue!.
Comment #26
damiankloip CreditAttribution: damiankloip commentedYep, I get its just giving one random value. It just seems we could just pick a random value instead? We don't gain from randomly generating, except maybe a random failure in the future ;)
I thought as much with the data provider, it doesn't make sense to use them here.
Comment #27
ekes CreditAttribution: ekes commentedAh, now I understand. Yes sure, swapping to a known not set.
Yes, only figuring if - can actually be in the string already such that double makes sense, then either another different character or an extra-extra -.
Comment #28
damiankloip CreditAttribution: damiankloip commentedI will review properly on monday, but for now I think that sanitize/revert is not the best naming choice. I think we should do with encodeValidatorId and decodeValidatorId instead, as that is more inline with other core methods that do similar things. What do you think?
Comment #29
ekes CreditAttribution: ekes commentedencode/decode sounds better; revertSanitized is kind of clunky anyway just the best I could think of at the time.
Comment #30
clemens.tolboomXREF #2095235: The argument handler is broken for argument_validators for path like clone/taxonomy/term/1+2
Comment #31
ekes CreditAttribution: ekes commentedRe-roll, plus changed method names suggested in #28.
Comment #33
clemens.tolboomI get "Drupal\Component\Plugin\Exception\PluginException: The plugin (taxonomy_term) did not specify an instance class. in Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass() (line 62 of /core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php). "
when calling a clone version of taxonomy_term view. Taken from steps to reproduce on #2095235: The argument handler is broken for argument_validators for path like clone/taxonomy/term/1+2
Should I reinstall drupal to make sure?
Comment #34
ekes CreditAttribution: ekes commentedThere are some API changes. I've updated. I'll post an updated patch for that.
However, for that, there is still one point where the taxonomy term page is broken. The preview works, the page itself has some path/route issues. Question as posed in IRC is
I'll post the other changes in a moment though.
Comment #35
ekes CreditAttribution: ekes commentedReroll as #31 plus API changes: uses Drupal\views\Annotation\ViewsArgumentValidator rather than core Plugin Annotation; changes plugin/derivative module to provider; and gets Field definitions from EntityController, not the StorageController.
Issue with taxonomy/term/% page view as per #34 exists.
Comment #36
ekes CreditAttribution: ekes commentedThe issue in #34 is independent of this patch and exists in the core view at the moment [1]. So changing to needs review.
[1] Issue #2091399: [META] Remove menu_get_object() comment #2
Comment #37
dawehnerI don't think we need tests anymore, just a couple of final nitpicks before setting it to RTBC. This is really great work.
You can now skip to specify this annotation classes, see #2090353: Don't require to put the use statement into plugin classes
Nice documentation but for you missed the variable itself :)
Comment #38
ekes CreditAttribution: ekes commentedChanges for #37.
Comment #39
jibranYay!! Thanks @ekes for killer tests RTBC as per #37.
Comment #40
dawehnerNice and important work!!
Comment #41
alexpottI manually tested this by:
This results in:
Comment #42
ekes CreditAttribution: ekes commentedThe issue with menu_link not implementing (EntityNG) fields comment-#7 has returned with the API change #2024963: Move baseFieldDefinitions from storage to entity classes. But I'm not sure if it's in the scope of this issue/patch this time.
In Drupal\views\Plugin\views\argument_validator\Entity we call
$this->entityManager->getFieldDefinitions($entity_type)
. Previously, the storage controller getFieldDefinitions method returned an empty array for the menu entities. Now the method Drupal\Core\Entity\EntityManager::getFieldDefinitions calls$class::baseFieldDefinitions($entity_type),
. As the menu entities do not implement the method baseFieldDefinitions the function dies with a fatal error:PHP Fatal error: Call to undefined method Drupal\menu_link\Entity\MenuLink::baseFieldDefinitions() in ..../core/lib/Drupal/Core/Entity/EntityManager.php on line 482
. Just putting return if not method_exists call in EntityManager after the $class loaded solves this for this patch.Bug against EntityManager::getFieldDefinitions(); or should it be called differently?
Comment #43
BerdirIt's not related to that issue, this is about #2004244: Move entity revision, content translation, validation and field methods to ContentEntityInterface.
As the documentation of that function says, it's not valid to call it with a non content entity type. There could be nicer error handling, but the result would be the same.
Comment #44
ekes CreditAttribution: ekes commented.
What's the best way for me to know when I've got the entity type name?
Comment #45
BerdirYou need to check if the $entity_definition['class'] implements ContentEntityInterface.
Comment #46
ekes CreditAttribution: ekes commentedOr possibly better, check if the entity definition says that the entity type is fieldable?
Comment #47
ekes CreditAttribution: ekes commentedWrong patch.
Comment #48
dawehnerI really like this solution.
It would be great to have one additional sets of brackets here, just to make it clear what runs first.
Comment #49
BerdirNo, that is not correct.
The fieldable key is misleading (that's why there's an issue to change it). File for example has field definitions (base fields) but fieldable = FALSE (because fieldable means configurable fields).
Comment #50
ekes CreditAttribution: ekes commentedAh, shame. It seems to make sense to be able to ascertain from EntityManager if the entity has field definitions/is a content type.
But anyway to move this on. Swapping to just:
Comment #51
ekes CreditAttribution: ekes commentedComment #52
dawehner#50: vdc-2029509-50.patch queued for re-testing.
Comment #54
dawehnerRerolled the patch and marked #2110845: Allow overriding views to override paths with parameters critical due to the fact that taxonomy/term don't work at the moment.
Comment #56
dawehner54: vdc-2029509-54.patch queued for re-testing.
Comment #57
dawehnerI manually tested the patch using simplytest.me
The curreny URL looks like the following, though this is not caused by that patch, certainly.
The patch just cares about the "1", not the next argument.
taxonomy/term/1/%7Btaxonomy_term_modifier%7D
Comment #58
catchif (!$terms) is plenty.
Comment should say translation manager.
Comment #59
dawehnerThis patch uses a $this->t() method in the derivative class as well as extends DerivativeBase
Comment #60
tim.plunkettThis was already RTBC, and despite no interdiff the last patch addresses #58.
Triple dash! Woo. Glad this has a d.o link
Some day we'll have a method for this...
Beautiful tests!
Comment #61
catchCommitted/pushed to 8.x, thanks!
Comment #62
damiankloip CreditAttribution: damiankloip commentedplugin.manager.entity doesn't exist anymore as a service.
Comment #63
catchWhoops. I wonder who committed that patch removing the service then committed this one a day later without noticing...
Comment #64
amateescu CreditAttribution: amateescu commentedComment #66
damiankloip CreditAttribution: damiankloip commented