You are here

function block_token_form_alter in Block Token 7

Implements hook_form_alter().

Alter block edit form to add configuration field.

File

./block_token.module, line 180
The file contains Block Token module code.

Code

function block_token_form_alter(&$form, &$form_state, $form_id) {
  if (user_access('administer block token') && ('block_admin_configure' == $form_id || 'block_add_block_form' == $form_id)) {
    $block = block_load($form['module']['#value'], $form['delta']['#value']);
    $form['settings']['block_token'] = array(
      '#type' => 'checkbox',
      '#title' => t('Create the token for this block'),
      '#description' => t('Token string is not available until the block is saved.'),
      '#default_value' => isset($block->block_token) ? $block->block_token : '',
    );
    if (!is_null($block->delta)) {
      $token = block_token_token_name($block->module, $block->delta);
      $form['settings']['block_token']['#description'] = t('Token will be @token', array(
        '@token' => sprintf('[block_token:%s]', $token),
      ));
    }
    $form['#submit'][] = 'block_token_form_submit';
  }
}