You are here

function block_class_styles_form_alter in Block Class Styles 7.2

Same name and namespace in other branches
  1. 7 block_class_styles.module \block_class_styles_form_alter()

Implements hook_form_alter().

Related topics

File

./block_class_styles.module, line 281
Base module file for block_class_styles

Code

function block_class_styles_form_alter(&$form, $form_state, $form_id) {
  $stored_css_class = '';
  if ($form_id === 'bean_form') {
    $bean = $form['#entity'];
    $pform = $form;
    $pform['module'] = array(
      '#value' => 'bean',
    );
    $pform['delta'] = array(
      '#value' => $bean->delta,
    );
    $pform_id = 'block_admin_configure';
    block_class_form_alter($pform, $form_state, $pform_id);
    $stored_css_class = $pform['settings']['css_class']['#default_value'];
  }
  if (in_array($form_id, array(
    'block_admin_configure',
    'block_add_block_form',
  ))) {

    ////    $block->module = $form['module']['#value'];

    ////    $block->delta = $form['delta']['#value'];
    if (!empty($form['settings']['css_class']['#default_value'])) {
      $stored_css_class = $form['settings']['css_class']['#default_value'];
    }
  }

  //
  //
  // Generate the form element to be shared in different forms.
  if (in_array($form_id, array(
    'block_admin_configure',
    'block_add_block_form',
    'bean_form',
  ))) {
    $multiple = FALSE;

    //@todo See admin.inc for explanation

    //$multiple = current(variable_get('block_class_styles_allow_multiple', BLOCK_CLASS_STYLES_ALLOW_MULTIPLE));
    $options = block_class_styles_info();
    $default = array(
      $stored_css_class,
    );

    // If the default is hidden we need to grab it
    if ($stored_css_class && !array_key_exists($stored_css_class, $options)) {

      //      $default_is_hidden = TRUE;
      $hidden = block_class_styles_info(TRUE);
      $options += array_intersect_key($hidden, array_flip($default));
      $options[$stored_css_class] .= ' ***';
    }
    if (!$multiple) {
      $options = array(
        NULL => t('-None-'),
      ) + $options;
      $default = $stored_css_class;
    }
    $element = array(
      '#type' => 'fieldset',
      '#title' => variable_get('block_class_styles_fs_title', BLOCK_CLASS_STYLES_FS_TITLE),
      '#description' => variable_get('block_class_styles_fs_description', BLOCK_CLASS_STYLES_FS_DESCRIPTION),
      '#collapsible' => TRUE,
      '#collapsed' => !variable_get('block_class_styles_form_collapsed', FALSE),
    );
    $element['css_class'] = array(
      '#type' => $multiple ? 'checkboxes' : 'select',
      '#title' => variable_get('block_class_styles_title', BLOCK_CLASS_STYLES_TITLE),
      '#options' => $options,
      '#default_value' => $default,
      '#description' => variable_get('block_class_styles_description', BLOCK_CLASS_STYLES_DESCRIPTION),
      '#maxlength' => 255,
    );
    $element['admin'] = array(
      '#markup' => t('To edit styles <a href="!url">click here</a>.', array(
        '!url' => url(BLOCK_CLASS_STYLES_PATH_SETTINGS, array(
          'query' => drupal_get_destination(),
        )),
      )),
      '#access' => user_access('administer block_class_styles'),
    );
  }

  //
  //
  // Support for normal blocks
  if (in_array($form_id, array(
    'block_admin_configure',
    'block_add_block_form',
  ))) {
    $form['block_class']['#access'] = user_access('block_class_styles:use');
    $form['block_class']['#title'] = variable_get('block_class_styles_fs_title', BLOCK_CLASS_STYLES_FS_TITLE);
    $form['block_class']['#description'] = variable_get('block_class_styles_fs_description', BLOCK_CLASS_STYLES_FS_DESCRIPTION);
    $element['#access'] = $form['block_class']['#access'];
    $element['#weight'] = variable_get('block_class_styles_form_weight', 0);
    $form['block_class_styles'] = $element;

    // This field needs to be hidden because we show it in our own way in our
    // fieldset, and... we can't set #access to FALSE because our variable name
    // is the same, so we have turn it into a non-displaying type = 'value'
    $form['settings']['css_class']['#type'] = 'value';
  }
  elseif ($form_id === 'bean_form') {
    $form['block_class_styles_css_class'] = $element;
    $form['#submit'][] = '_block_class_styles_form_submit';
  }
}