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

Drupal example source code file (page_title.install)

This example Drupal source code file (page_title.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

array, default, delete, foreach, function, id, not, null, page_title, php, ret, true, type, variable_del

The page_title.install Drupal example source code

<?php
// $Id: page_title.install,v 1.10.4.4 2009/06/17 15:03:07 njt1982 Exp $

/**
 * @file
 * The install file for Page Title allows the module to install (and uninstall) itself. This is required as this module uses its own table.
 */

/**
 * Implementation of hook_install().
 */
function page_title_install() {
  drupal_install_schema('page_title');
}


/**
 * Implementation of hook_schema().
 */
function page_title_schema() {
  $schema['page_title'] = array(
    'fields' => array(
      'type'       => array('type' => 'varchar', 'length' => 15,  'not null' => TRUE, 'default' => 'node'),
      'id'         => array('type' => 'int', 'unsigned' => TRUE,  'not null' => TRUE, 'default' => 0),
      'page_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
    ),
    'primary key' => array('type', 'id'),
  );

  return $schema;
}


/**
 * Implementation of hook_update_n().
 */
function page_title_update_6200() {
  $ret = array();

  if (db_column_exists('page_title', 'id')) {
    return $ret;
  }

  db_create_table($ret, 'page_title_temp', array(
    'fields' => array(
      'type'       => array('type' => 'varchar', 'length' => 15,  'not null' => TRUE, 'default' => 'node'),
      'id'         => array('type' => 'int', 'unsigned' => TRUE,  'not null' => TRUE, 'default' => 0),
      'page_title' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '')
    ),
    'primary key' => array('type', 'id'),
  ));

  $ret[] = update_sql('INSERT INTO {page_title_temp} (id, page_title) SELECT nid, page_title FROM {page_title}');

  db_rename_table($ret, 'page_title', 'page_title_old');

  db_rename_table($ret, 'page_title_temp', 'page_title');

  $display_settings = variable_get('page_title_display', array());
  foreach ($display_settings as $type) {
    if ($type) {
      variable_set('page_title_type_'. $type .'_showfield', 1);
    }
  }
  variable_del('page_title_display');

  return $ret;
}


/**
 * Implementation of hook_uninstall().
 */
function page_title_uninstall() {
  drupal_uninstall_schema('page_title');

  // Clear variables
  variable_del('page_title_default');
  variable_del('page_title_individual');
  variable_del('page_title_front');
  variable_del('page_title_blog');
  variable_del('page_title_user');
  variable_del('page_title_user_showfield');
  variable_del('page_title_pager_pattern');

  // Clear the node specific variables
  $types = node_get_types('names');
  foreach ($types as $type => $name) {
    variable_del("page_title_type_{$type}");
    variable_del("page_title_type_{$type}_showfield");
  }

  // Clear the vocab specific variables
  $vocabs = taxonomy_get_vocabularies();
  foreach ($vocabs as $vid => $vocab) {
    variable_del("page_title_vocab_{$vid}");
    variable_del("page_title_vocab_{$vid}_showfield");
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal page_title.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.