Closed (fixed)
Project:
View reference
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
25 May 2012 at 21:06 UTC
Updated:
20 Jun 2012 at 00:41 UTC
Jump to comment: Most recent file
Comments
Comment #1
danielb commentedI'm impressed with the contextual links, though a bit concerned about this 'cleans up the theming process' bit... Will have to analyse whats happened there...
Comment #2
danielb commentedChanging how the theme functions work is pretty much out of the question, as it would require any theme implementations on existing sites to be changed. I think you've just taken the flexibility out of it in favour of less code in theme functions by making it do specifically what the stock formatters need?
The intention is that viewreference_get_view() provides an array of data/string/html components as decided by the theme implementer, and then the theme functions are used to compose the final HTML string. I think the shortcuts make it unclear to themers how they can easily tweak it since it directly returns a render array from another function.
Comment #3
markhalliwellOk, I can understand the breaking sites part... one of my downsides to remember when it comes to theming functions. I was in favor of actually reducing the code, but having to keep the module backwards compatible prevents that. I did kind of rework some of the logic to make sense and also added commenting where I could.
I refactored the patch against 7.x-3.x-dev.
Comment #4
markhalliwellMight help if I actually attach the patch lol not my week.
Comment #5
danielb commentedWhen creating issues about one thing, why patch a whole bunch of things without explanation? I don't see any reasons to include a majority of these changes. There are still changes to the theme functions, to the wording of comments, to how variables are aliased/used/named. I don't see any justification or reason to change all this. The new functionality is not added with the technique of how everything that came before it works. It just seems like you decided you didn't like it and rewrote a lot of it, but it isn't necessary.
You have provided the logic for what is needed to solve this issue, and I can work with that to incorporate it into a method consistent with the current implementation.
Comment #6
danielb commentedHere is a patch where I've added the contextual links to the default and full formatters, I think those are the ones where you might typically want them. It is done using the same technique where the themer requests the pieces they need and then can assemble them as they see fit (rather than it being automatically added to their output through a function call).
I've changed the call to views_add_contextual_links() to use 'view' as the location, as that seems to be more correct than 'block', for the context we are printing the view in. For some reason a lot of views plugins only provide a 'page' location for the contextual links, which is a bit weird so nothing happens. Therefore I have also checked the #contextual_links param because if it doesn't exist then a warning appears when you try to render it.
For views that do provide the right contextual links for the right location it all seems to work fine.
The other changes given in the other patches would have to be discussed in their own issues, but honestly I think you've changed some things without realising the intentions or understanding the benefits of how it currently works, and some of the changes are not needed and just make the workflow less verbose for novice themers.
Comment #7
markhalliwellRe: using the 'view' location instead of 'block'
See: http://drupalcontrib.org/api/drupal/contributions!views!views.module/fun...
Meaning that, for instance, if the view that you're trying to attach is a block then it will not show any contextual links. That's because the block display plugin provides it's own contextual links (same for page). So, in retrospect, I'm almost half tempted to say we should use the 'special_block_-exp' location as it's added to every plugin and it doesn't matter what type of display plugin the referenced view is using, yes?
I apologize if I wasn't clear enough. It wasn't initially my intent to radically alter how this module functions. Rather, I was trying to encompass very standard drupal practices when involving contextual links. Your patch will not work (at least from a UX standpoint). You may be able to add the contextual links to the output array and then render them in the theme, but you're not actually wrapping them with the 'contextual-links-region' that's necessary for keeping the cog relative. This is why I was trying to wrap the entire output of the format. It was to provide a relative region that shows the contextual outline (for the entire field formatter itself).
I was just trying to improve the understanding of what was actually happening. Sorry. Didn't realize that was wrong.
I don't know if I necessarily didn't "like it" or not, but it certainly didn't feel like it was the "Drupal way" to code what needed to be accomplished. I was at little taken back at how drastically this module throws so much control at the theme level. While I agree that themes need better support for hooking into what a module outputs, this is almost too much.
This module provides 4 different formatters.... four of them. All of which use the exact SAME function to generate it's content. If people are really customizing these theme functions, then why even provide four different formatters? Isn't that a little redundant? Couldn't they just have one that they could override if you can pass the same call and return the same array? I might not know the history of the module, but this just seems a rather odd way to go about implementing formatters.
Also, you indirectly talked about backwards comparability above. Because of how this module implements it's formatters, it gives the theme the ability to determine how it's structured. Doesn't that kind of defeat the whole purpose of the formatter? It does not allow for new features (ie: contextual links) to be added without having to tell the developer/themer "hey... you'll have to add modify your template file" (which would have to happen regardless of either of our patches).
Originally, I almost took out the need for specifying what should be built and just build out all of it, let the theme function decide what it's going to use. I then realized that it's probably because you're trying to cut processing time (why build out what you're not going to use) which I understand. It still just feels like it's the wrong way to accomplish what needs to be accomplished.
I really feel that the module should just provide a default formatter. One that simply generates the view. Then have it pass through a theming function that allows the theme a chance to render it how it wants to. After that it would add any contextual filters that are needed. Simple. I know that what I'm suggesting is really a 4.x branch, but in all honesty it's needed.
The whole purpose of a formatter is to "format the display" of a field. The field is the view (via reference). I think it only makes sense to have a default formatter and then provide settings for that formatter (ie: checkboxes) to determine which components should actually be rendered.
I'm sorry for the long post, I just don't see why it has to be this complicated.
Comment #8
markhalliwellSummary:
My second patch did provided exactly what you asked for (backwards compatibility) within the confines of the module's current formatter/theme implementation. I apologize again for the long post. I just felt I should further explain why I did what I did. I don't normally do such drastic changes to code, but I honestly felt it was needed.
Comment #9
danielb commentedYes, I did notice that was always present. I would be willing to change to that as well.
I'll look into that. It certainly seems to work, the cog appears, and the dotted line wraps the view. Not sure how/why it knows to do that since it's output before the embed code.
Yes I got the sense you were doing it more the 'Drupal way', but the way I saw it was that it was more the 'Drupal module way', which I think is against the spirit of how theme functions should work. There are certain consistencies I've noticed in good theme functions, always aliasing the $variable keys, always starting by declaring $output as an empty string which is added to through the function, and then returning $output at the end. It makes it very clear to casual themers what they're expected to do. View reference is a bit more complicated since it has to interact with the Views module too, so it isn't perfect in it's simplicity.
I'm all for people being responsible for their own themes and me doing less in terms of maintenance, but people kept requesting or providing patches to add more formatters/themes, and for things people might commonly want - hey why not just make it easy to do via the UI - and it wasn't that much of a chore to add.
The common functionality between the formatters which is to get the view, etc.. was extracted out of the theme functions into viewreference_get_view() because themers shouldn't be concerned with how to integrate with views. It is unavoidable that all the formatters have to do some things in common, so why not use the same function? So they nominate what they want (so we can avoid generating everything, like embed code when they only need a link - executing and rendering the output for a full view is quite a hefty operation), and we return those components, as well as the View object itself if they need to make decisions based on what's in that. The views stuff is kind of put behind-the-scenes so they don't have to worry about the logistics of that. The focus of the theme functions is on HTML output, though by default there isn't much output at all. The default themes just spit those components out one after the other, the themers might choose to do something more elaborate of course.
The themes are intended to look straight forward and make them approachable to newbies but still have the potential for a more experienced user to really customise them.
I guess I don't really understand what you're saying. To me a formatter is just a bridge to the theme, because the theme is the thing that the site admin can actually control. This way if someone is unhappy with how it works I can just turn around and say it's their responsibility to theme the site. Maybe that's the wrong way to look at it, and it seems so from your next suggestion, but it works.
I like the idea of using settings on the formatter rather than multiple formatters. The concept of using settings on a formatter is quite unfamiliar to me though, I pretty much learnt how to make these sorts of modules based on Node reference in Drupal 5 and 6 which used multiple formatters. I would be willing to consider a new branch if you started an issue where we could discuss improvements in regards to simplifying processes using better use of formatters. As long as I could still put the burden of customisations onto the site admin in terms of output. Perhaps rather than trying to compromise with how it currently works and how it should work, we can get a clean slate to start from.
I disagree that the patch gives backwards compatibility. For example, you removed the ability to return the view object to the themer, and instead put the embed code into the view key. That is going to cause headaches for people currently looking for the view object in 'view' or the embed code in 'embed'. Anyway, I didn't actually ask for backwards compatibility, I probably wasn't very clear but what I wanted was for the extra changes to not be included at all, just focus on one thing at a time. If we want to change something like how formatters work, that definitely deserves it's own issue, and it would be good to get some opinions from other users as well.
Comment #10
danielb commentedI'm committing the patch. It certainly appears to work, and the view is infact wrapped with a contextual-links-region, dunno where that came from but it's there.
Comment #11
danielb commentednevermind I've been looking at the wrong thing
Comment #12
danielb commentedComment #13
danielb commentedFixed, the div just has to be put in through the theme function. Which is technically where I want HTML to be controlled, so I guess that makes sense.