In my application, all I need is a way to define sections, and then check what section I am in. In using the sections module, I needed a way to return just the name of the section.
Sections_in_section() returned an object with a bunch of section data that did not include the section name.
This patch adds 'name' to the object returned by sections_in_sections, it also provides another function, sections_check_section, which leverages sections_in_sections and behaves how I had expected sections_in_sections to act.
function sections_check_sections($section_to_match = NULL)
If a string is passed to the function, it checks if that string matches the name of the current section and returns TRUE/FALSE based on this match.
If no string is passed to the function, it returns the string name of the current section
Feel free to get some dialogue going here. sections_in_section simply didn't do what I needed it to do. I actually don't care about defining different themes to different sections. I think it might be a good idea to strip down this sections module to ONLY handle defining and checking sections. Then write another module, section_theme or something like that, which themes by section. Just a thought.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | sections_name.patch | 894 bytes | sime |
| #2 | sections_kingmoore_patch_150208.txt | 2.29 KB | KingMoore |
| patch_vday_kingmoore.txt | 1.89 KB | KingMoore |
Comments
Comment #1
hass commentedSee http://drupal.org/patch/create how to create unified patches. Please do not set your own code to RTBC.
Aside could you please give a more detailed explanation what you are doing there and why your need to create sections from outside of sections and what your own module is for or what the intention is.
Comment #2
KingMoore commentedThanks for the quick response. Good to see someone is actively monitoring this module. I redid the patch with -up. Didn't know that was required. Will do that in the future and also not submit as RTBC.
As far as more details as to what I am doing... The reason I turned to the section module was because I needed to be able to define sections of my website, and then in templates.php make decisions based on what section I am in. I didn't need the theming bits, just the section logic that this module does pretty well.
The problem was, when I called the sections_in_sections() function, rather than getting returned what section I am in, I got back an object with the section properties (path, status, visibility, theme, weight) but not actually what section it was (name). There is no way to tell what the section is from just the properties.
Also, sending a $section string to sections_in_sections() does not seem to work. It is compared to the sections object, and in my bit of testing always returned false.
I added one field (name) to the query and object that is returned by sections_in_section() so you now actually get the name of the section back, in case you need to use that. I didn't want to change much about the sections_in_sections() function, so I added another function, sections_check_section(), that levereges sections_in_section(), and responds how I had assumed (incorrectly) sections_in_section() would.
sections_check_section() can be called with a $section string, or without any parameters just like sections_in_section. It then calls sections_in_section(), gets the object of the current section (with name), and then either compares that name to the string sent sections_check_section() and returns TRUE/FALSE, or else just returns the section name if no parameters have been sent to sections_check_section.
In summary, sections_check_section() allows you to find out the name of the current section, or check to see if you are in a specific section.
Comment #3
hass commentedWhy do you need the section name on theme level? It sounds like you are doing something not correct. If you'd like to switch themes you should create n-themes as you need them. For e.g. with subthemes. You could take a look to http://www.yaml-fuer-drupal.de/ for an example about different page.tpl.php's and how this should be done to be save for D6 - or take a look into minelli if you have CSS subthemes only.
If this doesn't help, please try to explain why you are switching a theme at theme level. It sounds to me - you are trying to bend drupals theme engine... something i tried in my first days, too. Theme level is too late to switch a theme. However i cannot really follow. A real world and short example what you are trying to archive would be helpful.
Comment #4
KingMoore commentedI am not using the theme functionality of sections. I simply want to be able to test what section a user is currently in, and then use that in various ways.
Here is the real world situation that came up:
I have 4 navigation images that are being outputted by signwriter. When a user is in a current section, I need to send a different background image to signwriter so that the "current" nav image has a different look than the other nav items. I used the section module to define my sections, but I needed to find out what section I was in in order to know which nav image needed a different background image sent.
Comment #5
hass commentedWhat is "signwriter" you are talking about?
If you have some primary menu items and you click on one, this menu item automatically get's the class "active". With the "active" class you can assign a background color via css. This is a standard menu item feature... something wrong with this?
Comment #6
KingMoore commentedSignwriter is another module. http://drupal.org/project/signwriter, and yes, the "active" class doesn't work for me.
However this isn't an implementation specific issue. In using sections, I would like to be able to identify what section I am in. With the current sections API functions available to me, I cannot do this, so I added a function to add this functionality to the API.
Comment #7
hass commentedWell sections does not provide this info. You are trying to identify something that the module isn't for. Sections should switch a theme based on sections (path matches) and not provide names of matching regions to themes.
Why are you not switching with sections to "subtheme1" with the correct background color and if you need another background you switch to subtheme2, etc.? This should be a CSS-subtheme only and therefor a subtheme with "one" line of css code. I think this will be the Drupal way...
Comment #8
KingMoore commentedYeah I realize sections didn't provide this info, although it is doing all the other work besides actually making the section name available to the developer. Rather than writing a whole new module it seemed logical to use the existing sections module and add a function to return what I needed.
You keep trying to tell me other ways to solve my problem, but they don't work. Believe me, I exausted all the CSS options before determining this was the route I needed to go. A CSS/Theme solution simply wont work with the signwriter implementation we have here.
If you don't want to apply the patch, that is fine. I will continue to use it in this way. Perhaps one day I will port it to a separate module which only defines and retrieves sections. Since I had written code I was using, I wanted to make it available to others who might have a similar need. That is all.
Thanks for your timely responses and the dialogue.
Comment #9
simeMy attempt to clarify ...
Basically, we have a design client who specifies site sections in the design. The types of changes we need to apply are breadcrumb alterations, and adding a class to the body tag.
We'd like to use the Sections module to put section control in the clients hand's. But the only problem is, we can't ask "What is the current section?" from our template.php.
Comment #10
simeComment #11
hass commentedSorry guys, but i really try to understand what you are trying to archive... I'm not against a feature that helps, but it should be the right drupal way.
Getting a sections "name" from an api is a *very* unsafe value. This value might change in UI and you cannot hardwire something on this name! I'm not sure if you thought about this yet... hardwiring something on the sections name is wrong! Additional doing this api request (from patch above) would result in an extra SQL request, what is not good.
Be assured i'm maintaining a very advanced theme and i know some tricks not visible in normal themes on d.o. All i read from the above is you'd like to change background colors based on themes and change the breadcrumb. Subthemes are the perfect solution for this! You should really take a look into "YAML for Drupal" theme how this could be done... If you'd need to change the breadcrumb - you cannot use CSS themes... so you must go the way i used with yaml, too. Add a page.tpl.php and all other template files to a subtheme folder + template.php. Add the special background colors to this subtheme with something like
#breadcumb {}andul.menu .active {}class or whatever your menu class is and whatever more you need to change in this section - change the subtheme...For altering the breadcumb, add the following code to the subthemes template.php and do your alterations (example from garland).
And every time this theme is active, you are *sure* what you must do in this theme used for your section. Please, try the above.
Have you checked the yaml for drupal theme i provided the link for in #3?
Comment #12
simeHi hass
Thanks for persisting, I see what you're saying. I'll discuss with KingMoore further but mark won't fix for now.
(Regarding the YAML link, can I switch to English on that site?)
Comment #13
hass commentedI've waited long time for D6... and i'm working on this upgrade. After this is done - for sure - the english site version of YAML for Drupal will come, but it's not ready... yaml css framework (see http://www.yaml.de/en/) and documentation is nevertheless available in English, but wouldn't explain the drupal theme and logics inside the theme. I'm going to work on this docs after the next release...
Comment #14
simeHi hass
I've discussed our requirements with KingMoore, and we still desire to know what section we are in. To me, not knowing the section name/sid is like not knowing what content type a node is :)
I've attached a patch which does the bare minimum, hope this small change can be accommodated.
Comment #15
hass commentedCould you please answer my questions in #7 first?
Comment #16
hass commentedhttp://drupal.org/node/227743
Comment #17
simeHi hass
I'm disappointed that we couldn't get this small change in. It doesn't break anything and it encourages us to use this module and thus extend your user base.
#7 continues to ask us a question which is not relevant to us, we don't work like that.
Good luck with the module.
Comment #18
simeApologies, I see the linked thread does contain what we need. Ignore my previous comment please.