I'm creating a module wich provides a separate node overview page for each content type.
My problem lies in trying to recreate the node operations dropdown.
In the node module this is done by calling the module_invoke_all function with the 'node_operations' hook.
This returns an array of all modules that implement the 'node_operations' hook.
In my case the following two modules: 'node' and 'nodewords'.
When I call module_invoke_all('node_operations') in my module, it returns only the 'nodewords' module, not the 'node' module.
This is because the 'node_node_operations' function does not exist.
Can anyone explain this behavior?
It looks like the hook is in node.admin.inc, which is not automatically included. See http://api.drupal.org/api/drupal/modules--node--node.admin.inc/function/node_node_operations/7
This is imho a bug, you should look if there already is an issue and if not, create a new one.
Anyway, as a workaround, you can include the node.admin.inc file like this before calling the hook:
<?php
module_load_include('inc', 'node', 'node.admin');
?>
(Yeah, weird syntax ;))
Related
Hi Can anyone Please let me know can we use php inbuilt function inside a twig file.if not then why.
What is the way then to access php inbuilt function inside a twig file.
Because in a application in 100 of time we need to check many conditions basis of php inbuilt function.I have tried in_array() function to check multiple vaslue selected in a multiple dropdown list but i am getting error Is_array() not defined.
Please help
Thanks
As #DonCallisto Said, There is some PHP equivalent function exists in twig not all. So you cant call a php function from twig template. You may have to use a existing equivalent or need to create one if not exists.
Why?
One of the main reason is SoC. Template is for presentation layer of your application. So twig made available tools(filter,functions, global variables) to do that.
Know the differences
Though you have date function in twig. its not the same date function you have in php. To achieve a similar functionality you may have to use same or different approach in twig then php. for instance you can achieve php's in_array functionality using the twig's Containment Operator
What is the way
Now come to last part of your question:
What is the way then to access php inbuilt function inside a twig file?
I think you already know the short answer from #DonCallisto. You can create your own extension. And define what function you needed. Or if you are crazy enough to access all php builtin function from your template, you can use this Extension. It will allow you to call any php functions by prefixed with php_. for example if you like to call in_array function, then you can call like php_in_array() from your template.
Happy coding!
Twig have some php builtin functions equivalent. For instance in_array() php function is in twig function. Check it out
If you don't find some builtin, you need to write your own twig exstension
Buddypress has a group functionality in which I combined with the plugin BP Group Hierarchy so that I can create an hierarchy of groups based on user role.
However, the plugin used an method as taught by Buddpress in group-extension-api> link.
The group steps are registered using the function bp_register_group_extension and add_action are called. I tried to remove the action by with no success. Because I not really understand how the array works i.e. array( &$extension, \'_register\' ), so I go search out and found this post.
There's a line stating that
The new format for the above object referenced method callbacks are always: class name, followed immediately by the method name, followed by the amount of previously added (classname+methodname). For classes, this allows you to add as many object referenced classes and add methods which don’t override each other.
However I can't seems to be able to remove the action.
I tried to remove the action by putting following lines of code in function.php
function remove_bp_hierarchy(){
if (has_action('bp_actions')) {
echo $extension = new BP_Groups_Hierarchy_Extension;
remove_action('bp_actions', array( &$extension, '_register' ), 999);
} else {
}
add_action('bp_init','remove_bp_hierarchy', 999);
Is it something wrong with my remove_action or I use wrong method? Thanks and regards.
## Update
Found a page in which let we see a list of hooks and also hooked function in the page. I see that there's a function with the name _register which is the function I'm looking for. However, class address always change. I was thinking using the function found to do a preg_match on it and remove it when it found. this is super heavy. So is there other way of removing it? Thanks and Regards.
CodingBabyDotCom -
Long story short: you will have to traverse the $wp_filter array to remove the action.
You need a reference to the SAME instance that was used to create the action in order to remove it with the remove_action function. So the function you posted doesn't work because it is using a new instance.
Unfortunately bp_register_group_extension() creates only a temporary instance, so it can't be referenced by later functions.
The code in your comment will remove ALL actions at level 8, which means all group extensions. To remove only the one you want, iterate over each filter and check its type with:
is_a( $wp_filter['bp_actions'][8][$key], 'BP_Groups_Hierarchy_Extension' )
I have an insert hook that catches nodes whenever the user adds a node.
So here's my code:
function blah_insert($node){
$record = array(
'nid' => (int) $node->nid
);
drupal_write_record('table_name', $record);
}
schema::
table_name(
nid int primary key not null
)
Performing a check on the return value of drupal_write_record results in FALSE. db_query doesn't work either. var_dump confirms that all the fields are where they're supposed to be.
The nodes are properly being inserted into the node tables but not the table that is defined by the schema in my install file (not written like the schema that I have above of course - nid is defined as an int and all other relevant fields).
Does anyone have any idea as to what's going on?
Make sure your module is installed and enabled
Make sure your module name is definitely named blah (or whatever you're putting before _insert
Make sure that you're using the right hook...if your module is not responsible for defining a content type (i.e. a 'node' module) then you're using the wrong one. From the docs of hook_insert: "This hook is invoked only on the module that defines the node's content type". It may be that you're looking for hook_node_insert() instead, which responds to the insertion of a node of any type.
When you implement any hooks in your module make sure you clear caches afterwards, depending on what version of Drupal you're using these implementations may be cached for quicker access and won't be picked up until that cache is cleared.
Check that your custom table actually exists in the database! If not grab the devel module, install it and visit /devel/reinstall where you can invoke a full re-install of your module.
Once you've checked those if is still doesn't work it's symptomatic of a larger problem with your Drupal installation...if your schema is as you've said it is above then there's no reason drupal_write_record() wouldn't work if the function is indeed being run.
I have read the docs over and over trying to wrap my head around this seemingly simple task. Basically, I have a template with a 'skip navigation' div hard-coded in html.tpl.php that I do not want on front-page.
My idea was to set a $vars['skiplink'] variable in theme_preprocess_page. Since this variable contains a few lines of html markup, I was aiming for something as seen in garland theme:
function garland_preprocess_page(&$vars) {
// Move secondary tabs into a separate variable.
$vars['tabs2'] = array(
'#theme' => 'menu_local_tasks',
'#secondary' => $vars['tabs']['#secondary'],
);
<snip>
I would like to have the html in a themable function or even a template, but I cannot even get this snippet to work:
/**
* Override or insert variables into the page template.
*/
function morin_preprocess_page(&$vars) {
// add skiplink markup
$vars['skiplink'] = 'hello world';
}
This generates a notice:
Notice : Undefined variable: skiplink in include() (ligne 14 in /var/dev/morin/www/sites/all/themes/morin/templates/html.tpl.php).
Can anyone slap me with a clue? I would really like to understand how to do this with both methods, ( template & function ). I'm also wondering if this should be done in a module?
I realise there are probably 10 ways to skin this cat, so any insights on pros/cons of methods used are welcome.
Ok I figured out I was using the wrong preprocess function, setting $vars['skiplink'] in preprocess_html is the way to go for top-level variables.I still have yet to figure out in a clear way how to associate this variable to a template file.
The preprocess hooks follow this pattern:
<theme name>_preprocess_<template name>
So if you want to modify the variables for "html.tpl.php" you want to use this hook:
<theme name>_preprocess_html(&$variables)
You are using preprocess_page but you are inserting the variable in the html.tpl.php.
You should either insert it in the page.tpl.php or rename your preprocess function, to add the variable to the html.tpl.php
And remember to clear cache if you didn't have the preprocess function defined already.
Update:
You seem to be missing a key point. Preprocess functions (along with the actual theme call) is how you make variables accessible in templates. Different preprocess functions are called for different templates, (..._page for page.tpl.php etc.)
Do you still have problems after using the correct preprocess function and clearing cache?
I've created a content type that has a CCK text field.
When I select the text field using the Drupal Themer widget it tells me the last function called was
theme_text_formatter_default() , which I found in the CCK text.module
It also tells me that it's parents were;
content-field.tpl.php < theme_markup < theme_markup < node.tpl.php < page.tpl.php
So I assumed that somewhere in the content-field.tpl.php was the function call to theme('text_formatter_default',$element) but it wasn't in there. Just print $item['view'] used to display the content.
I searched all the project files for theme('text_formatter_default',$element) and it doesn't exist. I know it's being called by the theme function as I override it in my template.php and it used my overridden function, which would only happen if was using the theme_hook$. Wouldn't it?
So how is it being called? It's not that I need to override it. I'm just learning how drupal works and thought I had it sussed until this. Something must be calling it.
Also, the function theme_text_formatter_default exists in the theme registry and it's overridable (if that's a word) as I did so in my template.php and it displayed. It's all quite confusing.
Any help would be much appreciated
It's CCK that calls the theming function.
When you create a CCK field you select a widget. The widget corresponds to a theming function that is called. That's the short explaination.
To understand the entire mechanics will be a bit difficult as creating a cck field is a complex subject lacking good documentation.
To really understand what, how and why, you would need to understand how the CCK module works internally. Probably to the point where you could write patches for it. Something very few people could help you with.
Edit:
I don't know the CCK module in depth, I have only created my own field formatters. Anyways, I looked though the db and found that the table content_node_field_instance holds info about each CCK field, one of the columns is widget which it seems, is where CCK stores which theming function to call. It knows what function to call because if the naming convention that is used and through the implementation of hook_field_formatter_info, which is what other modules uses when they want to tell CCK about how to theme a field.
The function is defined in text.module. the theme function that matches the entry text_formatter_default returned from the implementation of hook_theme()istheme_text_formatter_default()`.
/**
* Theme function for 'default' text field formatter.
*/
function theme_text_formatter_default($element) {
return ($allowed =_text_allowed_values($element)) ? $allowed : $element['#item']['safe'];
}