You are here

function override_css_selector_value in Override css 7

Set values of css properties

3 string references to 'override_css_selector_value'
override_css_menu in ./override_css.module
Implements hook_menu().
override_css_settings_form_alter in override_css_settings/override_css_settings.module
Implements hook_form_alter().
override_css_settings_menu in override_css_settings/override_css_settings.module
Implements hook_menu().

File

./override_css.admin.inc, line 42

Code

function override_css_selector_value($form, &$form_state, $selector = array(), $redirect = FALSE) {
  drupal_add_library('system', 'farbtastic');
  $available_properties = override_css_properties_list();
  $properties = array_filter($selector['properties']);
  $form = array();
  $form['description'] = array(
    '#markup' => '<em>' . $selector['description'] . '</em>',
  );
  $form['selector'] = array(
    '#type' => 'value',
    '#value' => $selector['name'],
  );
  $form['redirect'] = array(
    '#type' => 'value',
    '#value' => $redirect,
  );
  foreach ($properties as $property) {
    $fieldset = $property . '_fieldset';
    $form[$fieldset] = array(
      '#type' => 'fieldset',
      '#title' => $available_properties[$property]['title'],
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    switch ($available_properties[$property]['type']) {
      case 'border':
        $form[$fieldset][$property . '_picker'] = array(
          '#markup' => '<div id="' . $available_properties[$property]['name'] . '-picker" style="float: right;"></div>',
          '#weight' => 1,
        );
        $form[$fieldset][$property] = array(
          '#type' => 'textfield',
          '#title' => 'Kleur',
          '#default_value' => isset($selector['properties_values'][$property]) ? $selector['properties_values'][$property] : '#ffffff',
          '#description' => '',
          '#size' => 7,
          '#prefix' => "<script type='text/javascript'>\n            (function (\$) {\n              Drupal.behaviors.override_css_" . $property . " = {\n                attach: function() {\n                  \$('#" . $available_properties[$property]['name'] . "-picker').farbtastic('#edit-" . $available_properties[$property]['name'] . "');\n                }\n              }\n            })(jQuery);\n          </script>",
          '#weight' => 2,
        );
        $form[$fieldset][$property . '_size'] = array(
          '#title' => 'Dikte',
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property . '_size']) ? $selector['properties_values'][$property . '_size'] : 0,
          '#size' => 5,
          '#field_suffix' => 'px',
          '#weight' => 3,
        );
        $border_type = array(
          'solid' => 'Solid',
          'dashed' => 'Dashed',
          'dotted' => 'Dotted',
          'double' => 'Double',
          'groove' => 'Groove',
          'ridge' => 'Ridge',
          'inset' => 'Inset',
          'outset' => 'Outset',
        );
        $form[$fieldset][$property . '_type'] = array(
          '#title' => 'Type',
          '#type' => 'select',
          '#options' => $border_type,
          '#description' => '',
          '#default_value' => isset($selector['properties_values'][$property . '_type']) ? $selector['properties_values'][$property . '_type'] : '',
        );
        break;
      case 'shadow':
        $form[$fieldset][$property . '_horizontal'] = array(
          '#title' => 'Positie horizontaal',
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property . '_horizontal']) ? $selector['properties_values'][$property . '_horizontal'] : 0,
          '#size' => 5,
          '#field_suffix' => 'px',
          '#weight' => 3,
        );
        $form[$fieldset][$property . '_vertical'] = array(
          '#title' => 'Positie verticaal',
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property . '_vertical']) ? $selector['properties_values'][$property . '_vertical'] : 0,
          '#size' => 5,
          '#field_suffix' => 'px',
          '#weight' => 4,
        );
        $form[$fieldset][$property . '_blur'] = array(
          '#title' => 'Blur',
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property . '_blur']) ? $selector['properties_values'][$property . '_blur'] : 0,
          '#size' => 5,
          '#field_suffix' => 'px',
          '#weight' => 5,
        );
        $form[$fieldset][$property . '_spread'] = array(
          '#title' => 'Grootte',
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property . '_spread']) ? $selector['properties_values'][$property . '_spread'] : 0,
          '#size' => 5,
          '#field_suffix' => 'px',
          '#weight' => 6,
        );
        $direction = array(
          '' => 'Naar buiten',
          'inset' => 'Naar binnen',
        );
        $form[$fieldset][$property . '_direction'] = array(
          '#title' => 'Binnen- of buitenkant',
          '#type' => 'select',
          '#options' => $direction,
          '#description' => '',
          '#default_value' => isset($selector['properties_values'][$property . '_direction']) ? $selector['properties_values'][$property . '_direction'] : '',
          '#weight' => 7,
        );
      case 'background-color':
        $form[$fieldset][$property . '_opacity'] = array(
          '#title' => 'Percentage doorzichtbaarheid',
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property . '_opacity']) ? $selector['properties_values'][$property . '_opacity'] : 0,
          '#size' => 5,
          '#field_suffix' => '%',
          '#weight' => 3,
        );
      case 'color':
        $default = isset($selector['properties_values'][$property]) ? $selector['properties_values'][$property] : '';
        $form[$fieldset][$property . '_container'] = array(
          '#type' => 'container',
        );
        $form[$fieldset][$property . '_container'][$property . '_picker'] = array(
          '#markup' => '<div id="' . $available_properties[$property]['name'] . '-picker" style="float: right;"></div>',
          '#weight' => 1,
        );
        $form[$fieldset][$property] = array(
          '#type' => 'textfield',
          '#title' => 'Kleur',
          '#default_value' => $default == '' ? '#ffffff' : $default,
          '#description' => '',
          '#size' => 7,
          '#prefix' => "<script type='text/javascript'>\n            (function (\$) {\n              Drupal.behaviors.override_css_" . $property . " = {\n                attach: function() {\n                  \$('#" . $available_properties[$property]['name'] . "-picker').farbtastic('#edit-" . $available_properties[$property]['name'] . "');\n                }\n              }\n            })(jQuery);\n          </script>",
          '#weight' => 2,
        );
        break;
      case 'size':
      case 'radius':
        $form[$fieldset][$property] = array(
          '#title' => $available_properties[$property]['title'],
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property]) ? $selector['properties_values'][$property] : '',
          '#size' => 5,
          '#field_suffix' => $available_properties[$property]['unit'],
        );
        break;
      case 'image':
        $form[$fieldset][$property] = array(
          '#title' => 'Pad naar huidige afbeelding',
          '#type' => 'textfield',
          '#description' => 'Het pad naar het bestand dat u wilt gebruiken.',
          '#default_value' => isset($selector['properties_values'][$property]) ? $selector['properties_values'][$property] : '',
        );
        $form[$fieldset][$property . '_upload'] = array(
          '#title' => 'Upload nieuwe afbeelding',
          '#type' => 'file',
          '#maxlength' => 40,
          '#description' => 'Gebruik dit veld om een nieuwe afbeelding te uploaden.',
        );
        $position_horizontal = array(
          'left' => 'Links',
          'center' => 'Centreren',
          'right' => 'Rechts',
        );
        $form[$fieldset][$property . '_position_horizontal'] = array(
          '#title' => 'Horizontale positie',
          '#type' => 'select',
          '#options' => $position_horizontal,
          '#description' => '',
          '#default_value' => isset($selector['properties_values'][$property . '_position_horizontal']) ? $selector['properties_values'][$property . '_position_horizontal'] : '',
        );
        $position_vertical = array(
          'top' => 'Bovenkant',
          'center' => 'Centreren',
          'bottom' => 'Onderkant',
        );
        $form[$fieldset][$property . '_position_vertical'] = array(
          '#title' => 'Verticale positie',
          '#type' => 'select',
          '#options' => $position_vertical,
          '#description' => '',
          '#default_value' => isset($selector['properties_values'][$property . '_position_vertical']) ? $selector['properties_values'][$property . '_position_vertical'] : '',
        );
        $attachment = array(
          'scroll' => 'Mee scrollen met pagina',
          'fixed' => 'Gefixeerd tov de pagina',
        );
        $form[$fieldset][$property . '_attachment'] = array(
          '#title' => 'Attachment',
          '#type' => 'select',
          '#options' => $attachment,
          '#description' => '',
          '#default_value' => isset($selector['properties_values'][$property . '_attachment']) ? $selector['properties_values'][$property . '_attachment'] : '',
        );
        $repeat = array(
          'repeat' => 'Herhaal horizontaal en verticaal',
          'repeat-x' => 'Herhaal enkel in horizontale richting',
          'repeat-y' => 'Herhaal enkel in verticale richting',
          'no-repeat' => 'Geen herhaling',
        );
        $form[$fieldset][$property . '_repeat'] = array(
          '#title' => 'Herhaling',
          '#type' => 'select',
          '#options' => $repeat,
          '#description' => '',
          '#default_value' => isset($selector['properties_values'][$property . '_repeat']) ? $selector['properties_values'][$property . '_repeat'] : '',
        );
        $stretch = array(
          'none' => 'Niet',
          'horizontal' => 'Volledige breedte',
          'vertical' => 'Volledige hoogte',
          'both' => 'Volledige hoogte en breedte',
        );
        $form[$fieldset][$property . '_stretch'] = array(
          '#title' => 'Afbeelding uitrekken',
          '#type' => 'select',
          '#options' => $stretch,
          '#description' => '',
          '#default_value' => isset($selector['properties_values'][$property . '_stretch']) ? $selector['properties_values'][$property . '_stretch'] : 'none',
        );
        break;
      case 'font':
        $form[$fieldset][$property] = array(
          '#title' => 'Lettertype',
          '#type' => 'select',
          '#options' => override_css_font_option_list(),
          '#default_value' => isset($selector['properties_values'][$property]) ? $selector['properties_values'][$property] : '',
          '#suffix' => override_css_font_list_preview(),
        );
        break;
      default:
        $form[$fieldset][$property] = array(
          '#title' => $available_properties[$property]['title'],
          '#type' => 'textfield',
          '#default_value' => isset($selector['properties_values'][$property]) ? $selector['properties_values'][$property] : '',
          '#size' => 25,
        );
        break;
    }

    // Add checkbox to reset/disable property
    foreach ($form[$fieldset] as $key => $element) {
      if (is_array($element)) {
        $element['#states'] = array(
          'invisible' => array(
            ':input[name="' . $property . '_disabled"]' => array(
              'checked' => TRUE,
            ),
          ),
        );
      }
      $form[$fieldset][$key] = $element;
    }
    $form[$fieldset][$property . '_disabled'] = array(
      '#type' => 'checkbox',
      '#title' => 'Disable ' . strtolower($available_properties[$property]['title']),
      '#default_value' => isset($selector['properties_values'][$property . '_disabled']) ? $selector['properties_values'][$property . '_disabled'] : 0,
      '#weight' => -100,
    );

    // Integration with sliderfield module (if available)
    if (module_exists('sliderfield')) {
      foreach ($form[$fieldset] as $key => $element) {
        if (is_array($element) && $element['#type'] == 'textfield' && isset($element['#field_suffix'])) {
          $element['#type'] = 'slider';
          switch ($element['#field_suffix']) {
            case 'px':
              $element['#min'] = 0;
              $element['#max'] = 40;
              break;
            case '%':
              $element['#min'] = 0;
              $element['#max'] = 100;
              break;
          }
          $element['#display_inputs'] = FALSE;
          $element['#display_values'] = TRUE;
          $element['#display_values_format'] = '%{value}% ' . $element['#field_suffix'];
          $element['#field_suffix'] = '';
          $element['#slider_length'] = '250px';
        }
        $form[$fieldset][$key] = $element;
      }
    }
  }
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  $form['actions']['cancel'] = array(
    '#type' => 'link',
    '#title' => t('Cancel'),
    '#href' => $redirect ? variable_get('override_css_settings_path', OVERRIDE_CSS_SETTINGS_PATH) : 'admin/appearance/override_css/list/' . $selector['name'],
  );
  return $form;
}