contact_storage_test.module 1.49 KB
Newer Older
1 2 3 4 5 6 7
<?php

/**
 * @file
 * Contains custom contact message functionality for ContactStorageTest.
 */

8
use Drupal\Core\Field\BaseFieldDefinition;
9 10 11 12 13 14 15

/**
 * Implements hook_entity_base_field_info().
 */
function contact_storage_test_entity_base_field_info(\Drupal\Core\Entity\EntityTypeInterface $entity_type) {
  if ($entity_type->id() == 'contact_message') {
    $fields = array();
16
    $fields['id'] = BaseFieldDefinition::create('integer')
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
      ->setLabel(t('Message ID'))
      ->setDescription(t('The message ID.'))
      ->setReadOnly(TRUE)
      // Explicitly set this to 'contact' so that
      // ContentEntityDatabaseStorage::usesDedicatedTable() doesn't attempt to
      // put the ID in a dedicated table.
      // @todo Remove when https://www.drupal.org/node/1498720 is in.
      ->setProvider('contact')
      ->setSetting('unsigned', TRUE);

    return $fields;
  }
}


/**
 * Implements hook_entity_type_alter().
 */
function contact_storage_test_entity_type_alter(array &$entity_types) {
  /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
  // Set the controller class for nodes to an alternate implementation of the
  // Drupal\Core\Entity\EntityStorageInterface interface.
  $entity_types['contact_message']->setStorageClass('\Drupal\Core\Entity\ContentEntityDatabaseStorage');
  $keys = $entity_types['contact_message']->getKeys();
  $keys['id'] = 'id';
  $entity_types['contact_message']->set('entity_keys', $keys);
  $entity_types['contact_message']->set('base_table', 'contact_message');
}