How do I render contextual links for blocks I render in my code?
Solutions
Bart's answer will give a Strict Standards warning (enabled by default in PHP 5.4). To fix this just use an intermediate variable for the renderable array:
$block = block_load('module', 'delta');
$renderable_array = _block_get_renderable_array(_block_render_blocks(array($block)));
print drupal_render($renderable_array);
The reason the warning occurs is because the drupal_render
function expects its parameter to be a reference. It has the signature drupal_render(&$elements)
. For more information see the answer to this similar question.
$block = block_load('module', 'delta');
print drupal_render(_block_get_renderable_array(_block_render_blocks(array($block))));
Too bad we have to use private functions from the block module (_*()) to achieve this.
Contextual links are helpful and really easy to implement.
For your use-case you need to implement hook_block_view_alter()
to change #contextual_links item to suit your needs.
These references will help you out:
- http://drupal.org/documentation/modules/contextual
- http://dominiquedecooman.com/blog/drupal-7-tip-add-contextual-links-anything
GL :)
Does [Cache blocks] in Performance means that blocks generated by Views are also cached?
I am working on an old Drupal 6 project. My goal is to boost the performance of the website as much as I can. Among other things I have done, I have already enabled cache Configuration > Development > Performance My question is, does [Cache blocks] in Performance means that blocks generated by Views are also cached or I have to enable caching insid...
Admin page to show 2 blocks (or page+block) with 1 filter that affects both blocks
I am new to Drupal and would love some guidance on how best to achieve the following: An admin page that has (top-down): - a date selector, defaulting to today's date - a section displaying Arrivals for the date selected (this selects custom content type 'Bookings' with filter of arrivalDate = dateselected) - a section displaying Departures for the...
Create page of blocks only / Create a node of blocks
Sometimes I use a basic page as a place holder for the purpose of creating a node to hold blocks. So I create a basic page and link it to a menu, then I use the blocks interface to configure certain blocks to display on that page only. The problem with this approach is twofold. Firstly I don't need the page, but secondly when a user tries to edit t...