You are here

function ccl_local_actions_form_ccl_add_form_alter in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl_local_actions/ccl_local_actions.module \ccl_local_actions_form_ccl_add_form_alter()

Implements hook_form_FORM_ID_alter().

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

File

ccl_local_actions/ccl_local_actions.module, line 12
Adds the ability to create local tasks with CCL.

Code

function ccl_local_actions_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']['local_actions'] = t('Local Action');
  $form['options_group']['la_title'] = array(
    '#type' => 'item',
    '#title' => t('Visibility settings'),
    '#states' => array(
      'visible' => array(
        ':input[name="ccl_type"]' => array(
          'value' => 'local_actions',
        ),
      ),
    ),
  );

  // Visibility settings.
  $form['options_group']['la'] = array(
    '#type' => 'container',
    '#states' => array(
      'visible' => array(
        ':input[name="ccl_type"]' => array(
          'value' => 'local_actions',
        ),
      ),
    ),
  );
  $form['options_group']['la']['#attached']['library'][] = array(
    'system',
    'ui.accordion',
  );
  $form['options_group']['la']['#attached']['js'][] = array(
    'data' => '(function($){$(function() { $("#edit-la").accordion({autoHeight: false, navigation: true});})})(jQuery);',
    'type' => 'inline',
  );

  // Per-path visibility.
  $form['options_group']['la']['page_title'] = array(
    '#markup' => '<h5><a href="#">' . t('Pages') . '</a></h5>',
  );
  $options = array(
    0 => t('All pages except those listed'),
    1 => t('Only the listed pages'),
  );
  $form['options_group']['la']['la_visibility'] = array(
    '#type' => 'radios',
    '#title' => t('Show link on specific pages'),
    '#options' => $options,
    '#default_value' => $clid && isset($link->options['la_visibility']) ? $link->options['la_visibility'] : 1,
    '#prefix' => '<div>',
  );
  $form['options_group']['la']['la_pages'] = array(
    '#type' => 'textarea',
    '#default_value' => $clid && isset($link->options['la_pages']) ? $link->options['la_pages'] : '',
    '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
      '%blog' => 'blog',
      '%blog-wildcard' => 'blog/*',
      '%front' => '<front>',
    )),
    '#suffix' => '</div>',
  );
  $form['options_group']['la']['ct_title'] = array(
    '#markup' => '<h5><a href="#">' . t('Content Types') . '</a></h5>',
  );
  $form['options_group']['la']['la_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Show link for specific content types'),
    '#default_value' => $clid && isset($link->options['la_types']) ? $link->options['la_types'] : array(),
    '#options' => node_type_get_names(),
    '#description' => t('Show this link only on pages that display content of the given type(s). If you select no types, there will be no type-specific limitation.'),
    '#prefix' => '<div>',
    '#suffix' => '</div>',
  );

  // Per-role visibility.
  $role_options = array_map('check_plain', user_roles());
  $form['options_group']['la']['roles_title'] = array(
    '#markup' => '<h5><a href="#">' . t('Roles') . '</a></h5>',
  );
  $form['options_group']['la']['la_roles'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Show link for specific roles'),
    '#default_value' => $clid && isset($link->options['la_roles']) ? $link->options['la_roles'] : array(),
    '#options' => $role_options,
    '#description' => t('Show this link only for the selected role(s). If you select no roles, the link will be visible to all users.'),
    '#prefix' => '<div>',
    '#suffix' => '</div>',
  );
}