Problem/Motivation
On #2393339: [META] Make sure Views base fields are using Field API for formatting, and do not lose functionality, we are updating all base entity fields in entity views data so that they are using Field API for formatting rather than using generic Views handlers.
This issue is about the node_field_revision.title field, which is currently using a custom 'node_revision' Views handler.
Proposed resolution
Change node_field_revision.title to use the Field API formatter 'field' instead of the custom formatter. Should also be able to remove the custom formatter from the code base completely.
Remaining tasks
Make a patch.
User interface changes
None. We decided to just have the option "link to entity", which links to the revision if there is one and otherwise falls back to the canonical entity link.
API changes
Comment | File | Size | Author |
---|---|---|---|
#61 | interdiff-60.txt | 3.88 KB | k4v |
#61 | field-2456599-60.patch | 16.29 KB | k4v |
#56 | interdiff-2456599-53-56.txt | 678 bytes | cutesquirrel |
#56 | field-2456599-56.patch | 17.4 KB | cutesquirrel |
#53 | interdiff-53.txt | 672 bytes | k4v |
Comments
Comment #1
dawehnerIn order to support this properly we have to allow the String formatter to support linking to any revision.
Comment #2
jhodgdonThat sounds like something other of these issues will need, such as the node revision title?
Comment #4
dawehnerWell, I think every entity type supporting revisions somehow would need that, so I went with solving the generic problem, not just the specific usecase of a single special case.
Comment #5
dawehnerComment #7
dawehnerThe remaining test is caused by a too long table name due to the new table name. tricky.
Comment #8
tim.plunkettThis is a nice trick! But it should probably have some comment.
But, how useful is this? If you want to link to a specific vid you cannot, and urlRouteParameters() always calls $this->getRevisionId(), when is that not the default vid?
This won't take advantage of the new $rel === revision hack though, right?
Comment #10
dawehnerThanks a lot for your review!
Well, I wanted to try to avoid that code adding a link to a revision have to deal with that. As we still have the ugly
access checking, catch agreed on IRC to link to the entity itself, if its the current revision.
See core/modules/node/src/Access/NodeRevisionAccessCheck.php:141 in HEAD.
I'm really not sure what exactly to do, honestly
Yeah, but I guess it could when we replace the usages of that handler and all the child classes?
Comment #11
dawehnerWe have to fix the database prefix, as its too long now.
Comment #13
dawehnerberdir had a great suggestion: Just use a different test, which doesn't add an entity type.
Comment #14
effulgentsia CreditAttribution: effulgentsia commentedPer #2393339-57: [META] Make sure Views base fields are using Field API for formatting, and do not lose functionality, tagging for critical office hours, but if there's a reason to not have this particular child issue in that list, please untag it.
Comment #15
larowlanCouple of questions
Also - should we be removing the old plugin here?
As with #8 - a comment here would be great
Can you elaborate on why this change was needed?
Unneeded
Can you elaborate why this change is needed?
Comment #16
dawehnerWell, we first should discuss whether this the right way of solving it ... any opinion?
The SimpleTestBrowserTest test runs the StringFormatterTest. By doing that you result in simpletest123456simpletest12345entity_test__field_test as table name.
This patch replaces the entity_test entity type usage with entity_test_rev which then results in a total tablename size of over 64. Given that the SimpleTestBrowserTest just
tests any kernel tests, we can choose a different one.
Comment #17
larowlan16.1 - I have no issues with that approach
Comment #18
dawehnerIts great that you don't have any issues with it! Let's put up a new patch.
With the change in
Entity.php
itself, this change is not needed anymore.Comment #19
xjmDiscussed with @webchick, @effulgentsia, and @alexpott. We agreed that this issue should be critical because creating lists of node revision titles that respect access expectations is a very common usecase.
Comment #20
larowlanSlightly tweaked the comment.
Manual testing screenshots:
Let's get this one in
Comment #21
alexpottIn NodeViewData - looks like we're still using
Drupal\node\Plugin\views\field\Revision
. Have we fixed what the issue summary claims to have fixed?Comment #22
rteijeiro CreditAttribution: rteijeiro commentedRe-rolled and fixed #21
Comment #23
k4v CreditAttribution: k4v commentedI'm also working on this =). There is another issue here, the UI for the StringFormatter can be better. At the moment you have to check both options to make the item link to the revision.
I change it to have radios for no link, link to entity & link to revision.
Comment #24
k4v CreditAttribution: k4v commentedComment #26
xjmComment #27
dawehner@k4v
If you need any information / help, feel free to ask me.
Comment #28
k4v CreditAttribution: k4v commentedI changed the boolean field in the backend to a string to hold the link_option
Comment #29
k4v CreditAttribution: k4v commentedNow it looks like this. the formatter dropdown does not belong there, it should be some side effect in another issue.
Comment #30
k4v CreditAttribution: k4v commentedComment #31
k4v CreditAttribution: k4v commentedComment #32
k4v CreditAttribution: k4v commentedComment #33
k4v CreditAttribution: k4v commentedComment #34
k4v CreditAttribution: k4v commentedComment #35
k4v CreditAttribution: k4v commentedComment #37
yched CreditAttribution: yched commentedDiscussing with @k4v at dev days.
Do we really need to complexify the UI with a new, explicit setting in StringFormatter for "link to the revision" ?
Couldn't we just keep "link / no link", where "link" simply always links to the correct revision (the one of the entity that contains the field) ?
I mean, the patch adds this code :
So StringFormatter could just do :
and just always link to the right revision ?
Comment #38
k4v CreditAttribution: k4v commented@dawehner said he could be okay with dropping the option to link to the current entity and always link to the revision, although this was possible before in the views formatter UI.
Comment #39
k4v CreditAttribution: k4v commentedlet's see...
Comment #40
k4v CreditAttribution: k4v commentedComment #42
k4v CreditAttribution: k4v commentedI looked into the errors with @xano. Turns out there is a schema missing for \Drupal\views\Plugin\views\field\Field which is the default handler views uses now that I removed the line from NodeViewsData.php.
Comment #43
k4v CreditAttribution: k4v commentedComment #44
k4v CreditAttribution: k4v commentedgo, testbot!
Comment #46
yched CreditAttribution: yched commentedNot sure we want to do that. This doesn't check if the entity is a revision, but if the entity type is revisionable.
So do we really want the option to read "Link to the revision" instead of "Link to the Content" whenever the formatter is used for nodes ?
I'd think "Link to the @entity_label" is good enough (and it silently happens to "do the right thing", i.e link to the revision of its parent entity) ?
Likewise
Comment #47
k4v CreditAttribution: k4v commented@yched: sounds reasonable i change it like that.
Comment #48
k4v CreditAttribution: k4v commentedComment #49
k4v CreditAttribution: k4v commentedComment #50
k4v CreditAttribution: k4v commentedComment #51
k4v CreditAttribution: k4v commentedComment #53
k4v CreditAttribution: k4v commentedComment #54
k4v CreditAttribution: k4v commentedComment #56
cutesquirrel CreditAttribution: cutesquirrel commentedHi @k4v, you don't need to wrap the test class in a
test[]
because it's already done later in the code :Hope it will be ok now :)
Comment #57
dawehner+1 for the interdiff in #56
I would see that patch as RTBC, but I worked quite a lot on it.
Comment #58
yched CreditAttribution: yched commentedNice ! @k4v++
A couple nitpicks below, other than that this looks RTBC to me :-)
Needless hunk, we should keep the [ ] style
Likewise
Minor, code grouping : let's keep the $url = NULL; line with the code block that's below, they go hand in hand.
Nitpick : we could inline the $entity var directly in the $url = ... line
that empty line needs to stay, according to our coding standards :-)
Minor : it's nicer to add a small comment that explains what you are checking (helps people having to debug a test fail in a later patch ;-)) See the beginning of the mathod.
Comment #59
k4v CreditAttribution: k4v commentednits massaged.
Comment #61
k4v CreditAttribution: k4v commentedComment #62
k4v CreditAttribution: k4v commentedComment #64
yched CreditAttribution: yched commented@k4v: thanks ! Let's get this in !
Comment #65
xjmThanks @k4v! Embedding the screenshot in the summary for review. Do you think you could also add a "before" screenshot of what it looks like in HEAD?
Comment #66
xjmOr never mind, just grabbed a screenshot myself. :)
Comment #67
dawehnerNobody will see that the screenshots are out of date :P
Comment #68
k4v CreditAttribution: k4v commentedI took out the screenshots, as the UI is the same as in head now.
Comment #69
k4v CreditAttribution: k4v commentedComment #70
k4v CreditAttribution: k4v commentedComment #71
webchickLooks great.
Committed and pushed to 8.0.x. Thanks!
Comment #73
xjmRestoring tag.
Great job @k4v!