By work77 on
Do I have to create an entirely new Search Block just to modify the Search label and add some style formatting? I understand just simply modifying search.module isn't legal.
I'm thinking there must be an easier way.
Thanks.
Do I have to create an entirely new Search Block just to modify the Search label and add some style formatting? I understand just simply modifying search.module isn't legal.
I'm thinking there must be an easier way.
Thanks.
Comments
=-=
the label can likely be altered with stringoverrides.module
style formatting is done with CSS
-
Thanks for responding VM. I was actually looking for a more programmatic way to do it. So, something in between a generic "modify module" module and re-writing the block altogether. Because I'm also looking to do some other subtle changes to existing modules, like removing the "Create a new user account" and "Request new password via e-mail" links that are defined here in the User module. Modifying php isn't a problem. I'm just not sure exactly what needs to be done. Is it possible to override like that somehow?
$items[] = l(t('Create new account'), 'user/register', array('attributes' => array('title' => t('Create a new user account.'))));
$items[] = l(t('Request new password'), 'user/password', array('attributes' => array('title' => t('Request new password via e-mail.'))));
=-=
investigate hook_form_alter @ api.drupal.org
...
theres quite few ways, take your pic:
hook_form_alter - all powerful way to mod FAPI output, needs to be in a module, can get long and tedious to maintain.
override templates - the simple way (usually), eg search-block-form.tpl.php
preprocess functions - the counterpart to templates - eg function themename_preprocess_search_block_form(&$vars)
hook_theme - register a function that mods the form output, done in theme layer, pretty easy
Of the four above I think hook_form_alter is what you are looking for, since you can make small changes and then just return the rest of the form.
Just remember that every time you hack core god kills a kitten ;)
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
-
This is a very helpful summary, Jeff. Thanks. Creating a search-block-form.tpl.php file worked for me, but it brings up a few questions.
1) What is the rule behind naming it search-block-form.tpl.php? Is it because that is the name of the id of the form element? Would that mean I can intercept ANY element the same way?
2) Is the $search variable available to me there solely because it has been defined in the 'features' array in my .info file.
3) What, if any, is the relationship with the file that I created and the file of the same name in the 'modules/search' folder?
Thanks again.
=-=
http://drupal.org/node/190815#template-suggestions & http://drupal.org/node/223440 may help clear that fog. The devel.module helps a great deal as well.
What?
What? Modifying the search module isn't legal? Why? I thought that this was an open sourced community... so, you may not be able to change the search module downloaded on this site, but surely you can modify it any way you want on your own?
Nameless
-
'legal' wasn't literal. :)
=-=
what the user means, it is frowned upon to hack core files or contrib files for that matter. Drupal uses a hook system as well as a theme layer to change parts of drupal you want to change. Hacking away at files can become a PITA over time as you will be less likely to update core or modules because you've altered the actual files to suit instead of building your changes at the theme layer or in custom modules using the hook system.
OK
Ah... OK... I think I get the point now... and the main thing is the module not being able to update correctly as well... well, if I could change the module, I would, but I couldn't be bothered and while it may not suit my site, it seems to blend in perfectly well... so it should be OK? I don't think I will change it anyway. :P
Nameless
...
You certainly dont want to be hacking core or important contrib modules like Views and CCK unless you have a very good reason to - but I have no issues with hacking small modules to make them do what I want, or more precisely I will build a whole new module based on the contrib code but modified to do what I want.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
_
This actually touches on a question I have, Jeff. You say you will "build a whole new module based on the contrib code". I take it you're just referring to the non-themable functionality, yes? Is this the only way to properly override non-themable functionality? What about overriding already-overridden functions?
For example, I want to add one line to the dhtml_menu_theme_menu_item() function (the proper way). But, 1) It's a user-contributed module. 2) As the function is already an override of the theme_menu_item(), it doesn't begin with 'theme_' or 'template_preprocess'. Do I need to create a whole new module just to add one line?
Thanks.
...
The theme always gets last crack at theme functions, so you can copy the function from dhtml module to your template.php file, rename it to match your themeName and make your change, it should work - I'm not so familiar with this module but that should work. You might have to clear the theme registry to get it kick in.
The sort of stuff I am talking about is rather major hacking and adding features etc, I wouldn't bother with a whole new module if I can just override a theme function in the theme, unless I needed it to be theme independent (such as the end user wanted to switch theme or similar).
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
_
I did try copying dhtml_menu_theme_menu_item() to template.php and renaming it to my_theme_1_dhtml_menu_theme_menu_item(). Cleared the cache. But it was ignored. From what I understand, you can only override functions that start with the word 'theme_' to work in the template.php file (where template_preprocess functions can be semi-overridden too.). So, the next thought would be to just rename it to my_theme_1__menu_item(), but then this function would override ALL references to the theme_menu_item, not just dhtml's. Unless you know of a magic way to retrieve the calling module from within the function. Then I could just make a condition.
So, I'm still confused about how to properly override an already-overridden function, and also how to override a function that has nothing to do with theming. In other words, just tweak the logic. Start a new module from scratch?