visually_impaired_module.module in Visually Impaired Support (module) 7
Same filename and directory in other branches
Provides version for visually impaired people.
File
visually_impaired_module.moduleView source
<?php
/**
* @file
* Provides version for visually impaired people.
*/
/**
* Implements hook_help().
*/
function visually_impaired_module_help($path, $arg) {
return '';
}
/**
* Implements hook_init().
*/
function visually_impaired_module_init() {
drupal_add_library('system', 'jquery.cookie');
if (path_is_admin(current_path()) && variable_get('visually_impaired_module_selection') == 'default') {
drupal_set_message(t('Please select visually impaired theme in appearance settings'), 'warning');
}
}
/**
* Implements hook_block_info().
*/
function visually_impaired_module_block_info() {
$blocks['visually_impaired_block1'] = [
'info' => t('Visually Impaired block'),
'cache' => DRUPAL_CACHE_PER_ROLE,
];
$blocks['visually_impaired_block2'] = [
'info' => t('Normal version block'),
'cache' => DRUPAL_CACHE_PER_ROLE,
];
return $blocks;
}
/**
* Implements hook_block_configure().
*/
function visually_impaired_module_block_configure($delta = '') {
$form = [];
$active = [
0 => t('Text'),
1 => t('Image'),
];
if ($delta == 'visually_impaired_block1' || $delta == 'visually_impaired_block2') {
$form['block_style'] = [
'#type' => 'radios',
'#title' => t('Block style'),
'#required' => TRUE,
'#options' => $active,
'#default_value' => variable_get($delta . '_block_style', 1),
];
}
return $form;
}
/**
* Implements hook_block_save().
*/
function visually_impaired_module_block_save($delta = '', $edit = []) {
if ($delta == 'visually_impaired_block1' || $delta == 'visually_impaired_block2') {
variable_set($delta . '_block_style', $edit['block_style']);
}
}
/**
* Implements hook_block_view().
*/
function visually_impaired_module_block_view($delta = '') {
$block = [];
switch ($delta) {
case 'visually_impaired_block1':
$block['subject'] = '';
$block['content'] = [
drupal_get_form('visually_impaired_module_create_form1'),
];
break;
case 'visually_impaired_block2':
$block['subject'] = '';
$block['content'] = [
drupal_get_form('visually_impaired_module_create_form2'),
];
break;
}
return $block;
}
/**
* Create button for Visually Impaired Block.
*/
function visually_impaired_module_create_form1($form, &$form_state) {
$classes = [];
variable_get('visually_impaired_block1_block_style', 1) ? $classes[] = 'vi-special-block-image' : ($classes[] = 'vi-special-block-text');
$form['visually_impaired-block'] = [
'#type' => 'submit',
'#submit' => [
'visually_impaired_module_submission_handler1',
],
'#attributes' => [
'itemprop' => 'copy',
'class' => $classes,
],
'#value' => t('Visually impaired site version'),
];
return $form;
}
/**
* Create button for Normal Block.
*/
function visually_impaired_module_create_form2($form, &$form_state) {
$classes = [];
variable_get('visually_impaired_block2_block_style', 1) ? $classes[] = 'vi-normal-block-image' : ($classes[] = 'vi-normal-block-text');
$form['visually_impaired-normal-block'] = [
'#type' => 'submit',
'#attributes' => [
'class' => $classes,
],
'#value' => t('Normal site version'),
'#submit' => [
'visually_impaired_module_submission_handler2',
],
];
return $form;
}
/**
* Visually Impaired Block Button Submit.
*/
function visually_impaired_module_submission_handler1() {
setcookie('visually_impaired', 'on', 0, '/');
cache_clear_all();
}
/**
* Normal Block Button Submit.
*/
function visually_impaired_module_submission_handler2() {
setcookie('visually_impaired', 'off', 0, '/');
cache_clear_all();
}
/**
* Alter the system theme settings form to add the VI theme settings.
*/
function visually_impaired_module_form_system_theme_settings_alter(&$form, $form_state, $form_id) {
if ($form['var']['#value'] == 'theme_settings') {
$form['visually_impaired_module'] = [
'#type' => 'fieldset',
'#prefix' => '<div class="theme-settings-right">',
'#suffix' => '</div>',
'#title' => t('Please select visually impaired theme'),
'#description' => '',
'#weight' => -4,
];
$themes = [
'default' => t('Default'),
];
$options = list_themes();
foreach ($options as $name => $attr) {
if ($attr->status) {
$themes[$name] = $attr->info['name'];
}
}
$form['visually_impaired_module']['visually_impaired_module_selection'] = [
'#type' => 'select',
'#title' => '',
'#description' => '',
'#options' => $themes,
'#default_value' => variable_get('visually_impaired_module_selection', 'default'),
];
$form['#submit'][] = 'visually_impaired_module_settings_submit';
}
}
/**
* Submit handler on the theme settings to save the visually_impaired theme.
*/
function visually_impaired_module_settings_submit($form, $form_state) {
if (isset($form_state['values']['visually_impaired_module_selection'])) {
variable_set('visually_impaired_module_selection', $form_state['values']['visually_impaired_module_selection']);
}
}
/**
* Implements hook_custom_theme().
*/
function visually_impaired_module_custom_theme() {
if (arg(0) == 'admin') {
return variable_get('admin_theme');
}
elseif (isset($_COOKIE['visually_impaired']) && $_COOKIE['visually_impaired'] == 'on') {
return variable_get('visually_impaired_module_selection', 'default');
}
}