function block_titlelink_form_alter in Block Title Link 6.2
Same name and namespace in other branches
- 8 block_titlelink.module \block_titlelink_form_alter()
- 6 block_titlelink.module \block_titlelink_form_alter()
- 7 block_titlelink.module \block_titlelink_form_alter()
Implementation of hook_form_alter
File
- ./
block_titlelink.module, line 26 - module for adding a link to a block title
Code
function block_titlelink_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'block_admin_configure' || $form_id == 'block_add_block_form') {
$block = new stdClass();
$block->module = $form['module']['#value'];
$block->delta = $form['delta']['#value'];
$titlelink_data = _block_titlelink_get_data($block);
$url = isset($titlelink_data['url']) ? $titlelink_data['url'] : NULL;
$title = isset($titlelink_data['title']) ? $titlelink_data['title'] : NULL;
$targets = drupal_map_assoc(array(
'_blank',
'_self',
'_parent',
'_top',
));
$target = isset($titlelink_data['target']) ? $titlelink_data['target'] : NULL;
$display_link = isset($titlelink_data['display']) ? $titlelink_data['display'] : TRUE;
$form['block_titlelink'] = array(
'#type' => 'fieldset',
'#title' => t('Block Title Link Settings'),
'#collapsible' => TRUE,
'#weight' => 0,
'#tree' => TRUE,
);
$form['block_titlelink']['title_link'] = array(
'#type' => 'textfield',
'#title' => t('Title Path'),
'#default_value' => $url,
'#description' => t('URL path of Block Title. Tokens are supported if the <a href="@token-module" target="_blank">token module</a> is enabled.', array(
'@token-module' => url("http://drupal.org/project/token"),
)),
'#maxlength' => '255',
);
$form['block_titlelink']['title_link_title'] = array(
'#type' => 'textfield',
'#title' => t('Title Attribute'),
'#description' => t('value for the <a> title attribute.'),
'#default_value' => $title,
);
$form['block_titlelink']['title_link_target'] = array(
'#type' => 'select',
'#title' => t('Link Target'),
'#options' => $targets,
'#empty_value' => '',
'#description' => t('Add a target to open the link in a new tab/window'),
'#default_value' => $target,
);
$form['block_titlelink']['display_link'] = array(
'#type' => 'checkbox',
'#title' => t('Display Link'),
'#description' => t('Select this option if title should render as a link. If deselected, the title path value is stored within the block object as $block->title_link but is not rendered. This is useful if you wish to use the link elsewhere in the block template (ex: as an icon).'),
'#default_value' => $display_link,
);
// Provide Token Help
$value = function_exists('token_replace') ? theme('token_tree', array(
'user',
), TRUE, TRUE) : t('Tokens are supported if the <a href="@token-module">token module</a> is enabled.', array(
'@token-module' => url("http://drupal.org/project/token"),
));
$form['block_titlelink']['token_help'] = array(
'#type' => 'item',
'#value' => $value,
);
// Assign weight to block title so it appears above link
if (!isset($form['block_settings']['#weight'])) {
$form['block_settings']['#weight'] = -1;
}
$form['#validate'][] = 'block_titlelink_form_validate';
$form['#submit'][] = 'block_titlelink_form_submit';
}
}