Problem/Motivation
Too many theme functions and theme templates that duplicate the same resulting markup structure.
Proposed resolution
Remove views-more.html.twig and call theme('more_link') instead, and use a render array.
An example of how to do a similar conversion can be seen at #2031301: Replace theme_more_link() and replace with #type 'more_link'.
Steps To Reproduce
- The "Recent content (Content)" view under
/admin/structure/views/view/content_recent
Remaining tasks
Remove views-more.html.twig- Manually Test
Check markup change reported in #21 and #25
More Link Markup BEFORE

More Link Markup AFTER

User interface changes
None
API changes
Removal of views-more-link.html.twig (theme_views_more_link)
Related Issues
#1595614: [meta] Remove all the theme functions and templates in core that simply output a link. Replace with #type 'link' render arrays
#2041909: theme_more_link() needs to accept attributes and options for l()
Beta phase evaluation
| Issue category | Task: because it's not a functional bug fix. |
|---|---|
| Issue priority | Major: because it a code refactoring/clean-up which is important by community consensus. |
| Prioritized changes | Because it reduces fragility and I can also consider that removes code already marked for removal by 8.0.0 as per #1595614: [meta] Remove all the theme functions and templates in core that simply output a link. Replace with #type 'link' render arrays |
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | 2036195-views-more-20.patch | 2.59 KB | rteijeiro |
Comments
Comment #1
thedavidmeister commentedThis is a template, not a function.
Comment #2
jibranTagging.
Comment #2.0
jibranupdated
Comment #3
andypostThe main difference that now view is not passed to preprocess (no idea how views_load_more and others works)
Also this link now gets DIV wrapper
Comment #4
joelpittet@andypost thanks for picking this up!
It's using the same 'more-link' class but that is now on the wrapper
divinstead of theatag. This will make styling this link much easier as it won't have to get unnecessary selectors added likea.more-linkanddiv.more-link, so big +1 to this approach!We need to do a manual test on this, I wonder if there are any views using this option in core, that will help with the manual testing. I don't think so but maybe we can get some steps to reproduce in the Issue Summary.
This removes the built up suggestions. Can we somehow get this back through hook_suggestions() or something on the render array?
This $url->toString() to let it print itself needs to be checked in the manual testing but I expect it should work, and if so +1 to that change!
This didn't need the check plain to begin with, nice change:)
No longer has view variable in the context. Is this acceptable?
Comment #5
Anonymous (not verified) commentedI found a view in core using this option. The "Recent content (Content)" view under /admin/structure/views/view/content_recent
Comment #6
Anonymous (not verified) commentedThe patch didn't apply, so i redid it.
Comment #7
dimaro commentedCheck as Needs review
Comment #8
joelpittet@_nolocation or @dimaro would you mind addressing some of the items in #4?
Comment #9
joelpittetAnd thanks for finding the location where we can test @_nolocation! Mind adding that to the Issue Summary?
Comment #10
m1r1k commentedMeh, I'm a bit late :)
Here is a patch with #view in context and restored view suggestions.
Comment #11
joelpittetAwesome thanks @m1r1k, this could use manual testing, I moved @_nolocation's note to "Steps to Reproduce" in the issue summary.
Just need a bit of assurance with manual testing: Someone can take a screenshots of the markup before and after.
Comment #12
joelpittetSome doc links for what those tags mean:
https://www.drupal.org/issue-tags/special#needs-manual-testing
https://www.drupal.org/issue-tags/special#needs-screenshot
Comment #13
m1r1k commentedBecomes even better :)
Before:


After:
Also now you could create such templates:
containner--more-link[--view-dipslay-id].html.twig or any other common views related suggestion.
Comment #14
m1r1k commentedComment #15
akalata commented@m1r1k, since this is your patch, somebody else should test. :)
Comment #16
rteijeiro commentedJust refactored it a little. Let me know what do you think @m1r1k. Feel free to pay me a beer ;)
Comment #17
m1r1k commented@rteijeiro, you are Mr. Makeup! I'm fine with both requests :)
Comment #18
akalata commentedNot ready for RTBC yet, still needs manual testing. Will do that once #16 passes.
Comment #20
rteijeiro commentedSorry, my bad. The refactor was not as good as I expected so back to previous code from @m1r1k. Just kept the conditions in one line to align with coding standards. Also provided screenshots.
More Link BEFORE
More Link AFTER
Comment #21
akalata commentedWhile I like the formatting of the "after" link more than the "before," I don't think we want to be introducing a visual change?
Though maybe it's fixing an error introduced at https://www.drupal.org/node/2031301#comment-8861319? That issue also has a discussion of whether or not the
<a>should be wrapped in a<div>, see https://www.drupal.org/node/2031301#comment-9062805.Comment #22
haasontwerp commented@akalata I took a look at #2031301: Replace theme_more_link() and replace with #type 'more_link' and can confirm that the full-width link has nothing to do with that issue, checked before and after and the error is not introduced there. Note: the blocks that we're relevant to that issues, weren't view blocks back then.
In this issue we're dealing with a read-more link that's specific to views.
I also looked at before and after #2020393: Convert "Recent content" block to a View. Even directly after the conversion of the recent content block to views the read-more link was still in the wrapper div and not displayed full width.
Currently in head the style shows the version without the wrapper div with a display: block, which makes it display fullwidth. I am about to do a git bisect (http://webchick.net/node/99) to find which commit introduced the new html without the wrapper div, so we can find out if this is a change made on purpose.
Comment #23
haasontwerp commentedSo ive been bisecting all afternoon, still can't figure out where the commit which made the change it. It's somewhere between 87fe2f4 (good) and (4b172c7) bad.
Comment #24
rteijeiro commentedComment #25
haasontwerp commentedFound it: this http://cgit.drupalcode.org/drupal/commit/?id=1b76c015a944617e5edd77a9a2e... is the commit that added the borders to each link. This is done so there is an extra visual indicator for displaying a link, which makes sense. Since the more link is a display: block without a container, it spreads out to the available width. Possible solutions are to alter display to inline-block, but that will make it align to the left, or add the wrapper div previously removed (https://www.drupal.org/node/2226923) again with a text-align: right and an inline-block on the link itself.
Comment #26
akalata commentedThanks @haasontwerp!
Based on the comments at #2031301-128: Replace theme_more_link() and replace with #type 'more_link', the wrapping
<div>was kept in order to position the link without having the dotted underline be full-width. This isn't ideal (see @thedavidmeister's comment in #2031301-138: Replace theme_more_link() and replace with #type 'more_link'), but it's what we have at the moment. I think introducing that bugfix here is okay.Comment #27
yesct commentedI think it would be good to document on the issue a before and after of the markup changes.
Comment #28
rteijeiro commentedComment #29
rteijeiro commentedComment #30
rteijeiro commentedComment #31
joelpittetRe #27 @YesCT do you mean or think we need a change record for this?
Thanks for the screenshots @rteijeiro!
Comment #32
webchickThanks a lot for the screenshots, that's a huge help. Also thanks for the historical digging, hassontwerp. :)
This looks like a great clean-up, and markup is unfrozen, so this is good for beta. I did get confused about why we're doing hook_theme_suggestions() but I see in #4 this was explicitly asked for to retain feature compatibility.
Committed and pushed to 8.0.x. Thanks!
Comment #34
andypostNeeds followup
There should not be full namespace, add "use" statement and it's strange that there's no interface for ViewExecutable
Comment #35
joelpittet@andypost there you go, thanks for spotting that: #2481751: Don't use full namespace for \Drupal\views\ViewExecutable in views.module