You are here

field_test.entity.inc in Zircon Profile 8

Same filename and directory in other branches
  1. 8.0 core/modules/field/tests/modules/field_test/field_test.entity.inc

Defines an entity type.

File

core/modules/field/tests/modules/field_test/field_test.entity.inc
View source
<?php

/**
 * @file
 * Defines an entity type.
 */

/**
 * Implements hook_entity_type_alter().
 */
function field_test_entity_type_alter(array &$entity_types) {

  /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
  foreach (field_test_entity_info_translatable() as $entity_type => $translatable) {
    $entity_types[$entity_type]
      ->set('translatable', $translatable);
  }
}

/**
 * Helper function to enable entity translations.
 */
function field_test_entity_info_translatable($entity_type_id = NULL, $translatable = NULL) {
  $stored_value =& drupal_static(__FUNCTION__, array());
  if (isset($entity_type_id)) {
    $entity_manager = \Drupal::entityManager();
    $original = $entity_manager
      ->getDefinition($entity_type_id);
    $stored_value[$entity_type_id] = $translatable;
    if ($translatable != $original
      ->isTranslatable()) {
      $entity_manager
        ->clearCachedDefinitions();
      $entity_type = $entity_manager
        ->getDefinition($entity_type_id);
      $entity_manager
        ->onEntityTypeUpdate($entity_type, $original);
    }
  }
  return $stored_value;
}

Functions

Namesort descending Description
field_test_entity_info_translatable Helper function to enable entity translations.
field_test_entity_type_alter Implements hook_entity_type_alter().