You are here

cssoverrider.inc in Node displays 6

Plugin to override css inline.

File

plugins/cssoverrider.inc
View source
<?php

/**
 * @file
 * Plugin to override css inline.
 */

/**
 * Implementation of nd_pluginname_form().
 */
function nd_cssoverrider_form(&$form, $nd_display_settings) {
  $form['cssoverrider'] = array(
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#title' => t('CSS overrider'),
    '#description' => t('Either add extra classes or override CSS inline per region.'),
  );
  $build_mode = $form['#build_mode'];
  $regions = nd_regions();
  foreach ($regions as $region => $title) {
    if ($region != 'disabled') {
      $form['cssoverrider']['region-class-' . $region] = array(
        '#title' => $title . ' class',
        '#type' => 'textfield',
        '#description' => t('Enter extra classes, seperated by comma.'),
        '#default_value' => nd_default_value($nd_display_settings, $build_mode, 'cssoverrider', 'class', $region, ''),
      );
      $form['cssoverrider']['region-inline-' . $region] = array(
        '#title' => $title . ' inline css',
        '#type' => 'textfield',
        '#description' => t('Enter inline css. Note, you only need to enter the css rules, the plugin will add style="" for you.'),
        '#default_value' => nd_default_value($nd_display_settings, $build_mode, 'cssoverrider', 'inline', $region, ''),
      );
    }
  }
}

/**
 * Implementation of nd_pluginname_submit().
 */
function nd_cssoverrider_submit($form, $form_state, &$nd_display_settings) {
  $regions = nd_regions();
  $css_save = array();
  $build_mode = $form['#build_mode'];
  foreach ($regions as $region => $title) {
    $css_save['class'][$region] = $form_state['values']['cssoverrider']['region-class-' . $region];
    $css_save['inline'][$region] = $form_state['values']['cssoverrider']['region-inline-' . $region];
  }
  $nd_display_settings[$build_mode]['cssoverrider'] = $css_save;
}

/**
 * Implementation of nd_pluginname_process().
 */
function nd_cssoverrider_process(&$vars, &$node_display, $nd_display_settings) {
  foreach ($node_display->themed_regions as $region_name => $region_data) {
    $classes = nd_default_value($nd_display_settings, $vars['node']->build_mode, 'cssoverrider', 'class', $region_name, '');
    $inline = nd_default_value($nd_display_settings, $vars['node']->build_mode, 'cssoverrider', 'inline', $region_name, '');
    if (!empty($classes)) {
      $node_display->themed_regions[$region_name]['extra_class'] = ' ' . $classes;
    }
    if (!empty($inline)) {
      $node_display->themed_regions[$region_name]['inline_css'] = 'style="' . $inline . '"';
    }
  }
}

Functions

Namesort descending Description
nd_cssoverrider_form Implementation of nd_pluginname_form().
nd_cssoverrider_process Implementation of nd_pluginname_process().
nd_cssoverrider_submit Implementation of nd_pluginname_submit().