You are here

function panopoly_admin_form_alter in Panopoly 7

Implementation of hook_form_alter()

File

modules/panopoly/panopoly_admin/panopoly_admin.module, line 147

Code

function panopoly_admin_form_alter(&$form, &$form_state, $form_id) {
  global $base_url;

  // Improve the title field
  if (isset($form['title']['#title'])) {
    $form['title']['#title_display'] = 'invisible';
    $form['title']['#attributes']['placeholder'] = $form['title']['#title'];
  }

  // Improve the node edit form
  if (isset($form['#entity_type']) && $form['#entity_type'] == 'node') {

    // Improve the URL selection form
    if (isset($form['path']) && isset($form['path']['alias'])) {
      unset($form['path']['#type']);

      // remove the fieldset
      unset($form['path']['alias']['#description']);
      $form['path']['alias']['#title'] = '<strong>' . t('Permalink') . ':</strong> ';
      $form['path']['alias']['#field_prefix'] = $base_url . '/';
      if (isset($form['path']['pathauto'])) {
        $form['path']['pathauto']['#access'] = FALSE;

        // Alter the place holder text based on the pathauto default value.
        $form['path']['alias']['#attributes'] = array(
          'placeholder' => '<' . t('magically generated') . '>',
        );
        $form['path']['alias']['#states'] = array();
        $form['#submit'][] = 'panopoly_admin_pathauto_submit';
      }
    }

    // Add clearfix to node body container to prevent clearing issue with
    // vertical tabs - @see https://drupal.org/node/1686500
    if (isset($form['body']['#type']) && $form['body']['#type'] == 'container') {
      $form['body']['#attributes']['class'][] = 'clearfix';
    }

    // Hide the body label if it's 'Body' (which isn't terribly helpful) and the
    // field is required.
    if (!empty($form['body'][LANGUAGE_NONE][0]['#required']) && $form['body'][LANGUAGE_NONE][0]['#title'] == t('Body')) {
      if ($form['body'][LANGUAGE_NONE][0]['summary']['#type'] == 'textarea') {

        // We can't just set '#title_display' to invisible because it'll break
        // the summary Javascript. So, we just set a class which we'll use in
        // our own Javascript to hide the label.
        $form['body']['#attributes']['class'][] = 'panopoly-admin-hide-body-label';
      }
      else {
        $form['body'][LANGUAGE_NONE][0]['#title_display'] = 'invisible';
      }
    }

    // Improve the publishing options by remove promote to front page and sticky
    if (isset($form['options']) && !variable_get('panopoly_admin_front_page_and_sticky', 0)) {
      $form['options']['promote']['#access'] = FALSE;
      $form['options']['sticky']['#access'] = FALSE;
    }

    // Improve authoring options
    if (isset($form['author'])) {
      unset($form['author']['name']['#description']);
      $form['author']['name']['#title'] = t('Author');
      $form['author']['name']['#size'] = '40';
      $form['author']['name']['#weight'] = 4;
      $form['author']['date']['#weight'] = 5;

      // Adjust options for Date Popup Module
      if (module_exists('date_popup_authored')) {
        $form['author']['date']['#title_display'] = 'invisible';
        $form['author']['date']['#size'] = 20;
      }
    }
  }

  // Improve and potentially hide the machine name option from Default Content
  if (isset($form['machine_name_fs'])) {
    $form['options']['machine_name_fs']['machine_name'] = $form['machine_name_fs']['machine_name'];
    $form['options']['machine_name_fs']['machine_name']['#size'] = '';
    $form['options']['machine_name_fs']['#weight'] = 30;
    $form['options']['machine_name_fs']['#access'] = variable_get('panopoly_admin_machine_name', FALSE);
    unset($form['options']['machine_name_fs']['machine_name']['#description']);
    unset($form['machine_name_fs']);
  }

  // Move the featured field into publishing options
  if (!empty($form['field_featured_status']) && $form['options']['#access']) {
    $form['options']['field_featured_status'] = $form['field_featured_status'];
    $form['field_featured_status'] = array(
      '#language' => $form['options']['field_featured_status']['#language'],
    );
  }

  // Remove the description from the featured image
  if (!empty($form['field_featured_image'])) {
    $form['field_featured_image'][LANGUAGE_NONE][0]['#title_display'] = 'invisible';
  }
  if (!empty($form['field_featured_categories']) && $form['field_featured_categories'][LANGUAGE_NONE]['#type'] != 'textfield') {
    $form['field_featured_categories'][LANGUAGE_NONE]['#title_display'] = 'invisible';

    // Hide the featured category field if there are no featured category options
    if (count($form['field_featured_categories'][LANGUAGE_NONE]['#options']) == 0 || !empty($form['field_featured_categories'][LANGUAGE_NONE]['#options']['_none']) && count($form['field_featured_categories'][LANGUAGE_NONE]['#options']) == 1) {
      $form['field_featured_categories']['#access'] = FALSE;
    }
  }

  // Improve the revision interface
  if (!empty($form['revision_information']['revision']['#access'])) {
    $form['revision_information']['log']['#states'] = array(
      'visible' => array(
        'input[name="revision"]' => array(
          'checked' => TRUE,
        ),
      ),
    );
    $form['revision_information']['log']['#weight'] = 10;
    $form['revision_information']['log']['#title_display'] = 'invisible';
    $form['revision_information']['revision']['#weight'] = 9;
    $form['options']['revision'] = $form['revision_information']['revision'];
    $form['options']['log'] = $form['revision_information']['log'];
    unset($form['revision_information']['#type']);
    unset($form['revision_information']['log']);
    unset($form['revision_information']['revision']);
  }

  // Improve the menu adding experience
  if (isset($form['menu']) && isset($form['menu']['enabled']) && !empty($form['menu']['#access'])) {
    $form['menu']['link']['link_title']['#size'] = '';
    $form['menu']['link']['weight']['#access'] = FALSE;
    $form['menu']['link']['link_title']['#title'] = t('Link title');
    $form['menu']['link']['parent']['#title'] = t('Parent');
    $form['menu']['link']['description']['#access'] = variable_get('panopoly_admin_link_description', FALSE);
    $form['#validate'][] = 'panopoly_admin_menu_validate';
  }
}