I searched far and wide to find a working solution to this but couldn't find it.
What I want to do is change the argument that is passed to the view because I want for pathauto cleaned taxonomy terms to work as an argument. I have a code that transforms cleaned term back to a original one, but cannot make the view use it.
I saw some people changing it in hook_preprocess_views_view(&$vars) but in my case (Views 2.11) has a argument in $vars instanced so many times that it's not the way.
Can anyone please help me change this argument?
There may be a better way but you could use views_embed_view() and set the arguments yourself
I have two ideas, either to add some custom php code to the view's argument's phpcode section that does something like this
$args[0] = 1;
return $args;
or try to use the function
hook_views_pre_view(&$view, &$display_id, &$args) {
// modify $args value here
}
didn't test them so don't know which will work.
I think hook_views_pre_view might help you do just that.
Related
As I have started learning wordpress plugin developement recently but i can't understand the function __return_empty_array. It returns an array but when should we really use it.
__return_empty_array returns an empty array. It is ued to return empty array to filters. For example consider the case of turning off the link of the authors page. You can add the following code to functions.php to get it done.
add_filter ('author_rewrite_rules', '__return_empty_array');
In this case an empty array is returned and __return_empty_array is used for it. Hope you get me.
Im very new to WordPress. I was going through Smooth Slider WP Plugin and saw
if ( function_exists( 'get_smooth_slider_category' ) ) { get_smooth_slider_category('Uncategorized'); }
This pretty much gives what I wanted, but not quite. This pulls all the content in the category and what Im after is just the image URL.
My question is whats "function_exists" in wordpress? and I checked get_smooth_slider_category in functions.php file but couldnt find any. Can someone please explain how function_exists works?
function_exists is a PHP function, not limited to WordPress.
From the manual "Checks the list of defined functions, both built-in (internal) and user-defined, for function_name."
It returns true or false on whether or not the function exists. So you can either create a new function before it that does something slightly different, or prevent an error if it doesn't exist (normally because the required file hasn't been included).
This is a PHP function that checks if the passed in name matches any defined functions (either internal, or user defined).
It is a way to check if a function is "available" before calling it.
I have a Panel Page set up with the path node/%node/foo and all works fine when I visit a link such as node/6/foo. However, when I visit nodealias/foo it doesn't work at all. Is it possible to get panels to work with pathauto in this way?
I am thinking I may have to implement the hook hook_url_inbound_alter and change the url myself.
I also posted a support request in the panels module here: http://drupal.org/node/1219796
As Alexey answers panels doesn't care about aliases, it only sees node/%nid
Here's a good explanation that is valid still for D7:
http://drupal.org/node/211338
To summarize and bring it up to date for D7:
Export your variant for the panel you've created and import it into the panel that overrides the default node display in Drupal.
Add Criterias to the variant so the Panel/variant is only used for the type(s) of content you want to display with this variant.
Voila :) (read the discussion at the link, else the summary will be difficult to understand)
Hope this helps - I myself have spend some time googling and trying to understand this, and I was also confused by the fact that Views DOES care about aliases...
I fixed this using the following code, you would need to alter the pattern to match the pattern of your url aliases and alter the function name to match your module's name.
function brooklands_url_inbound_alter(&$path, $original_path, $path_language) {
$pattern = '#^works\/[A-Za-z0-9]+(-[A-Za-z0-9]+)*\/images(\/\d+)?$#';
if(preg_match($pattern, $original_path)) {
$snip = substr($original_path, 0, strrpos($original_path, '/images'));
$system_path = drupal_lookup_path('source', $snip);
if($system_path) {
$tail = substr($original_path, strrpos($original_path, '/images'));
$path = $system_path . $tail;
}
}
}
You can use this module Subpathauto
it automatically makes the alias to work with subpaths, such as: nodealias/foo
The nodealias is the full alias of your node with nid=6. The third argument (foo) is added through hook_menu() by panels module to the exact alias (node/%nid/%anythingelse) and it is NOT applied to your aliased URL, so you can not use nodealias/foo url to access your panel just because it is not 'hooked' by panels module.
Changing url manually is a good idea, I think.
Given a $node, I'm trying to decide between the following two ways of outputting that $node.
either
$output = theme('node', $node);
or
node_build_content($node);
$output = drupal_render($node->content);
They both seem to give similar results, but is there something I should consider before I choose one way over the other?
Your output is similar if there are no other modules and themes altering the output via the theme layer.
But! If you bypass the theme layer, you'll probably start experiencing unexpected behaviour when you install modules or themes and change config settings that use the theme layer to alter the node's output.
In short, by bypassing the theme layer, you're building error into your application. These error are likely to occur after you hand your application over to someone (a client perhaps) who starts changing settings in admin/
See the decorator pattern if you're interested. Drupal uses this extensively.
http://en.wikipedia.org/wiki/Decorator_pattern
Well, sortof.
What you really want is
$output = node_view($node);
if you just call node_build_content, and then call theme('node', $node), hook_nodeapi('alter') is never called, nor is hook_link().
So if any module is expecting to alter the built node, it wont get a chance to, and if there is supposed to be links on it they wont be there either.
Additionally you can call $output = node_view($node, FALSE, FALSE, FALSE); which gives you the node without the links.
See the documentation for node_view().
If you look into the source of drupal_render(), it actually calls theme() itself as well (provided a #theme override is provided).
In Drupal 7, you should do :
$elements = node_view($node, 'teaser');
$rendered_node = drupal_render($elements);
The solution that worked here was a combination of both of these techniques. Just using theme('node', $node); doesn't seem to work without the help of node_build_content($node);.
Here is the result of an example only using theme('node', $node);.
But if we first do node_build_content($node); prior to handling the $node to the theme function, you can see that the form button is also rendered.
Therefore, the real solution is:
node_build_content($node);
$output = theme('node', $node);
First is recommended, as it is passed via the theme layer.
I have a Drupal filter module whose output I would like to alter, depending on where the output is going to be displayed. Specifically, I want to the filter to give the full output for nodes, but trim the content down for blocks.
I don't think this would be possible. It's hard enough to figure out what context something is being displayed in. It's doable but quite hard to code on your own. However the way the filter system works I don't think its possible within a filter to determine then context of the text being filtered. It's simply not made for something like that.
I'm the OP (but just registered an account).
I did manage to find a solution/workaround. Here's what I did:
Create block.tpl.php in my module which is a copy from system/block.tpl.php, with a constant added at the top.
Put my template file at the head of the theme registry using hook_theme_registry_alter():
function hook_theme_registry_alter(&$theme_registry) {
// using our own block.tpl.php file.
$theme_registry['block']['template'] = 'block';
$theme_registry['block']['path'] = drupal_get_path('module', 'module_name');
$theme_registry['block']['type'] = 'module';
$theme_registry['block']['theme path'] = drupal_get_path('module', 'module_name');
$theme_registry['block']['theme paths'] = Array();
}
Checked for the constant while constructing the filter output, changing as necessary.
Celebrated the outcome.