You are here

function block_class_form_submit in Block Class 7.2

Same name and namespace in other branches
  1. 6.2 block_class.module \block_class_form_submit()
  2. 6 block_class.module \block_class_form_submit()
  3. 7 block_class.module \block_class_form_submit()

Helper function: additional submit callback for block configuration pages.

Save supplied CSS classes.

1 string reference to 'block_class_form_submit'
block_class_form_alter in ./block_class.module
Implements hook_form_alter().

File

./block_class.module, line 110
Enhanced control over the CSS Classes of any Block.

Code

function block_class_form_submit($form, &$form_state) {

  // Form ids of modules with block creation pages also need to be checked.
  if (in_array($form_state['values']['form_id'], array(
    'block_admin_configure',
    'block_add_block_form',
    'menu_block_add_block_form',
  ))) {

    // Only save if value has changed.
    if (isset($form_state['values']['css_class']) && $form['settings']['css_class']['#default_value'] != $form_state['values']['css_class'] && user_access('administer blocks')) {
      db_update('block')
        ->fields(array(
        'css_class' => $form_state['values']['css_class'],
      ))
        ->condition('module', $form_state['values']['module'])
        ->condition('delta', $form_state['values']['delta'])
        ->execute();

      // Flush all context module cache to use the updated css_class.
      if (module_exists('context')) {
        cache_clear_all('context', 'cache', TRUE);
      }
    }
  }
}