You are here

function icon_block_form_alter in Icon API 7

Same name and namespace in other branches
  1. 8 modules/icon_block/icon_block.module \icon_block_form_alter()

Implements hook_form_alter().

File

modules/icon_block/icon_block.module, line 93
icon_block.module Provides icon integration with blocks.

Code

function icon_block_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'block_admin_configure' || $form_id == 'block_add_block_form') {
    $access = user_access('administer icons') || user_access('administer block icons');
    $block = block_load($form['module']['#value'], $form['delta']['#value']);
    $settings = icon_block_get_settings($block);

    // Add an icon selector input element.
    $form['settings']['icon_selector'] = array(
      '#access' => $access,
      '#type' => 'icon_selector',
      '#default_bundle' => $settings['bundle'],
      '#default_icon' => $settings['icon'],
      '#default_wrapper' => $settings['wrapper'],
      '#default_wrapper_class' => $settings['wrapper_class'],
    );

    // Additional configuration on where to place the icon in the block.
    $form['settings']['icon_selector']['position'] = array(
      '#type' => 'select',
      '#title' => t('Position'),
      '#options' => array(
        'title_before' => t('Before title'),
        'title_after' => t('After title'),
        'title_inside_before' => t('Before title (inside markup)'),
        'title_inside_after' => t('After title (inside markup)'),
        'content_before' => t('Before content'),
        'content_after' => t('After content'),
      ),
      '#default_value' => $settings['position'],
      '#states' => array(
        'invisible' => array(
          _icon_states_selector('icon_selector[icon]') => array(
            'value' => '',
          ),
        ),
      ),
    );
    if ($access) {
      $form['#submit'][] = 'icon_block_form_submit';
    }
  }
}