Drupal: Set content in a region programmatically

This CodeLet will allow you to set some text in a region you specify from configuration page. The regions are from the current theme. The desired content will be displayed in the region when the page is rendered.

CodeLet: 

/**
*
*
* Provide an administrator interface for adding SEO text & images for specific page
*
* DrupalD
*/

/**
* Implementation of hook_menu
*
* DrupalD
*/
function seo_util_menu() {
$item['admin/config/development/seo-util'] = array(
'type' => MENU_NORMAL_ITEM,
'title' => t('SEO text'),
'page callback' => 'seo_util_overview',
'access arguments' => array('Administer site configuration')
);

$item['admin/config/development/seo-util/manage'] = array(
'type' => MENU_DEFAULT_LOCAL_TASK,
'title' => t('Manage text'),
'page callback' => 'seo_util_overview',
'access arguments' => array('Administer site configuration'),
'weight' => -10,
);

$item['admin/config/development/seo-util/config'] = array(
'type' => MENU_LOCAL_TASK,
'title' => t('Settings'),
'page callback' => 'drupal_get_form',
'page arguments' => array('seo_util_config'),
'access arguments' => array('Administer site configuration'),
'weight' => -7,
);

return $item;
}

/**
* seo_util_overview
*
* Display SEO text overview
*
* DrupalD
*/
function seo_util_overview() {
drupal_add_css(drupal_get_path('module', 'seo_util') .'/seo_util.css');
$am__overview = drupal_get_form('seo_util_global_text');
$output = '

'. drupal_render($am__overview);
$output .= '
'. _get_config_summary() .'

';
return $output;

}

/**
* seo_util_global_text
*
* DrupalD
*/
function seo_util_global_text() {
$form['global_text'] = array(
'' => 'textarea',
'' => t('Global text'),
'' => t('Set the text for all pages. This will be overwritten
by the individual page text. You can use PHP code within .
You will need to enable PHP filter module to do this.',
array('' => '')),
'' => variable_get('global_text', ''),
'' => -50,
);

return system_settings_form($form);
}

/**
* seo_util_config
*
* Select the vocabulary for which text to be added
*
* DrupalD
*/
function seo_util_config() {
$am__vocabulary = taxonomy_vocabulary_get_names();
$am__vocab = array();
$am__vocab[0] = t('-- Select --');
foreach ($am__vocabulary as $vocabulary => $ob) {
$am__vocab[$ob->vid] = $ob->name;
}

$form['seo_util_province_vocabulary'] = array(
'' => 'select',
'' => t('Province Vocabulary'),
'' => t('Select a vocabulary which provides a list of
provice & cities'),
'' => $am__vocab,
'' => TRUE,
'' => variable_get('seo_util_province_vocabulary',00),
'' => -10,
);

$form['seo_util_course_vocabulary'] = array(
'' => 'select',
'' => t('Course Vocabulary'),
'' => t('Select a vocabulary which provides a list of courses'),
'' => $am__vocab,
'' => TRUE,
'' => variable_get('seo_util_course_vocabulary',00),
'' => -9,
);

$form['seo_util_theme_regions'] = array(
'' => 'select',
'' => t('Theme regions'),
'' => t('Select the region where you want to display the
text for each of the pages/path') .'
'.
t('The regions are listed from your default theme. Your default
theme is .', array('' => variable_get('theme_default', ''))),
'' => system_region_list(variable_get('theme_default', '')),
'' => TRUE,
'' => variable_get('seo_util_theme_regions', ''),
);

return system_settings_form($form);
}

/**
* Implementation of hook_page_build
*
* $page
* DrupalD
*/
function seo_util_page_build(&$page) {
$ss__global_text = variable_get('global_text', '');
$ss__region = variable_get('seo_util_theme_regions', '');
$page[$ss__region]['text'][''] = php_eval($ss__global_text);
}

/**
* _get_config_summary
*
* DrupalD
*/
function _get_config_summary() {
$output = '

'. t('Configuration summary') .'

';

$output .= '

    ';
    $output .= '
  • '. t('Province/City taxonomy')
    .': '. _get_vocabulary(variable_get('seo_util_province_vocabulary', '--')) .'
  • ';
    $output .= '

  • '. t('Course taxonomy')
    .': '. _get_vocabulary(variable_get('seo_util_course_vocabulary', '--')) .'
  • ';
    $output .= '

  • '. t('Default theme region') .': '.
    variable_get('seo_util_theme_regions', '--') .'
  • ';
    $output .= '

  • '. t('Default theme') .': '.
    variable_get('theme_default', '--') .'
  • ';
    $output .= '

';
$output .= t('You can change above configuration from !config page',
array('!config' => l(t('Settings'), 'admin/config/development/seo-util/config')));
return $output;
}

/**
* _get_vocabulary
*
* Enter description here ...
* unknown_type $sn__vid
* DrupalD
*/
function _get_vocabulary($sn__vid) {
$names = db_query('SELECT name FROM {taxonomy_vocabulary} WHERE vid = :vid',
array(':vid' => $sn__vid))->fetchAllAssoc('name');
$names = array_values($names);

return $names[0]->name;
}
?>

Is CodeLet useful?: 

Compatibility:

Image: 
Drupal: Set content in a region programmatically | Configuration
Info file details: 

name = SEO Custom utility
description = SEO custom Utility module.
core = 7.x