home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (pathauto.install)

This example Drupal source code file (pathauto.install) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

0/feed, _pattern, as, foreach, function, if, like, name, pattern, php, sql, variable, vid, where

The pathauto.install Drupal example source code

<?php
// $Id: pathauto.install,v 1.30 2011/01/11 19:55:39 davereid Exp $

/**
 * @file
 * Install, update, and uninstall functions for Pathauto.
 *
 * @ingroup pathauto
 */

/**
 * Implements hook_install().
 */
function pathauto_install() {
  // Set some default variables necessary for the module to perform.
  variable_set('pathauto_node_pattern', 'content/[node:title]');
  variable_set('pathauto_taxonomy_term_pattern', '[term:vocabulary]/[term:name]');
  variable_set('pathauto_forum_pattern', '[term:vocabulary]/[term:name]');
  variable_set('pathauto_user_pattern', 'users/[user:name]');
  variable_set('pathauto_blog_pattern', 'blogs/[user:name]');

  // Set the default separator character to replace instead of remove (default).
  variable_set('pathauto_punctuation_hyphen', 1);

  // Set the weight to 1
  db_update('system')
    ->fields(array('weight' => 1))
    ->condition('type', 'module')
    ->condition('name', 'pathauto')
    ->execute();
}

/**
 * Implements hook_uninstall().
 */
function pathauto_uninstall() {
  // Delete all the pathauto variables and then clear the variable cache
  db_query("DELETE FROM {variable} WHERE name LIKE 'pathauto_%'");
  cache_clear_all('variables', 'cache');
}

/**
 * Remove the unsupported user/%/contact and user/%/tracker pattern variables.
 */
function pathauto_update_6200() {
  variable_del('pathauto_contact_bulkupdate');
  variable_del('pathauto_contact_pattern');
  variable_del('pathauto_contact_supportsfeeds');
  variable_del('pathauto_contact_applytofeeds');
  variable_del('pathauto_tracker_bulkupdate');
  variable_del('pathauto_tracker_pattern');
  variable_del('pathauto_tracker_supportsfeeds');
  variable_del('pathauto_tracker_applytofeeds');
}

/**
 * Empty update since it is handled by pathauto_update_7000().
 */
function pathauto_update_6201() {
}

/**
 * Remove obsolete variables since batch API is now used.
 */
function pathauto_update_7000() {
  variable_del('pathauto_max_bulk_update');
  variable_del('pathauto_node_bulkupdate');
  variable_del('pathauto_taxonomy_bulkupdate');
  variable_del('pathauto_forum_bulkupdate');
  variable_del('pathauto_user_bulkupdate');
  variable_del('pathauto_blog_bulkupdate');
  variable_del('pathauto_modulelist');
  variable_del('pathauto_indexaliases');
  variable_del('pathauto_indexaliases_bulkupdate');
}

/**
 * Taxonomy and forum feed suffixes changed from '0\/feed' to 'feed'.
 */
function pathauto_update_7001() {
  if (variable_get('pathauto_taxonomy_applytofeeds', '') == '0/feed') {
    variable_set('pathauto_taxonomy_applytofeeds', 'feed');
  }
  if (variable_get('pathauto_forum_applytofeeds', '') == '0/feed') {
    variable_set('pathauto_forum_applytofeeds', 'feed');
  }
}

/**
 * Update pathauto_taxonomy_[vid]_pattern variables to pathauto_taxonomy_[machinename]_pattern.
 */
function pathauto_update_7002() {
  if (module_exists('taxonomy')) {
    $vocabularies = taxonomy_get_vocabularies();
    foreach ($vocabularies as $vid => $vocabulary) {
      if ($vid == variable_get('forum_nav_vocabulary', '')) {
        // Skip the forum vocabulary.
        continue;
      }
      if ($pattern = variable_get('pathauto_taxonomy_' . $vid . '_pattern', '')) {
        variable_set('pathauto_taxonomy_' . $vocabulary->machine_name . '_pattern', $pattern);
      }
      variable_del('pathauto_taxonomy_' . $vid . '_pattern');
    }
  }
}

/**
 * Rename 'taxonomy' variables to use the entity type 'taxonomy_term'.
 */
function pathauto_update_7003() {
  $variables = db_query("SELECT name FROM {variable} WHERE name LIKE :pattern AND name NOT LIKE :pattern2", array(':pattern' => db_like("pathauto_taxonomy_") . '%', ':pattern2' => db_like("pathauto_taxonomy_term_") . '%'))->fetchCol();
  foreach ($variables as $variable) {
    $value = variable_get($variable);
    variable_del($variable);
    $variable = strtr($variable, array('pathauto_taxonomy_' => 'pathauto_taxonomy_term_'));
    variable_set($variable, $value);
  }
}

/**
 * Remove obsolete variables for removed feed handling.
 */
function pathauto_update_7004() {
  variable_del('pathauto_node_supportsfeeds');
  variable_del('pathauto_node_applytofeeds');
  variable_del('pathauto_taxonomy_supportsfeeds');
  variable_del('pathauto_taxonomy_applytofeeds');
  variable_del('pathauto_forum_supportsfeeds');
  variable_del('pathauto_forum_applytofeeds');
  variable_del('pathauto_user_supportsfeeds');
  variable_del('pathauto_user_applytofeeds');
  variable_del('pathauto_blog_supportsfeeds');
  variable_del('pathauto_blog_applytofeeds');
}

/**
 * Build a list of Drupal 6 tokens and their Drupal 7 token names.
 */
function _pathauto_upgrade_token_list() {
  $tokens = array(
    //'catpath' => 'node:term-lowest:parent:path][node:term-lowest',
    //'catalias' => 'node:term-lowest:path',
    'termpath' => 'term:parent:path][term:name',
    'termalias' => 'term:path',
    'bookpathalias' => 'node:book:parent:path',
  );
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal pathauto.install source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.