You are here

function panopoly_widgets_form_alter in Panopoly Widgets 7

Implementation of hook_form_alter()

File

./panopoly_widgets.module, line 230

Code

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

  // Simplify the menu block edit form
  if ($form_id == 'menu_block_menu_tree_content_type_edit_form') {
    $form['admin_title']['#access'] = FALSE;
    $form['depth']['#access'] = FALSE;
    $form['display_options']['#default_value'] = 'advanced';
    $form['display_options']['#access'] = FALSE;
    $form['title_link']['#access'] = FALSE;
    $form['buttons']['#prefix'] = '<div class="menu-block-ctools-buttons">';

    // Disable some options since they appear busted or confusing in Menu Block
    $form['sort']['#access'] = FALSE;

    // Add configuration for max expanded depth.
    $form['expanded_max_depth'] = array(
      '#type' => 'select',
      '#title' => t('Maximum expanded depth'),
      '#weight' => 9,
      '#options' => array(
        '1' => t('Only 1 level'),
        '2' => t('Only 2 levels'),
        '3' => t('Only 3 levels'),
        '4' => t('Only 4 levels'),
        '5' => t('Only 5 levels'),
        '6' => t('Only 6 levels'),
        '7' => t('Only 7 levels'),
        '8' => t('Only 8 levels'),
        '9' => t('Only 9 levels'),
        '0' => t('Expand all children'),
      ),
      '#default_value' => isset($form_state['conf']['expanded_max_depth']) ? $form_state['conf']['expanded_max_depth'] : 0,
      '#states' => array(
        'visible' => array(
          ':input[name="expanded"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );

    // Modify the 'expanded' checkbox so it appears right above the max depth
    // and makes sense with that option.
    $form['expanded']['#weight'] = 8;
    $form['expanded']['#title'] = t('<strong>Expand children</strong> of this tree.');

    // Hide the 'Always display title' option that only useful in rare edge
    // cases.
    if (!empty($form['display_empty'])) {
      $form['display_empty']['#access'] = FALSE;
    }
  }
  if ($form_id == 'fieldable_panels_panes_fieldable_panels_pane_content_type_edit_form') {

    // Add fields to the FPP object if we are adding a reusable object for the first time
    if ($form_state['entity']->reusable && $form_state['op'] == 'add') {
      if (fieldable_panels_panes_access('update', $form_state['entity'])) {
        $form = fieldable_panels_panes_entity_edit_form($form, $form_state);
        $form_state['no update entity'] = FALSE;
      }
      else {
        $form['message']['#markup'] = '<p>' . t("You don't have permission to edit this widget.") . '</p>';
        return;
      }
    }

    // Add a custom pre-render method to deal with "Content Settings" fieldset.
    $form['#pre_render'][] = 'panopoly_widgets_fieldable_panel_pane_pre_render';

    // Remove the revisioning information
    $form['revision']['revision']['#type'] = 'value';
    $form['revision']['log']['#access'] = FALSE;

    // Add a widget setting
    $form['widget_settings']['#type'] = 'fieldset';
    $form['widget_settings']['#title'] = t('General Settings');
    $form['title']['#attributes']['placeholder'] = $form['title']['#title'];
    $form['title']['#title_display'] = 'invisible';
    $form['widget_settings']['title'] = $form['title'];

    // If the title hasn't been replaced by the title module then it's safe to
    // unset it. Otherwise it's already been hidden by the title module.
    if (!(module_exists('title') && isset($form['title']['#field_replacement']) && $form['title']['#field_replacement'])) {
      unset($form['title']);
    }

    // Move the link field into the general settings tab.
    $form['widget_settings']['link'] = $form['link'];
    unset($form['link']);

    // Improve the reusable interface
    $form['reusable']['#title'] = t('Reusable Settings');
    $form['reusable']['#type'] = 'fieldset';
    $form['reusable']['#process'] = array(
      'ctools_dependent_process',
    );
    $form['reusable']['#id'] = 'reusable-settings';
    $form['reusable']['category']['#value'] = t('Reusable Content');
    $form['reusable']['category']['#type'] = 'value';
    $form['reusable']['admin_description']['#access'] = FALSE;

    // Set the proper dependencies for the reusable markup
    $form['reusable']['warning']['#dependency'] = array(
      'edit-reusable' => array(
        1,
      ),
    );
    $form['reusable']['warning']['#prefix'] = '<div id="reusable-wrapper">';
    $form['reusable']['warning']['#suffix'] = '</div>';
    $form['reusable']['warning']['#type'] = 'item';

    // Update the text for the reusable markup
    $form['reusable']['warning']['#markup'] = '<div class="description">' . t('Note: This item is reusable! Any changes made will be applied globally.') . '</div>';
  }

  // Improve the usability and functionality of the table field widget
  if (!empty($form['field_basic_table_table'])) {
    $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['import']['#access'] = FALSE;

    // Remove importing from CSV
    $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['#collapsible'] = FALSE;
    $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['#collapsed'] = FALSE;
    $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_cols']['#field_prefix'] = $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_cols']['#title'] . '? ';
    $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_cols']['#title'] = '';
    $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_rows']['#field_prefix'] = $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_rows']['#title'] . '? ';
    $form['field_basic_table_table'][LANGUAGE_NONE][0]['tablefield']['rebuild']['count_rows']['#title'] = '';
  }
}