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
<?php
/**
* @file
*
* Provide an administrator interface for adding SEO text & images for specific page
*
* DrupalD <DrupalD@twitter>
*/
/**
* Implementation of hook_menu
*
* DrupalD <DrupalD@twitter>
*/
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 <DrupalD@twitter>
*/
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 = '<div class="global">'. drupal_render($am__overview);
$output .= '<div class="summary">'. _get_config_summary() .'</div>';
return $output;
}
/**
* seo_util_global_text
*
* DrupalD <DrupalD@twitter>
*/
function seo_util_global_text() {
$form['global_text'] = array(
'#type' => 'textarea',
'#title' => t('Global text'),
'#description' => t('Set the text for all pages. This will be overwritten
by the individual page text. You can use PHP code within @php.
You will need to enable PHP filter module to do this.',
array('@php' => 'lt;?php ?gt;')),
'#default_value' => variable_get('global_text', ''),
'#weight' => -50,
);
return system_settings_form($form);
}
/**
* seo_util_config
*
* Select the vocabulary for which text to be added
*
* DrupalD <DrupalD@twitter>
*/
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(
'#type' => 'select',
'#title' => t('Province Vocabulary'),
'#description' => t('Select a vocabulary which provides a list of
provice & cities'),
'#options' => $am__vocab,
'#required' => TRUE,
'#default_value' => variable_get('seo_util_province_vocabulary',00),
'#weight' => -10,
);
$form['seo_util_course_vocabulary'] = array(
'#type' => 'select',
'#title' => t('Course Vocabulary'),
'#description' => t('Select a vocabulary which provides a list of courses'),
'#options' => $am__vocab,
'#required' => TRUE,
'#default_value' => variable_get('seo_util_course_vocabulary',00),
'#weight' => -9,
);
$form['seo_util_theme_regions'] = array(
'#type' => 'select',
'#title' => t('Theme regions'),
'#description' => t('Select the region where you want to display the
text for each of the pages/path') .'<br />'.
t('The regions are listed from your default theme. Your default
theme is @theme.', array('@theme' => variable_get('theme_default', ''))),
'#options' => system_region_list(variable_get('theme_default', '')),
'#required' => TRUE,
'#default_value' => variable_get('seo_util_theme_regions', ''),
);
return system_settings_form($form);
}
/**
* Implementation of hook_page_build
*
* @param $page
* DrupalD <DrupalD@twitter>
*/
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']['#markup'] = php_eval($ss__global_text);
}
/**
* _get_config_summary
*
* DrupalD <DrupalD@twitter>
*/
function _get_config_summary() {
$output = '<h2>'. t('Configuration summary') .'</h2>';
$output .= '<ul>';
$output .= '<li>'. t('Province/City taxonomy')
.': <strong>'. _get_vocabulary(variable_get('seo_util_province_vocabulary', '--')) .'</strong></li>';
$output .= '<li>'. t('Course taxonomy')
.': <strong>'. _get_vocabulary(variable_get('seo_util_course_vocabulary', '--')) .'</strong></li>';
$output .= '<li>'. t('Default theme region') .': <strong>'.
variable_get('seo_util_theme_regions', '--') .'</strong></li>';
$output .= '<li>'. t('Default theme') .': <strong>'.
variable_get('theme_default', '--') .'</strong></li>';
$output .= '</ul>';
$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 ...
* @param unknown_type $sn__vid
* DrupalD <DrupalD@twitter>
*/
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;
}
?>
Info file details
name = SEO Custom utility
description = SEO custom Utility module.
core = 7.x