-
Notifications
You must be signed in to change notification settings - Fork 2
How to add a block to an App
baisong edited this page Mar 7, 2013
·
4 revisions
Sometimes, you might want your custom App to contain a single instance of a block, pre-created when the user enables your app.
A box is a kind of "block factory", that allows a site to create many instances of a single type. In contrast, a each block you add following these instructions will provide a single, pre-created instance in each vsite's available widgets layout page in CP > Build > Layout.
<?php
/**
* Implements hook_block_info().
*/
function mymodule_block_info() {
$blocks = array();
$blocks['myblock'] = array(
'info' => t('My block'),
'weight' => '-10',
);
return $blocks;
}
<?php
/**
* Implements hook_block_view().
*/
function mymodule_block_view($delta) {
$block = array();
switch ($delta) {
case 'myblock':
$block['content'] = mymodule_myblock_block_content();
break;
}
return $block;
}
<?php
/**
* Implements hook_os_widget().
*/
function mymodule_os_widget() {
$widgets = array();
$widgets['mymodule-myblock'] = array(
'module' => 'mymodule',
'delta' => 'myblock',
'title' => '',
'info' => t('My block'),
);
return $widgets;
}
That's it! Once your app is enabled on this vsite, the block will become available in the Layout.