The use of #ajax attribute in the Drupal Form API is limited to a certain set of form elements. But what if you want to use a link to trigger your AJAX instead? It may be possible using the Drupal AJAX framework, but you'll need to figure out a way to pass the $form_state without breaking your form. There is a workaround that will allow you to use the AJAX built into the Form API with links or any other element.
Here's a useful snippet if you want to add an "Unblock selected users" operation to Views Bulk Operations (VBO). All you need to do is create a new Rules component. To make things simple, just import the following in Rules components:
So you've come across a scenerio where you need to give users special access to nodes, but the collection of content access control modules available on drupal.org don't quite meet your need. Then you my friend need to build your own solution.
I found myself in the same boat, so I thought I'd share some of the articles that really helped me grasp custom node access.
If you've ever created a block with hook_block_info you know that the visibility options are limited to just pages. In my case, I wanted to set my block to only appear on certain node types. The challenge is that you can't do it from hook_block_info because node type visibility isn't dictated by the block module, it's provided by the node module.
But fear not, there is a way! If you want to add content type based visibility for your block, you can do so in the .install file of your module using hook_install.
If you find yourself needing to manipulate node fields during hook_node_insert or hook_node_update, the best way is to use field_attach_update. Especially, if you need access the node id.
When defining an "access callback" for a menu item in hook_menu, Drupal doesn't provide a callback for restricting access by a user's role. Which seems to be a bit of an oversight. So here's some code run a simple check against the user's role
If you need to include a custom template for a block in your Drupal 7 module, here's how to do it.
Drupal's theme system allows you to provide alternate template files by way of theme hook suggestions. In other words, you can override the output of nodes, pages, blocks, and more by providing your own template file and using the correct naming scheme. For more information on that naming scheme I suggest reading this article on Drupal 7 Theme Hook Suggestions.
If you're looking to preprocess a field in Drupal 7, you can use hook_preprocess_HOOK. The first "hook" is the name of your module. The second "HOOK" is the theme hook you want to preprocess (e.g. theme_node, theme_block, theme_link, theme_field). You can fine an exhustive list of the Drupal theme hooks by searching the Drupal API.
Here is a simple example of how to use it with fields.