You are here

function clean_markup_blocks_form_alter in Clean Markup 7.2

Same name and namespace in other branches
  1. 7.3 modules/clean_markup_blocks/clean_markup_blocks.module \clean_markup_blocks_form_alter()
  2. 7 modules/clean_markup_blocks/clean_markup_blocks.module \clean_markup_blocks_form_alter()

Implements hook_form_alter().

File

modules/clean_markup_blocks/clean_markup_blocks.module, line 26
Provides clean block markup.

Code

function clean_markup_blocks_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id === 'block_admin_configure' || $form_id == 'block_add_block_form') {
    if (user_access('administer clean markup block settings')) {

      // Load defaults.
      $defaults = variable_get('clean_markup_blocks-defaults');
      $wrapper_elements = _clean_markup_get_html_wrapper_elements();
      $optional_wrapper_elements = _clean_markup_get_html_wrapper_elements(TRUE);

      // Get settings for this block.
      $variable_name = _clean_markup_blocks_generate_prefix($form['module']['#value'], $form['delta']['#value']);
      $this_block_settings = variable_get($variable_name, $defaults);

      // Set our own submit handler so we can save the settings in our custom
      // part of the form.
      $form['#submit'][] = '_clean_markup_blocks_block_configure_submit';

      // Create our custom part of the form.
      $form['clean_markup'] = array(
        '#type' => 'fieldset',
        '#title' => t('Clean markup options'),
        '#group' => 'visibility',
      );

      // Controls for block markup.
      $form['clean_markup']['block_wrapper'] = array(
        '#type' => 'select',
        '#title' => t('Block wrapper markup'),
        '#description' => t('Choose the HTML element to wrap the block.'),
        '#default_value' => $this_block_settings['block_wrapper'],
        '#options' => $optional_wrapper_elements,
      );
      $form['clean_markup']['additional_block_classes'] = array(
        '#type' => 'textfield',
        '#title' => t('Additional block classes'),
        '#description' => t('Additional classes to set on the block wrapper.'),
        '#default_value' => $this_block_settings['additional_block_classes'],
        '#states' => array(
          'invisible' => array(
            ':input[name="block_wrapper"]' => array(
              'value' => CLEAN_MARKUP_NO_ELEMENT,
            ),
          ),
        ),
      );
      $form['clean_markup']['additional_block_attributes'] = array(
        '#type' => 'textfield',
        '#title' => t('Additional attributes'),
        '#description' => t('Additional attributes to set on the block wrapper (i.e. <code>role="navigation"</code>). Text entered here will not be sanitized.') . '<br />' . t('While this is a powerful and flexible feature if used by a trusted user with HTML experience, it is a security risk in the hands of a malicious or inexperienced user.'),
        '#default_value' => $this_block_settings['additional_block_attributes'],
        '#states' => array(
          'invisible' => array(
            ':input[name="block_wrapper"]' => array(
              'value' => CLEAN_MARKUP_NO_ELEMENT,
            ),
          ),
        ),
      );
      if (module_exists('token')) {
        $form['clean_markup']['token_help'] = array(
          '#title' => t('Replacement patterns'),
          '#type' => 'fieldset',
          '#collapsible' => TRUE,
          '#collapsed' => TRUE,
          '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
          '#states' => array(
            'invisible' => array(
              ':input[name="block_wrapper"]' => array(
                'value' => CLEAN_MARKUP_NO_ELEMENT,
              ),
            ),
          ),
        );
        $form['clean_markup']['token_help']['help'] = array(
          '#value' => theme('token_tree', array(
            'global',
          ), TRUE, TRUE),
        );
        $form['clean_markup']['token_help']['help']['tokens'] = array(
          '#theme' => 'token_tree',
          '#token_types' => array(
            'global',
          ),
          '#global_types' => TRUE,
          '#click_insert' => TRUE,
        );
      }
      $form['clean_markup']['block_html_id_as_class'] = array(
        '#type' => 'checkbox',
        '#title' => t("Output block's HTML ID as class"),
        '#default_value' => $this_block_settings['block_html_id_as_class'],
        '#states' => array(
          'invisible' => array(
            ':input[name="block_wrapper"]' => array(
              'value' => CLEAN_MARKUP_NO_ELEMENT,
            ),
          ),
        ),
      );
      $form['clean_markup']['enable_inner_div'] = array(
        '#type' => 'checkbox',
        '#title' => t('Enable inner div'),
        '#description' => t('Specify if you want an inner div element inside the main block wrapper.'),
        '#default_value' => $this_block_settings['enable_inner_div'],
        '#states' => array(
          'invisible' => array(
            ':input[name="block_wrapper"]' => array(
              'value' => CLEAN_MARKUP_NO_ELEMENT,
            ),
          ),
        ),
      );

      // Controls for title markup.
      $form['clean_markup']['title_wrapper'] = array(
        '#type' => 'select',
        '#title' => t('Title wrapper markup'),
        '#description' => t('Choose the HTML to use to wrap the block title.'),
        '#default_value' => $this_block_settings['title_wrapper'],
        '#options' => $wrapper_elements,
      );
      $form['clean_markup']['title_hide'] = array(
        '#type' => 'checkbox',
        '#title' => t('Visually-hide block title'),
        '#description' => t('Add the <code>element-invisible</code> CSS class to the block title. This hides it visually but leaves it visible to screenreaders.'),
        '#default_value' => $this_block_settings['title_hide'],
      );

      // Controls for content markup.
      $form['clean_markup']['content_wrapper'] = array(
        '#type' => 'select',
        '#title' => t('Content wrapper markup'),
        '#description' => t('Choose the HTML to use to wrap the block content.'),
        '#default_value' => $this_block_settings['content_wrapper'],
        '#options' => $optional_wrapper_elements,
      );
    }
  }
}