Some days ago, i write a blog post about how to render a Drupal 7 block programmatically.
Drupal 7 – Render a Block programmatically
If the block is created by Views, there is a simpler solution provided by the Views API. And we can also pass the contextual filter argument too.
print views_embed_view(<view machine name>, <display id>, <arg 1>);
Reference: Outputting a Drupal 7 View programmatically with Contextual Filters (arguments)
Not long a ago, i have 2 posted about rendering Blocks and Views in PHP.
We can render the Drupal 7 block by PHP in another way.
The following piece of code render the Views Exposed Filter.
$view = views_get_view('<view name>');
$display_id = 'page';
$form_state = array(
'view' => $view,
'display' => $view->display_handler->display,
'exposed_form_plugin' => $view->display_handler->get_plugin('exposed_form'),
'method' => 'get',
'rerender' => TRUE,
'no_redirect' => TRUE,
$form = drupal_build_form('views_exposed_form', $form_state);
Sometimes the content types we created are only used in Views. We don’t want to have the node view page for those content. The following solution would turn those unwanted node view pages to 404 not found.
Create a custom module and implement the hook_node_view() as follow.
Sometimes we may want to update multiple nodes at once. Views Bulk Operations may help if you want to set the same value for a field of multiple nodes. But if you want to set different values among a set of nodes, then Views Bulk Operations could not help.
In Drupal 6, the Editview module may help but unfortunately there is no Drupal 7 version. An alternative solution could be done by editablefields module.
1. Download and enable the module. (I used the 7.x-1.x-dev version)
2. Create a view with table format. (This is not necessary but better user interface)
Yesterday we have talked about how to use selection list for selecting Entity reference in Views exposed filter.
Drupal 7 – Selection list for Entity reference in Views exposed filter
Now i want to have more control on the selection list. For example, i have a content type called competition and i want to limit the number of options in the Entity reference selection list. In this case, we have to create a custom module and alter the views_exposed_form.
When you want to set an Entity reference field in Views exposed filter, it only allows free text input filter. But i want to have a selection list instead of a free text input.
Just simply go to the field setting page @ admin/structure/types/manage/<content-type>/fields/<field-name> and check the Render Views filters as select list option. Continue reading
When you have a hierarchy structure of taxonomy, the default selection list is not quite user friendly because it list out all the parent and child terms. Assume with want to attach a country and city terms to the Article content type. The most straight forward way is create one vocabulary with some countries as parent terms and some cities as child terms like the following list.
It turns on that when someone is adding a new article, he may select either a country term or a city term. That is probably not what we want.
I use the Views PHP field to retrieve a numeric value from database, but it could not be sorted even after i have checked the Enable click sort and select Sort numerically.
It will throws an error.
Today i would like share another module about Drupal access permission. It is called Path Access.
With the help of the Empty Page module, i could create any blank templates with different blocks. But unlike Views page, these empty pages do not have access permission settings. Luckily the Path Access module could fill the gap.
If you have enabled the Path Access module, you can configure the forbidden paths for different roles @ admin/config/people/pathaccess.