Need to update the hook_views_pre_view API example code to match actual functionality. Calling $view->id() is the correct way not $view->name
Original post
API page: https://api.drupal.org/api/drupal/core%21modules%21views%21views.api.php...
The code in the example function body is incorrect. Where it says $view->name, it should say $view->id().
| Comment | File | Size | Author |
|---|---|---|---|
| #49 | interdiff_47-49.txt | 635 bytes | pradhumanjain2311 |
| #49 | 2689923-49.patch | 1.5 KB | pradhumanjain2311 |
| #47 | interdiff_44-47.txt | 833 bytes | pradhumanjain2311 |
| #47 | 2689923-47.patch | 1.5 KB | pradhumanjain2311 |
| #44 | interdiff-2689923-35_44.txt | 843 bytes | anchal_gupta |
Comments
Comment #2
jhodgdonThanks for the issue! Marking Novice and fixing the issue summary slightly. Also this should be fixed in 8.2 and then it should be applied to the other 8.x versions (probably the same patch will apply to all).
Comment #3
johnrosswvsu commentedHi,
I have created a patch to address the request, but I have also found other instances of wrong use for $view->name.
There is one in hook_views_post_build and another in hook_views_pre_execute.
Please review.
Thanks.
PS: Patch also works for 8.0.x and 8.1.x.
Comment #4
jhodgdonLooks good! Thanks for fixing the other instances of $view->name in the same file. That is a perfectly excellent expansion of the issue scope.
Comment #5
johnrosswvsu commentedI grep in the entire code base and found no other instances except in this file. Please let me know should you find more.
Comment #6
johnrosswvsu commentedHi @jhodgdon,
I have found in https://api.drupal.org/api/drupal/core%21modules%21views%21src%21Views.p... the following documentaton:
views object (containing $exclude_view->storage->name and $exclude_view->current_display)
Does this case apply as well? Looked around in the codes and can see that in the following for example:
https://api.drupal.org/api/drupal/core%21modules%21views%21src%21Plugin%...
Line 162 uses: if ($view_id && $this->view->storage->id() != $view_id) {
I am not particularly sure about this one so I need anyone to check this.
Comment #7
alexpottI can't make my mind up about the scope of this issue - whether or not to fix all the things in views.api.php that are broken... for example
hook_field_views_data_views_data_alterhas$entity_type_id = $field->entity_type;which should be$entity_type_id = $field->entityTypeId();and I think$table_mapping = \Drupal::entityManager()->getStorage($entity_type_id)->getTableMapping();is wrong too. In other places$view->query->tables- the tables property does not exist as far as I can see. Same for$view->query->table_queue. Andhook_views_query_alteralso needs work.Comment #8
jhodgdonWell that is a good question, and probably not a novice issue if the scope is "Fix all the outdated stuff in views.api.php". Your call... I have been getting the scope wrong on issues lately and am not making this decision.
Comment #13
sk33lz commentedSome of these fixes have already been changed in previous commits it seems. I can't speak to the scope of this issue, but I re-rolled #6 to get this patch ready in it's current state for 8.6.x.
Comment #14
leoneldiaz02 commentedI tested the patch, and the patch worked correctly.
Comment #15
leoneldiaz02 commentedi also reviewed the patch and i saw that they were using the old coding standards for array and replaced for the new standard.
Comment #16
sk33lz commentedThanks for the clarification on that. I saw the array was done differently between versions and I was unsure about that change.
Comment #17
bdlangton commentedThis is a weird case because the original issue is already fixed in 8.6.x. The latest patch fixes something different. I don't see anything wrong with it, but just wanted to point that out.
Comment #26
smustgrave commentedTriggering a 9.5 build. Once that's complete I'll RTBC
Comment #27
smustgrave commentedLooks good.
Comment #28
avpadernoThe issue summary needs to be updated; it doesn't describe what the patch is effectively fixing.
(I am changing two issue tags, since this patch won't be back-ported to branches that are now unsupported.)
Comment #29
smustgrave commentedComment #30
smustgrave commented@apaderno updated the summary if that helped.
Comment #31
avpadernoThe documentation for
hook_views_pre_view()doesn't contain any reference to$namenorname(). That is not even what the patch is changing, since it changes the documentation comment for theViews::getViewsAsOptions()method, which is using the following documentation comment.The last attached patch contains the following lines.
The issue summary and the issue title must be updated.
Comment #32
avpaderno$exclude_view->storage->id()seems to still be not correct, since neither theViewsclass nor theDisplayPluginBaseclass seems to have a$storageproperty.Comment #33
avpadernoFurthermore, if the purpose of this issue is fixing the documentation comment for
Views::getViewsAsOptions(), there are other fixes to apply.For example, instead of views object, it should use
Viewsobject; it should not use colons followed by e.g. but a comma followed by for example; it should not use display id but display ID.Comment #34
pradhumanjain2311 commentedComment #35
WagnerMelo commentedHello, i worked in this issue, and did the changes asked by @apaderno on #33.
And about the comment #32 from @apaderno too, talking about the $exclude_view->storage->id(), i think that this way as are, its right because storage is a service from core, and is used in the same file at line line 325.
And sorry @pradhumanjainOSL, but i don't know if you know, but usually in core issues, we should don't assigne to ourself, only send the pathc, and made comments.
this link below explain better about that.
https://www.drupal.org/docs/develop/issues/fields-and-other-parts-of-an-...
Comment #36
smustgrave commentedTo help compare what was changed can you provide an interdiff please
Comment #37
asha nair commentedApplied patch in #35 successfully on 9.5x-dev. The patch has done the changes mentioned in #33 and changed '$view->name' to '$view->id()'.
Comment #38
pradhumanjain2311 commented@WagnerMelo I m new to contribution. Thanks for giving me the information about not assigning the core issues.
Comment #39
WagnerMelo commentedSorry about that, here are the interdiff @smustgrave.
NP @pradhumanjainOSL we are here to learn together.
Comment #41
sahil.goyal commentedHi, Thanx @WagnerMelo for the patch, As you corrected the documentation as per the comment #32 and #33, it looks great and relatable, I have tried to applied it successfully on 10.1.x it applied cleany, so it can be compatible for 10.1.x.
Comment #42
sahil.goyal commentedMoving to RTDC for now till further update.
Comment #43
alexpottI think the examples should be in single quotes and if we're changing these lines we should break the lines on 80 chars.
I would expect the docblock to end up looking something like:
Comment #44
anchal_gupta commentedI have uploaded the patch
Addressed #43 point.
Comment #45
anchal_gupta commentedComment #46
alexpott@Anchal_gupta how about fixing the 80 chars issue and the @param types too - as per #43.
Comment #47
pradhumanjain2311 commentedTry to address comment #43.
Comment #48
avpadernoJust a small change: The first line is missing a space after the comma and before for example..
Comment #49
pradhumanjain2311 commentedTry to address #48.
Comment #50
avpadernoThe patch fixes also the line longer than 80 characters. This is RTBTC.
Comment #52
alexpottBackported to 9.4.x as this is a docs bug fix.
Committed and pushed d88758034c to 10.1.x and 4467280292 to 10.0.x and 9ebe2b579b to 9.5.x and 6f71312b3f to 9.4.x. Thanks!