entity_test.install

Install, update and uninstall functions for the entity_test module.

File

drupal/core/modules/system/tests/modules/entity_test/entity_test.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the entity_test module.
 */

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

  // Auto-create a field for testing.
  $field = array(
    'field_name' => 'field_test_text',
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => FALSE,
  );
  field_create_field($field);
  $entity_types = array(
    'entity_test',
    'entity_test_rev',
    'entity_test_mul',
    'entity_test_mulrev',
  );
  foreach ($entity_types as $entity_type) {
    $instance = array(
      'entity_type' => $entity_type,
      'field_name' => 'field_test_text',
      'bundle' => $entity_type,
      'label' => 'Test text-field',
    );
    field_create_instance($instance);
    entity_get_form_display($entity_type, $entity_type, 'default')
      ->setComponent('field_test_text', array(
      'type' => 'text_text',
    ))
      ->save();
  }
}

/**
 * Implements hook_schema().
 */
function entity_test_schema() {

  // Schema for simple entity.
  $schema['entity_test'] = array(
    'description' => 'Stores entity_test items.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique entity-test item ID.',
      ),
      'uuid' => array(
        'description' => 'Unique Key: Universally unique identifier for this entity.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'type' => array(
        'description' => 'The bundle of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of the original variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The name of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'user_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'The {users}.uid of the associated user.',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'uuid' => array(
        'uuid',
      ),
    ),
  );

  // Schema for entity with revisions.
  $schema['entity_test_rev'] = array(
    'description' => 'Stores entity_test_rev items.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique entity-test item ID.',
      ),
      'revision_id' => array(
        'description' => 'The current {entity_test_rev_property_revision}.revision_id version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uuid' => array(
        'description' => 'Unique Key: Universally unique identifier for this entity.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'type' => array(
        'description' => 'The bundle of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of the original variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The name of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'uuid' => array(
        'uuid',
      ),
    ),
  );
  $schema['entity_test_rev_revision'] = array(
    'description' => 'Stores entity_test_rev item property revisions.',
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The {entity_test_rev}.id of the test entity.',
      ),
      'revision_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The primary identifier for this version.',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of this variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'name' => array(
        'description' => 'The name of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'user_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'The {users}.uid of the associated user.',
      ),
    ),
    'indexes' => array(
      'user_id' => array(
        'user_id',
      ),
    ),
    'foreign keys' => array(
      'user_id' => array(
        'users' => 'uid',
      ),
      'id' => array(
        'entity_test_rev' => 'id',
      ),
    ),
    'primary key' => array(
      'revision_id',
      'id',
      'langcode',
    ),
  );

  // Schema for entity with data table.
  $schema['entity_test_mul'] = array(
    'description' => 'Stores entity_test_mul items.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique entity-test item ID.',
      ),
      'uuid' => array(
        'description' => 'Unique Key: Universally unique identifier for this entity.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'type' => array(
        'description' => 'The bundle of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of the original variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'uuid' => array(
        'uuid',
      ),
    ),
  );
  $schema['entity_test_mul_property_data'] = array(
    'description' => 'Stores entity_test_mul item properties.',
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The {entity_test_mul}.id of the test entity.',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of this variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'default_langcode' => array(
        'description' => 'Boolean indicating whether the current variant is in the original entity language.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'name' => array(
        'description' => 'The name of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => FALSE,
      ),
      'user_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'The {users}.uid of the associated user.',
      ),
    ),
    'indexes' => array(
      'user_id' => array(
        'user_id',
      ),
    ),
    'foreign keys' => array(
      'user_id' => array(
        'users' => 'uid',
      ),
      'id' => array(
        'entity_test_mul' => 'id',
      ),
    ),
    'primary key' => array(
      'id',
      'langcode',
    ),
  );

  // Schema for entity with data table and revisions.
  $schema['entity_test_mulrev'] = array(
    'description' => 'Stores entity_test_mulrev items.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Primary Key: Unique entity-test item ID.',
      ),
      'revision_id' => array(
        'description' => 'The current {entity_test_mulrev_property_revision}.revision_id version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'uuid' => array(
        'description' => 'Unique Key: Universally unique identifier for this entity.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => FALSE,
      ),
      'type' => array(
        'description' => 'The bundle of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of the original variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'id',
    ),
    'unique keys' => array(
      'uuid' => array(
        'uuid',
      ),
    ),
  );
  $schema['entity_test_mulrev_property_data'] = array(
    'description' => 'Stores entity_test_mulrev item properties.',
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The {entity_test_mulrev}.id of the test entity.',
      ),
      'revision_id' => array(
        'description' => 'The current {entity_test_mulrev_property_revision}.revision_id version identifier.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of this variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'default_langcode' => array(
        'description' => 'Boolean indicating whether the current variant is in the original entity language.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'name' => array(
        'description' => 'The name of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'user_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'The {users}.uid of the associated user.',
      ),
    ),
    'indexes' => array(
      'user_id' => array(
        'user_id',
      ),
    ),
    'foreign keys' => array(
      'user_id' => array(
        'users' => 'uid',
      ),
      'id' => array(
        'entity_test_mulrev' => 'id',
      ),
    ),
    'primary key' => array(
      'id',
      'langcode',
    ),
  );
  $schema['entity_test_mulrev_property_revision'] = array(
    'description' => 'Stores entity_test_mulrev item property revisions.',
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The {entity_test_mulrev}.id of the test entity.',
      ),
      'revision_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'The primary identifier for this version.',
      ),
      'langcode' => array(
        'description' => 'The {language}.langcode of this variant of this test entity.',
        'type' => 'varchar',
        'length' => 12,
        'not null' => TRUE,
        'default' => '',
      ),
      'default_langcode' => array(
        'description' => 'Boolean indicating whether the current variant is in the original entity language.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 1,
      ),
      'name' => array(
        'description' => 'The name of the test entity.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'user_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'The {users}.uid of the associated user.',
      ),
    ),
    'indexes' => array(
      'user_id' => array(
        'user_id',
      ),
    ),
    'foreign keys' => array(
      'user_id' => array(
        'users' => 'uid',
      ),
      'id' => array(
        'entity_test_mulrev' => 'id',
      ),
    ),
    'primary key' => array(
      'revision_id',
      'id',
      'langcode',
    ),
  );
  return $schema;
}

Functions

Namesort descending Description
entity_test_install Implements hook_install().
entity_test_schema Implements hook_schema().