You are here

globallink_entity.install in GlobalLink Connect for Drupal 7.5

GlobalLink entity translation install file.

File

globallink_entity/globallink_entity.install
View source
<?php

/**
 * @file
 * GlobalLink entity translation install file.
 */

/**
 * Implements hook_schema().
 */
function globallink_entity_schema() {
  $schema = array();
  $schema['globallink_core_entity'] = array(
    'description' => 'GlobalLink Core Entity Table',
    'fields' => array(
      'rid' => array(
        'description' => 'The row ID',
        'type' => 'serial',
        'unsigned' => FALSE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'The node id',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'vid' => array(
        'description' => 'The current {node_revisions}.vid version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'type' => array(
        'description' => 'The {node_type}.type of this node.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'title' => array(
        'description' => 'The title of this node, always treated as non-markup plain text.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'timestamp' => array(
        'description' => 'The timestamp',
        'type' => 'int',
        'length' => 14,
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'source' => array(
        'description' => 'The origin language of the requested translation',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
      ),
      'target' => array(
        'description' => 'The target language of the requested translation',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
      ),
      'status' => array(
        'description' => 'The status of the request',
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => 'Pending Translations',
        'length' => 50,
      ),
      'document_ticket' => array(
        'description' => 'PD Document Ticket Id',
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 50,
      ),
      'submission' => array(
        'description' => 'PD Submission Name',
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 255,
      ),
      'submission_ticket' => array(
        'description' => 'PD Submission Ticket Id',
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 50,
      ),
      'project_code' => array(
        'description' => 'PD Project Code',
        'type' => 'varchar',
        'not null' => TRUE,
        'default' => '',
        'length' => 255,
      ),
      'last_modified' => array(
        'description' => 'Last Modified Date for Source Node',
        'type' => 'int',
        'length' => 14,
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'changed' => array(
        'description' => 'Boolean Flag indicating whether source node has changed',
        'type' => 'int',
        'length' => 1,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'rid',
    ),
    'indexes' => array(
      'status' => array(
        'status',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function globallink_entity_install() {

  /**
   * Insert Entity enabled fields
   */
  $node_types = node_type_get_types();
  foreach ($node_types as $node_type) {
    if (!entity_translation_node_supported_type($node_type->type)) {
      return;
    }
    $field_arr = field_info_instances('node', $node_type->type);
    $keys = array_keys($field_arr);

    // If the field exists in the table, ignore the insert.
    $results = db_select('globallink_field_config', 'tfc')
      ->fields('tfc')
      ->condition('content_type', $node_type->type)
      ->condition('bundle', $node_type->type)
      ->condition('field_name', 'title_field')
      ->execute();
    if ($results
      ->rowCount() == 0) {
      db_insert('globallink_field_config')
        ->fields(array(
        'content_type' => $node_type->type,
        'entity_type' => 'node',
        'bundle' => $node_type->type,
        'field_name' => 'title',
        'field_type' => 'text',
        'field_label' => 'Title',
        'translatable' => 1,
      ))
        ->execute();
    }
    if (module_exists('metatag')) {
      db_insert('globallink_field_config')
        ->fields(array(
        'content_type' => $node_type->type,
        'entity_type' => 'node',
        'bundle' => $node_type->type,
        'field_name' => 'metatags',
        'field_type' => 'text',
        'field_label' => 'Meta tags',
        'translatable' => 1,
      ))
        ->execute();
    }
    foreach ($keys as $field_name) {
      $field = field_info_field($field_name);
      switch ($field['type']) {
        case 'list_boolean':
        case 'image':
        case 'file':
        case 'taxonomy_term_reference':
        case 'list_boolean':
          continue 2;
      }
      $results = db_select('globallink_field_config', 'tfc')
        ->fields('tfc')
        ->condition('content_type', $node_type->type)
        ->condition('bundle', $node_type->type)
        ->condition('field_name', $field_name)
        ->execute();
      if ($results
        ->rowCount() == 0) {
        db_insert('globallink_field_config')
          ->fields(array(
          'content_type' => $node_type->type,
          'entity_type' => 'node',
          'bundle' => $node_type->type,
          'field_name' => $field_name,
          'field_type' => $field['type'],
          'field_label' => $field_arr[$field_name]['label'],
          'translatable' => 1,
        ))
          ->execute();
      }
    }
  }
}

Functions