You are here

function patterns_form_alter in Patterns 6.2

Same name and namespace in other branches
  1. 5 patterns.module \patterns_form_alter()
  2. 6 patterns.module \patterns_form_alter()

File

./patterns.module, line 2099
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function patterns_form_alter(&$form, &$form_state, $form_id) {
  if (user_access('administer patterns') && variable_get('patterns_form_helper', FALSE)) {
    $form['#after_build'][] = 'patterns_form_helper';
  }
  if (patterns_executing()) {

    // Ensure that parent and related dropdowns display all the terms
    // including those created during current pattern execution.
    // Without this, those terms would be omitted due to the static
    // caching within taxonomy_get_tree().
    $form_ids = array(
      'taxonomy_form_term',
    );
    if (in_array($form_id, $form_ids)) {
      $tid = $form['#term']['tid'];
      $vid = $form['#vocabulary']['vid'];
      $parent = array_keys(taxonomy_get_parents($tid));
      $children = _patterns_taxonomy_get_tree($vid, $tid);

      // A term can't be the child of itself, nor of its children.
      foreach ($children as $child) {
        $exclude[] = $child->tid;
      }
      $exclude[] = $tid;
      $form['advanced']['parent'] = _patterns_taxonomy_term_select(t('Parents'), 'parent', $parent, $vid, t('Parent terms') . '.', 1, '<' . t('root') . '>', $exclude);
      $form['advanced']['relations'] = _patterns_taxonomy_term_select(t('Related terms'), 'relations', array_keys(taxonomy_get_related($tid)), $vid, NULL, 1, '<' . t('none') . '>', array(
        $tid,
      ));
    }

    // Ensure that parent item dropdown displays all the menu items
    // including those created during current pattern execution.
    // Without this, those menu items would be omitted due to the
    // static caching within menu_tree_all_data().
    $form_ids = array(
      'menu_edit_item',
    );
    if (in_array($form_id, $form_ids)) {
      if (empty($form['menu']['#item'])) {
        $item = array(
          'link_title' => '',
          'mlid' => 0,
          'plid' => 0,
          'menu_name' => $form_state['values']['menu']['menu_name'],
          'weight' => 0,
          'link_path' => '',
          'options' => array(),
          'module' => 'menu',
          'expanded' => 0,
          'hidden' => 0,
          'has_children' => 0,
        );
      }
      else {
        $item = $form['menu']['#item'];
      }
      $form['menu']['parent']['#options'] = _patterns_menu_parent_options(menu_get_menus(), $item);
    }

    // Ensure that taxonomy dropdowns on node edit form display all the terms
    // including those created during current pattern execution.
    if (!empty($form['taxonomy']) && isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
      foreach ($form['taxonomy'] as $vid => $v) {
        if (!is_numeric($vid)) {
          continue;
        }
        $form['taxonomy'][$vid] = _patterns_taxonomy_form($vid, $form['taxonomy'][$vid]['#default_value'], $form['taxonomy'][$vid]['#description']);
      }
    }
  }
}