You are here

yoast_seo.install in Real-time SEO for Drupal 7

Same filename and directory in other branches
  1. 8.2 yoast_seo.install
  2. 8 yoast_seo.install

Install, update, and uninstall functions for the Yoast SEO for Drupal module.

File

yoast_seo.install
View source
<?php

/**
 * @file
 * Install, update, and uninstall functions for the Yoast SEO for Drupal module.
 */

/**
 * Implements hook_schema().
 */
function yoast_seo_schema() {
  $schema['yoast_seo'] = array(
    'fields' => array(
      'entity_type' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The entity type this data is attached to.',
      ),
      'entity_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The entity id this data is attached to.',
      ),
      'revision_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'The revision_id for the entity object this data is attached to.',
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The language of the entity.',
      ),
      'focus_keyword' => array(
        'description' => 'The focus keyword for this entity.',
        'type' => 'varchar',
        'length' => 512,
        'not null' => FALSE,
      ),
      'seo_status' => array(
        'description' => 'The SEO status in points.',
        'type' => 'float',
        'unsigned' => FALSE,
      ),
    ),
    'indexes' => array(
      'type_revision' => array(
        'entity_type',
        'revision_id',
      ),
    ),
    'primary key' => array(
      'entity_type',
      'entity_id',
      'revision_id',
      'language',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 *
 * @see metatag_install()
 */
function yoast_seo_install() {
  $entity_type = 'node';

  // Always enable the node entity.
  variable_set('yoast_seo_enable_' . $entity_type, TRUE);

  // Update each entity bundle too.
  $entity_info = entity_get_info($entity_type);
  if (!empty($entity_info['bundles'])) {
    foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
      $fields = field_info_instances($entity_type, $bundle_name);
      $variable_name = 'yoast_seo_enable_' . $entity_type . '__' . $bundle_name;

      // Enable Yoast SEO for Drupal when the body field is present.
      if (isset($fields['body'])) {
        variable_set($variable_name, TRUE);
      }
      else {
        variable_set($variable_name, FALSE);
      }
    }
  }
}

/**
 * Implements hook_uninstall().
 */
function yoast_seo_uninstall() {
  $entity_type = 'node';

  // Delete node entity variable.
  variable_del('yoast_seo_enable_' . $entity_type);

  // Also delete the variable for each entity bundle.
  $entity_info = entity_get_info($entity_type);
  if (!empty($entity_info['bundles'])) {
    foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
      variable_del('yoast_seo_enable_' . $entity_type . '__' . $bundle_name);
      variable_del('yoast_seo_body_fields_' . $bundle_name);
    }
  }
}

/**
 * Change yoast_seo field scheme type from 'int' to 'float'.
 */
function yoast_seo_update_7000() {
  db_drop_primary_key('yoast_seo');
  db_change_field('yoast_seo', 'seo_status', 'seo_status', array(
    'type' => 'float',
    'unsigned' => FALSE,
  ));
}

Functions

Namesort descending Description
yoast_seo_install Implements hook_install().
yoast_seo_schema Implements hook_schema().
yoast_seo_uninstall Implements hook_uninstall().
yoast_seo_update_7000 Change yoast_seo field scheme type from 'int' to 'float'.