You are here

function ccl_views_form_ccl_add_form_alter in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl_views/ccl_views.module \ccl_views_form_ccl_add_form_alter()

Implements hook_form_FORM_ID_alter().

Add additional form elements to the main CCL add/edit form.

File

ccl_views/ccl_views.module, line 12
Implements support of views in CCL.

Code

function ccl_views_form_ccl_add_form_alter(&$form, &$form_state, $form_id) {

  // Check if we are in edit mode.
  if (isset($form_state['clid'])) {
    $clid = $form_state['clid'];
    $link = $form_state['link'];
  }
  else {
    $clid = 0;
  }

  // Add blocks as an option for links.
  $form['options_group']['ccl_type']['#options']['view'] = t('View');

  // Follow the naming conventions outlined here in order to avoid
  // naming conflicts.
  if ($clid && isset($link->options['view_options'])) {
    $view_options_default = $link->options['view_options'];
  }
  else {
    $view_options_default = 2;
  }
  $form['options_group']['view_options'] = array(
    '#type' => 'radios',
    '#title' => t('Add this link to:'),
    '#default_value' => $view_options_default,
    '#options' => array(
      t('All views'),
      t('All displays of a view.'),
      t('A specific display of a view.'),
    ),
    '#states' => array(
      'visible' => array(
        ':input[name="ccl_type"]' => array(
          'value' => 'view',
        ),
      ),
    ),
  );
  $options = _ccl_views_get_info();
  $form['options_group']['view_display'] = array(
    '#type' => 'select',
    '#title' => t('Views displays'),
    '#description' => t('Select the views display this link should be added to.'),
    '#options' => $options['displays'],
    '#default_value' => $clid && isset($link->options['view_display']) ? $link->options['view_display'] : -1,
    '#states' => array(
      'visible' => array(
        ':input[name="view_options"]' => array(
          'value' => '2',
        ),
        ':input[name="ccl_type"]' => array(
          'value' => 'view',
        ),
      ),
    ),
  );
  $form['options_group']['view_view'] = array(
    '#type' => 'select',
    '#title' => t('Views'),
    '#description' => t('Select the view this link should be added to.'),
    '#options' => $options['views'],
    '#default_value' => $clid && isset($link->options['view_view']) ? $link->options['view_view'] : -1,
    '#states' => array(
      'visible' => array(
        ':input[name="view_options"]' => array(
          'value' => '1',
        ),
        ':input[name="ccl_type"]' => array(
          'value' => 'view',
        ),
      ),
    ),
  );

  // Add validation for blocks.
  $form['#validate'][] = "ccl_views_validation";
}