drupal 7 hook_form_form_id_alter - drupal

I'm trying to hook into a form with ID equal to "block-admin-configure," mymodule_form_block_admin_configure_alter(&$form, $form_state, $form_id) is not being triggered. When I use mymodule_block_view_block_admin_configure_alter(&$data, $block), it works perfectly.
My goal is to add some additional configuration options to a regular drupal block.

hook_block_configure() etc are only called in modules for blocks that that pareticular module defines in hook_block_info(), so if you're trying to hook into a block defined by another module you'll definitely have to user a form_alter function.
Just a note, hook implementations are cached in Drupal 7 so any time you declare a new hook you have to clear the caches before it'll get called.

Related

How to update update existing custom post type with register_post_type permanently?

I want to perform quick rewrite slug update for my custom post type on the fly. So I use code like in my theme's functions.php:
$no = get_post_type_object($pt_slug);
$no -> rewrite['with_front'] = false;
$no -> rewrite['slug'] = $slug;
register_post_type($pt_slug, $no );
Which is hooked to 'init' add_action('init', 'check_post_type_rewrite_url');
There is large code so I write only issue part in here.
register_post_type returns object with updated slug. I understand it means my custom post type was updated, but it was not. Existing post type still has its old rewrite slug. Should I add something special for rewrite rules to save changes and make it work? Or there is specific way to register/update post types with rewrite slug so it worked?
The way you solved the issue - by using flush_rewrite_rules - is technically correct but not recommended. As stated in the doc:
This function is useful when used with custom post types as it allows for automatic flushing of the WordPress rewrite rules (usually needs to be done manually for new custom post types). However, this is an expensive operation so it should only be used when absolutely necessary.
So you shouldn't keep your flush_rewrite_rules() call in your init hook, as it will regenerate all the rewrite rules at every page load, which is really badly ressource consuming.
Usually it's enough to just visit the Permalinks Settings page to flush the rules - so if you change again your CPT slug in the future, just visit the page once.
If your slug could change dynamically, then you can make use of flush_rewrite_rules(), but you need to use it carefully - it shouldn't be called on every page load, but could be used by a periodic cron job, or on plugin activation / deactivation, depends of the case.

Drupal Webform hook_webform_submission_insert not firing

I am trying to use the hook_webform_submission_insert in my theme template.php file. I have 2 other webform hooks currently running in here and they work just fine. I am trying to get the submission data after it has been submitted. Below is my code.
function acquarius_hook_webform_submission_insert($node, $submission){
var_dump($node);
var_dump($submission);
}
I am sure I am missing something small here but everything I try seems to fail.
You need to replace hook keyword with your theme name. Also add hook functions in module.
YOURTHEMENAME_webform_submission_insert($node, $submission){
// give your code here
}
After you create a new hook, you need to clear the drupal caches.
Go to YOURSITE.com/admin/config/development/performance
And click on "Clear all caches"

Drupal - Load page on hook_cron run

I'm developing a drupal module. I'm using only 2 hooks (hook_menu, hook_cron)
In hook_menu, I create a menu callback that does a certain function.
In hook_cron, the problem resides here. I wanna execute the path I created in hook_menu every time hook_cron runs!
How can I do that?!!!
You can use something like this.
drupal_http_request(url('your/path', array('absolute' => TRUE));
It's however not clear to me why you can't simply call an API function in your cron hook, another page request has quite an overhead.

theme_status_messages() is not firing in my Drupal 6 theme

I have a template.php file with a theme called
themename_status_messages
It's not being called/invoked by my theme.
When I use devel themer info on a test dsm output, I am told the candidate functions are:
theme_messages_alter_status_messages()
themename_messages_alter_status_messages()
I'm not sure why the status_messages() call isn't being called during page load. Any ideas?
Looks like the problem was there was a module enabled that changed how this was handled, and I didn't know the module was there and did that. The module was Messages Alter. Taught me a good less on in check the modules page for mysteries.
On your page.tpl.php, is there a $messages var being printing on the page anywhere?
A better way to see if $messages are being passed to your theme is to use a THEME_preprocess_page(&$vars) function in template.php:
function THEME_preprocess_page(&$vars) {
dpm($vars);
// or use $dpr($vars) for a textual array printout
// Replace 'THEME' in the function name with the name of your theme.
}

Drupal: where can I get the $content Array in my theme?

I need to modify the node content Array before it is rendered into html.
For this reason I cannot use the $content variable in my node template. I'm looking for it in template.php file, but I cannot find it.
thanks
AFAIK, you can not access the unrendered node content array from within a theme, as the theme processing occurs to late in the processing cycle (i.e. the content array will already be rendered as you observed).
The standard way to access and modify the node content array before it gets rendered would be to implement hook_nodeapi() within a custom module, reacting to the 'view' operation. This gets invoked after the content array has been assembled, but before it gets rendered, allowing you to adjust it at will.
Be aware that other modules might do this as well - if that is the case and you want to adjust values provided by other modules, the call order of the modules becomes relevant and you might need to adjust your modules weight to ensure it gets called after the others.
Original function that generates variables available to the node is: http://api.drupal.org/api/function/template_preprocess_node/6
You can modify template variables by implementing your own node preprocess function inside template.php that will execute after original function therefore allowing you to add your own variables:
function phptemplate_preprocess_node(&$vars, $hook) {
// Here you can add your custom variable...
$vars['myContent'] = "something";
}

Resources