<?php

/**
 * @file
 * Test module for the entity API providing an entity type for testing.
 */

/**
 * Implements hook_entity_info().
 */
function entity_test_entity_info() {
  $items['entity_test'] = array(
    'label' => t('Test entity'),
    'entity class' => 'Drupal\entity\Entity',
    'controller class' => 'Drupal\entity\EntityDatabaseStorageController',
    'base table' => 'entity_test',
    'fieldable' => TRUE,
    'entity keys' => array(
      'id' => 'id',
    ),
  );
  // Optionally specify a translation handler for testing translations.
  if (variable_get('entity_test_translation')) {
    $items['entity_test']['translation']['entity_test'] = TRUE;
  }
  return $items;
}

/**
 * Loads a test entity.
 *
 * @param int $id
 *   A test entity ID.
 * @param bool $reset
 *   A boolean indicating that the internal cache should be reset.
 *
 * @return Drupal\entity\Entity
 *   The loaded entity object, or FALSE if the entity cannot be loaded.
 */
function entity_test_load($id, $reset = FALSE) {
  return entity_load('entity_test', $id, $reset);
}

/**
 * Loads multiple test entities based on certain conditions.
 *
 * @param array|bool $ids
 *   An array of entity IDs, or FALSE to load all entities.
 * @param array $conditions
 *   An array of conditions to match against the {entity} table.
 * @param bool $reset
 *   A boolean indicating that the internal cache should be reset.
 *
 * @return array
 *   An array of test entity objects, indexed by ID.
 */
function entity_test_load_multiple($ids = array(), $conditions = array(), $reset = FALSE) {
  return entity_load_multiple('entity_test', $ids, $conditions, $reset);
}

/**
 * Deletes multiple test entities.
 *
 * @param $ids
 *   An array of test entity IDs.
 */
function entity_test_delete_multiple(array $ids) {
  entity_get_controller('entity_test')->delete($ids);
}
