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.
Follow-up to #2627666: Add a View-latest tab to show forward revisions
Problem/Motivation
The new View-latest-revision tab is showing a draft with unpublished background and is repeating the title. This feels like a theme-level issue.
Proposed resolution
Make it not do that.
Remaining tasks
Comment | File | Size | Author |
---|---|---|---|
#24 | view_latest_tab-2639990-24.patch | 5.46 KB | becw |
Comments
Comment #2
Crell CreditAttribution: Crell at Palantir.net commentedComment #4
becw CreditAttribution: becw at Palantir.net for Acquia commentedYeah, it is a theme-level issue that only (currently) applies to nodes--the view latest tab on core block content does not have this issue. The node template uses the
page
variable to determine whether to output the node title as part of the content.Because this is a node-specific issue, here is a node-specific fix.
Comment #5
Crell CreditAttribution: Crell at Palantir.net commentedNice. :-)
Does this make sense to move to a method of a service? I'd prefer to have no non-trivial code outside of a service if possible.
Comment #6
becw CreditAttribution: becw at Palantir.net for Acquia commentedIs there an existing node-specific service where it might live? Otherwise, I'm not sure--it's based on what node.module does, not that that should be taken as an example.
Comment #7
Crell CreditAttribution: Crell at Palantir.net commentedI don't believe so. Seems too one-off to be put into one of the handlers. The question is whether it's worth the effort to move that to a new service class for the experience. :-)
Comment #8
becw CreditAttribution: becw at Palantir.net for Acquia commentedOk, looks like I need to be moving this into a new service class.
Comment #9
becw CreditAttribution: becw at Palantir.net for Acquia commentedHere's the same thing, as a service.
Comment #10
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedI wouldn't make the class this specific. Rather, what is appropriate to live here? What else might we add?
My inclination would be to rename this to WorkbenchPreprocess, and then move the entire preprocess hook into a preprocessNode() method, which in turn can just call isLatestPage() as now.
A class that's name is the same as its one method is generally a sign that the class is too specific.
Better name: isLatestVersionPage(). (isLatestPage to me implies "is this the latest page of something else", like a most-recently-updated view or something.)
The need for !empty() suggests this could be restructured. Actually, I'm not clear on why we need to compare the IDs. When would those not match?
Assuming we still need that comparison, then we can take advantage of boolean short-circuiting, as elsewhere in the module, and the fact that = evaluates to the value assigned:
Comment #11
becw CreditAttribution: becw at Palantir.net for Acquia commentedThe IDs would not match if you were rendering a node as part of another node -- for example, when it is referenced in a field.
Here's an updated patch with the renamed/refactored class. I have one question, which is inline as a
@TODO
: I passed$variables
by reference to theWorkbenchPreprocess::preprocessNode
method, and I'm not sure whether that is acceptable.Comment #15
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedAs a service, this class is now testable. Yay! It involves an entity and routes, so probably a KernelTest, but it's definitely doable. Let's.
I don't like it either, but that's what we've done elsewhere in the module. Everything else is doing proper returns, but this method is really just the hook itself copied into a class keyword to mirroring the hook's API makes the most sense.
"use" the class name at the top of the file, then the short-name "Node" here.
Comment #16
dawehnerTotally. It is how it works.
IMHO ideally we would pass along the route match from outside into this method. One less "state" needed. Is there a reason why this wasn't implemented in an entity generic way?
Comment #17
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedHm, yeah getting the route match in the hook method and passing that to isLatestPage() is even better, and makes testing easier, too.
This is a node-specific bug due to the way nodes get themed. That's why it's a node-specific solution.
Comment #19
becw CreditAttribution: becw at Palantir.net for Acquia commentedI've added a unit test now, but I haven't refactored the
CurrentRouteMatch
thing yet.I did a unit test instead of a kernel test because I don't think it's necessary to have that much integration available for what is being tested here. On question, though: am I using
prophesize
/willReturn
wrong inWorkbenchPreprocessTest::setupCurrentRouteMatch
?Comment #24
becw CreditAttribution: becw at Palantir.net for Acquia commentedHere testbot, have another patch.
Comment #25
dawehnerMh, so the route at least is generated for every entity type, so is there a reason this code is specific to nodes?
Comment #26
becw CreditAttribution: becw at Palantir.net for Acquia commentedThis code is specific to nodes because the bug is specific to nodes--node templates use the
$page
variable, which is what is being tweaked... ahh, I see, so perhaps this specific method should not be node specific. I'll tweak that, thanks!Comment #27
becw CreditAttribution: becw at Palantir.net for Acquia commentedOk, I looked at the code more closely and changed my mind. The route is added to any moderatable entity type, but I think asking the router for arbitrary loaded entities and comparing them to the passed-in entity is too much complication here.
Comment #29
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedI agree with Bec. This is node-specific code to fix a node-specific bug, using a node-specific core oddity because nodes are still special, even in D8. :-(
Merged. Thanks, Bec!
Comment #30
dawehnerAlright!