You are here

taxonomy_facets.inc in Taxonomy Facets 7.3

Same filename and directory in other branches
  1. 7.2 taxonomy_facets.inc

Taxo Faceted Navigation module administration screens.

File

taxonomy_facets.inc
View source
<?php

/**
 * @file
 * Taxo Faceted Navigation module administration screens.
 */

/**
 * Provides admin page.
 *
 * @param array $form
 *   Admin form.
 * @param array $form_state
 *   Admin form.
 *
 * @return array
 *   returns admin form
 */
function taxonomy_facets_admin_settings(array $form, array &$form_state) {
  $form['taxonomy_facets_first_argument'] = array(
    '#type' => 'textfield',
    '#title' => t('First argument'),
    '#size' => 60,
    '#maxlength' => 250,
    '#default_value' => variable_get('taxonomy_facets_first_argument', 'items_list'),
    '#required' => TRUE,
    '#description' => t('First argument in the url, this is necessary for the working of this module. For example, for an ecommerce site the argument could be "products", so the URL would look something like http://yoursite.com/products/hardware/monitors. Cannot be null. Be careful not to use name produced by Token/Pathauto used to generate clean url.s'),
  );

  // ************ Display text about showing sub nodes ****.
  $form['show_subnodes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Show nodes associated with children terms.'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['show_subnodes']['show_subnodes_text'] = array(
    '#markup' => 'If you use a hierarchy of terms, for example:   Computers -> Desktop -> Workstation and if you associate the node with a bottom level term,
    say "Workstation", then the node will not appear when you click on a parent filter, say "Computers" or "Desktop".  To show a node in this case you need to associate the node with <strong>all</strong> of the parents of the child term as well i.e. all 3 terms from the example hierarchy,
    that would be Computers, Desktop and Workstation.  To be able to do that, when you create your node definition and when you add a "Term Reference" field,
    make sure you set "Number of values" to unlimited. Then when an editor creates a node they need to select the terms from all levels in the hierarchy, i.e. 
    Computers, Desktop and Workstation. Optionally you can install the  <a href="https://www.drupal.org/project/multiselect" target="_blank">Multiselect module</a>
    to make it easier for editors to select multiple terms.',
  );
  $form['show_subnodes']['taxonomy_facets_show_subnodes_checkbox'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show warning on node save.'),
    '#default_value' => variable_get('taxonomy_facets_show_subnodes_checkbox', FALSE),
    '#description' => t('If a node is associated with a child term, and you wish the node to appear when user selects parent filter, then make sure you associate the
     node with all appropriate terms as described above. When this checkbox is checked a warning will appear if the node is not associated correctly with all parent
     terms in the hierarchy.'),
  );

  // ************************************************************************.
  $form['taxonomy_facets_display_link_if_empty'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not display link if empty'),
    '#default_value' => variable_get('taxonomy_facets_display_link_if_empty', FALSE),
    '#description' => t('If there are no nodes under particular link, do not display it.'),
  );
  $form['taxonomy_facets_display_link_if_intersection_empty'] = array(
    '#type' => 'checkbox',
    '#title' => t('Do not display link if the intersection of terms is empty'),
    '#default_value' => variable_get('taxonomy_facets_display_link_if_intersection_empty', FALSE),
    '#description' => t('Do not display link if there are no nodes under particular link, but also taking into account current filter selection: i.e if there are no nodes for current filter combination. Works well only for flat hierarchies, i.e. single level hierarchy'),
  );
  $form['taxonomy_facets_redirect_to_home'] = array(
    '#type' => 'checkbox',
    '#title' => t('Redirect to page if no filters applied'),
    '#default_value' => variable_get('taxonomy_facets_redirect_to_home', FALSE),
    '#description' => t('If no arguments passed as filters, i.e if all filters deselected, then redirect to home page. If this checkbox is checked and the field below is empty redirect to home page. If this check box is unchecked all nodes will appear, this is similar behavior as on sitename.com/node page.'),
  );
  $form['taxonomy_facets_redirect_to_page'] = array(
    '#type' => 'textfield',
    '#title' => t('Redirect to a page if no filters applied'),
    '#default_value' => variable_get('taxonomy_facets_redirect_to_page', FALSE),
    '#description' => t('If no arguments passed as filters, i.e if all filters deselected, redirect to a specified page. NOTE: Make sure to check the "Redirect to page..." check box above and specify the page url in this field. If you want to redirect to the home page just leave this field empty.'),
  );
  $form['taxonomy_facets_ignore_language_prefix'] = array(
    '#type' => 'checkbox',
    '#title' => t('Ignore language prefix'),
    '#default_value' => variable_get('taxonomy_facets_ignore_language_prefix', FALSE),
    '#description' => t('If you check this box, the setting will force filters links to stay unchanged and language independent, so <strong>no</strong> language prefix will be added in the url.'),
  );

  // ******* Display text about configuring taxonomy paterns *****************.
  $form['set_taxo_patterns'] = array(
    '#type' => 'fieldset',
    '#title' => t('Set taxonomy patterns'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['set_taxo_patterns']['set_taxo_patterns_text'] = array(
    '#markup' => ' Go to:  <br>
       Administration > Configuration > Search and metadata > URL aliases > <a href="/admin/config/search/path/patterns">Patterns</a>
       <br>
       In the TAXONOMY TERM PATHS section configure term patterns, change it to
       single argument. <br>For example change default pattern:
       [term:vocabulary]/[term:name] to [term:name].<br>
       You can use [term:vocabulary]-[term:name] or similar, the key is NOT to have
       any / character in the pattern, as this module expects a single argument for
                each filter.<br><br>
              If you already have taxonomy term aliases generated with a different pattern then update them:<br>
        * <a href="/admin/config/search/path/delete_bulk"> Delete aliases for taxonomy terms.</a><br>
        * <a href="/admin/config/search/path/update_bulk">Bulk update taxonomy term paths</a><br>.
        ',
  );

  // **************************** Select content type ***********************.
  $form['content_types'] = array(
    '#type' => 'fieldset',
    '#title' => t('Select content types'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['content_types']['taxonomy_facets_content_type_options'] = array(
    '#type' => 'checkboxes',
    '#options' => taxo_faceted_get_node_types(),
    '#default_value' => variable_get('taxonomy_facets_content_type_options', array()),
    '#title' => t('What content types should be displayed on taxonomy facets listing page,
    i.e the page that you specified in the "First argument" field above?'),
  );

  // ********** Display text about adding taxo facets block  *****************.
  $form['set_taxo_block'] = array(
    '#type' => 'fieldset',
    '#title' => t('Add taxonomy faceted navigation blocks'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['set_taxo_block']['set_taxo_block_text'] = array(
    '#markup' => ' Go to:  <br>
      Administration > Structure > <a href="/admin/structure/block">Blocks</a>
      <br>
      Click on <a href="/admin/structure/block/add-taxofacet-block">"Add taxofacet block"</a>
      <br>Select desired taxonomy.
      <br>In the visibility settings set desired options. For example: if your "First argument" is "items_list" then
      in the  "Show block on specific pages"
      <br>
      Click on "Only the listed pages" radio button
      <br>
      and set it to: items_list*
      <br>.
      ',
  );

  // **************** Display text about theming  ****************************.
  $form['set_taxo_theme'] = array(
    '#type' => 'fieldset',
    '#title' => t('Theme templates'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['set_taxo_theme']['set_taxo_theme_text'] = array(
    '#markup' => t('There are 4 templates that you can use to theme your filter blocks. Simply copy all the files from the templates folder, that resides inside this module, into your theme template folder.'),
  );
  return system_settings_form($form);
}

/**
 * Validate the configuration form.
 */
function taxonomy_facets_admin_settings_validate($form, &$form_state) {

  // Get first argument as entered by user.
  $first_arg = $form_state['values']['taxonomy_facets_first_argument'];

  // Query menu router table and see if this argument has been already used.
  $duplicate_menu_item = taxonomy_facets_firstarg_exsists_in_menu_router($first_arg);
  if ($duplicate_menu_item) {
    form_set_error('taxonomy_facets_first_argument', t('The keyword @first_arg can not be used as the first argument. It has already been used in the first element of the following menu path(s): <br /> @duplicate_menu_item .
       </br> Please either rename this item or go to the Clean URLs page and rename the existing item, or examine the router page to see which item is causing the problem.', array(
      '@first_arg' => $first_arg,
      '@duplicate_menu_item' => $duplicate_menu_item,
    )));
  }
  else {
    global $base_url;
    $link = l(t('this page to clear the cache'), check_plain($base_url) . '/admin/config/development/performance');
    drupal_set_message(t('Value saved, please clear all caches now or you may get unexpected results. Go to: !link', array(
      '!link' => $link,
    )), 'warning');
  }
}

/**
 * Check the menu_router, url_alias table and see if the keyword exsits.
 */
function taxonomy_facets_firstarg_exsists_in_menu_router($first_arg) {
  $duplicate_path = NULL;

  // Check the menu_router table.
  $query = db_select('menu_router', 'mr');
  $or = db_or()
    ->condition('mr.path', $first_arg . '/%', 'LIKE')
    ->condition('mr.path', $first_arg);
  $query
    ->condition($or)
    ->fields('mr', array(
    'path',
    'page_callback',
  ))
    ->range(0, 50);
  $result = $query
    ->execute();
  foreach ($result as $row) {

    // If path produced by this module ignore.
    if ($row->page_callback != 'taxonomy_facets_print_landing_page') {
      $duplicate_path .= $row->path . '<br />';
    }
  }

  // Check url_alias table, alias field.
  $query = db_select('url_alias', 'ua');
  $or = db_or()
    ->condition('ua.alias', $first_arg . '/%', 'LIKE')
    ->condition('ua.alias', $first_arg);
  $query
    ->condition($or)
    ->fields('ua', array(
    'alias',
  ))
    ->range(0, 50);
  $result = $query
    ->execute();
  foreach ($result as $row) {
    $duplicate_path .= $row->alias . '<br />';
  }

  // Check url_alias table, source field.
  $query = db_select('url_alias', 'ua');
  $or = db_or()
    ->condition('ua.source', $first_arg . '/%', 'LIKE')
    ->condition('ua.source', $first_arg);
  $query
    ->condition($or)
    ->fields('ua', array(
    'source',
  ))
    ->range(0, 50);
  $result = $query
    ->execute();
  foreach ($result as $row) {
    $duplicate_path .= $row->source . '<br />';
  }
  return $duplicate_path;
}

Functions

Namesort descending Description
taxonomy_facets_admin_settings Provides admin page.
taxonomy_facets_admin_settings_validate Validate the configuration form.
taxonomy_facets_firstarg_exsists_in_menu_router Check the menu_router, url_alias table and see if the keyword exsits.