Issue #1981858 by Berdir, tim.plunkett, longwave, Les Lim: Rename hook_entity_info/alter() to hook_entity_type_build/alter().

8.0.x
Alex Pott 2014-02-20 10:04:54 +00:00
parent 40dc8daf51
commit c210e8681c
27 changed files with 118 additions and 145 deletions

View File

@ -10,33 +10,6 @@ use Drupal\Core\Entity\EntityStorageException;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
/**
* Gets the entity definition for an entity type.
*
* @param string|null $entity_type
* (optional) The entity type (e.g. 'node'). Leave NULL to retrieve
* information for all entity types.
*
* @return array
* An array containing the entity type's definition, as retrieved with
* \Drupal\Core\Entity\EntityManagerInterface. If $entity_type is NULL, an
* associative array of all entity type definitions keyed by entity type is
* returned.
*
* @see \Drupal\Core\Entity\EntityManagerInterface
* @see hook_entity_info_alter()
*
* @deprecated Use \Drupal\Core\Entity\EntityManagerInterface::getDefinitions() directly.
*/
function entity_get_info($entity_type = NULL) {
if (empty($entity_type)) {
return \Drupal::entityManager()->getDefinitions();
}
else {
return \Drupal::entityManager()->getDefinition($entity_type);
}
}
/**
* Resets the cached information about entity types.
*/
@ -131,7 +104,7 @@ function entity_get_form_modes($entity_type = NULL) {
$form_modes[$form_mode_entity_type][$form_mode_name] = (array) $form_mode;
}
drupal_alter('entity_form_mode_info', $form_modes);
cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_info' => TRUE));
cache()->set("entity_form_mode_info:$langcode", $form_modes, Cache::PERMANENT, array('entity_types' => TRUE));
}
}
@ -169,7 +142,7 @@ function entity_get_view_modes($entity_type = NULL) {
$view_modes[$view_mode_entity_type][$view_mode_name] = (array) $view_mode;
}
drupal_alter('entity_view_mode_info', $view_modes);
cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_info' => TRUE));
cache()->set("entity_view_mode_info:$langcode", $view_modes, Cache::PERMANENT, array('entity_types' => TRUE));
}
}

View File

@ -30,7 +30,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* Manages entity type plugin definitions.
*
* Each entity type definition array is set in the entity type's
* annotation and altered by hook_entity_info_alter().
* annotation and altered by hook_entity_type_alter().
*
* The defaults for the plugin definition are provided in
* \Drupal\Core\Entity\EntityManagerInterface::defaults.
@ -38,7 +38,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* @see \Drupal\Core\Entity\Annotation\EntityType
* @see \Drupal\Core\Entity\EntityInterface
* @see \Drupal\Core\Entity\EntityTypeInterface
* @see hook_entity_info_alter()
* @see hook_entity_type_alter()
*/
class EntityManager extends PluginManagerBase implements EntityManagerInterface {
@ -134,7 +134,7 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
* The string translationManager.
*/
public function __construct(\Traversable $namespaces, ContainerInterface $container, ModuleHandlerInterface $module_handler, CacheBackendInterface $cache, LanguageManager $language_manager, TranslationInterface $translation_manager) {
// Allow the plugin definition to be altered by hook_entity_info_alter().
// Allow the plugin definition to be altered by hook_entity_type_alter().
$this->moduleHandler = $module_handler;
$this->cache = $cache;
@ -143,9 +143,9 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
$this->translationManager = $translation_manager;
$this->discovery = new AnnotatedClassDiscovery('Entity', $namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
$this->discovery = new InfoHookDecorator($this->discovery, 'entity_info');
$this->discovery = new AlterDecorator($this->discovery, 'entity_info');
$this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . $this->languageManager->getCurrentLanguage()->id, 'cache', Cache::PERMANENT, array('entity_info' => TRUE));
$this->discovery = new InfoHookDecorator($this->discovery, 'entity_type_build');
$this->discovery = new AlterDecorator($this->discovery, 'entity_type');
$this->discovery = new CacheDecorator($this->discovery, 'entity_type:' . $this->languageManager->getCurrentLanguage()->id, 'cache', Cache::PERMANENT, array('entity_types' => TRUE));
$this->container = $container;
}
@ -352,7 +352,7 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
}
}
$this->cache->set($cid, $this->entityFieldInfo[$entity_type_id], Cache::PERMANENT, array('entity_info' => TRUE, 'entity_field_info' => TRUE));
$this->cache->set($cid, $this->entityFieldInfo[$entity_type_id], Cache::PERMANENT, array('entity_types' => TRUE, 'entity_field_info' => TRUE));
}
}
@ -414,7 +414,7 @@ class EntityManager extends PluginManagerBase implements EntityManagerInterface
}
}
$this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo);
$this->cache->set("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, array('entity_info' => TRUE));
$this->cache->set("entity_bundle_info:$langcode", $this->bundleInfo, Cache::PERMANENT, array('entity_types' => TRUE));
}
}

View File

@ -12,7 +12,7 @@ namespace Drupal\Core\Entity;
*
* All entity controller classes specified via the "controllers['storage']" key
* returned by \Drupal\Core\Entity\EntityManagerInterface or
* hook_entity_info_alter() have to implement this interface.
* hook_entity_type_alter() have to implement this interface.
*
* Most simple, SQL-based entity controllers will do better by extending
* Drupal\Core\Entity\DatabaseStorageController instead of implementing this

View File

@ -10,8 +10,8 @@ namespace Drupal\Core\Entity;
/**
* Provides an interface for an entity type and its metadata.
*
* Additional information can be provided by modules: hook_entity_info() can be
* implemented to define new properties, while hook_entity_info_alter() can be
* Additional information can be provided by modules: hook_entity_type_build() can be
* implemented to define new properties, while hook_entity_type_alter() can be
* implemented to alter existing data and fill-in defaults. Module-specific
* properties should be documented in the hook implementations defining them.
*/

View File

@ -49,7 +49,7 @@ class UpdateModuleHandler extends ModuleHandler {
// This is called during rebuild to find testing themes.
case 'system_theme_info':
// Those are needed by user_access() to check access on update.php.
case 'entity_info':
case 'entity_type_build':
case 'entity_load':
case 'user_role_load':
return array();

View File

@ -71,11 +71,11 @@ function action_menu_link_defaults() {
}
/**
* Implements hook_entity_info().
* Implements hook_entity_type_build().
*/
function action_entity_info(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_info['action']
function action_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['action']
->setFormClass('add', 'Drupal\action\ActionAddFormController')
->setFormClass('edit', 'Drupal\action\ActionEditFormController')
->setFormClass('delete', 'Drupal\action\Form\ActionDeleteForm')

View File

@ -136,15 +136,15 @@ function custom_block_load($id) {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function custom_block_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
function custom_block_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
// Add a translation handler for fields if the language module is enabled.
if (\Drupal::moduleHandler()->moduleExists('language')) {
$translation = $entity_info['custom_block']->get('translation');
$translation = $entity_types['custom_block']->get('translation');
$translation['custom_block'] = TRUE;
$entity_info['custom_block']->set('translation', $translation);
$entity_types['custom_block']->set('translation', $translation);
}
}

View File

@ -112,11 +112,11 @@ function book_permission() {
}
/**
* Implements hook_entity_info().
* Implements hook_entity_type_build().
*/
function book_entity_info(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_info['node']
function book_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['node']
->setFormClass('book_outline', 'Drupal\book\Form\BookOutlineForm')
->setLinkTemplate('book-outline-form', 'book.outline')
->setLinkTemplate('book-remove-form', 'book.remove');

View File

@ -9,15 +9,15 @@
use Drupal\comment\CommentInterface;
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function comment_test_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
function comment_test_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
if (\Drupal::languageManager()->isMultilingual()) {
// Enable language handling for comment fields.
$translation = $entity_info['comment']->get('translation');
$translation = $entity_types['comment']->get('translation');
$translation['comment_test'] = TRUE;
$entity_info['comment']->set('translation', $translation);
$entity_types['comment']->set('translation', $translation);
}
}

View File

@ -64,18 +64,18 @@ function config_test_config_test_create(ConfigTest $config_test) {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function config_test_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
function config_test_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
// The 'translatable' entity key is not supposed to change over time. In this
// case we can safely do it because we set it once and we do not change it for
// all the duration of the test session.
$entity_info['config_test']->set('translatable', \Drupal::service('state')->get('config_test.translatable'));
$entity_types['config_test']->set('translatable', \Drupal::service('state')->get('config_test.translatable'));
// Create a clone of config_test that does not have a status.
$entity_info['config_test_no_status'] = clone $entity_info['config_test'];
$config_test_no_status = &$entity_info['config_test_no_status'];
$entity_types['config_test_no_status'] = clone $entity_types['config_test'];
$config_test_no_status = &$entity_types['config_test_no_status'];
$config_test_no_status->setLinkTemplate('edit-form', 'config_test.entity_config_test_no_status');
$config_test_no_status->setLinkTemplate('delete-form', 'config_test.entity_delete_config_test_no_status');

View File

@ -85,11 +85,11 @@ function config_translation_theme() {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function config_translation_entity_info_alter($entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
foreach ($entity_info as $entity_type_id => $entity_type) {
function config_translation_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
foreach ($entity_types as $entity_type_id => $entity_type) {
if ($entity_type->isSubclassOf('Drupal\Core\Config\Entity\ConfigEntityInterface')) {
if ($entity_type_id == 'block') {
$class = 'Drupal\config_translation\Controller\ConfigTranslationBlockListController';

View File

@ -6,12 +6,12 @@
*/
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function config_translation_test_entity_info_alter(&$entity_info) {
function config_translation_test_entity_type_alter(array &$entity_types) {
// Remove entity definition for these entity types from config_test module.
unset($entity_info['config_test_no_status']);
unset($entity_info['config_query_test']);
unset($entity_types['config_test_no_status']);
unset($entity_types['config_query_test']);
}
/**

View File

@ -100,11 +100,11 @@ function contact_menu_link_defaults() {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function contact_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_info['user']->setLinkTemplate('contact-form', 'contact.personal_page');
function contact_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['user']->setLinkTemplate('contact-form', 'contact.personal_page');
}
/**

View File

@ -55,7 +55,7 @@ function content_translation_module_implements_alter(&$implementations, $hook) {
switch ($hook) {
// Move some of our hook implementations to the end of the list.
case 'menu_alter':
case 'entity_info_alter':
case 'entity_type_alter':
$group = $implementations['content_translation'];
unset($implementations['content_translation']);
$implementations['content_translation'] = $group;
@ -74,10 +74,10 @@ function content_translation_language_types_info_alter(array &$language_types) {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*
* The content translation UI relies on the entity info to provide its features.
* See the documentation of hook_entity_info() in the Entity API documentation
* See the documentation of hook_entity_type_build() in the Entity API documentation
* for more details on all the entity info keys that may be defined.
*
* To make Content Translation automatically support an entity type some keys
@ -100,24 +100,24 @@ function content_translation_language_types_info_alter(array &$language_types) {
*
* @see \Drupal\Core\Entity\Annotation\EntityType
*/
function content_translation_entity_info_alter(array &$entity_info) {
function content_translation_entity_type_alter(array &$entity_types) {
// Provide defaults for translation info.
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
foreach ($entity_info as $entity_type => &$info) {
if ($info->isTranslatable()) {
if (!$info->hasControllerClass('translation')) {
$info->setControllerClass('translation', 'Drupal\content_translation\ContentTranslationController');
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
foreach ($entity_types as $entity_type) {
if ($entity_type->isTranslatable()) {
if (!$entity_type->hasControllerClass('translation')) {
$entity_type->setControllerClass('translation', 'Drupal\content_translation\ContentTranslationController');
}
$translation = $info->get('translation');
$translation = $entity_type->get('translation');
if (!$translation || !isset($translation['content_translation'])) {
$translation['content_translation'] = array();
}
if ($info->hasLinkTemplate('canonical')) {
if ($entity_type->hasLinkTemplate('canonical')) {
// Provide default route names for the translation paths.
if (!$info->hasLinkTemplate('drupal:content-translation-overview')) {
$info->setLinkTemplate('drupal:content-translation-overview', "content_translation.translation_overview_$entity_type");
if (!$entity_type->hasLinkTemplate('drupal:content-translation-overview')) {
$entity_type->setLinkTemplate('drupal:content-translation-overview', "content_translation.translation_overview_" . $entity_type->id());
}
// @todo Remove this as soon as menu access checks rely on the
// controller. See https://drupal.org/node/2155787.
@ -125,7 +125,7 @@ function content_translation_entity_info_alter(array &$entity_info) {
'access_callback' => 'content_translation_translate_access',
);
}
$info->set('translation', $translation);
$entity_type->set('translation', $translation);
}
}
}

View File

@ -29,12 +29,12 @@ use Drupal\Core\Field\FieldDefinitionInterface;
* The Field Attach API uses the concept of bundles: the set of fields for a
* given entity is defined on a per-bundle basis. The collection of bundles for
* an entity type is added to the entity definition with
* hook_entity_info_alter(). For instance, node_entity_info_alter() exposes
* hook_entity_type_alter(). For instance, node_entity_type_alter() exposes
* each node type as its own bundle. This means that the set of fields of a
* node is determined by the node type.
*
* The Field API reads the bundle name for a given entity from a particular
* property of the entity object, and hook_entity_info_alter() defines which
* property of the entity object, and hook_entity_type_alter() defines which
* property to use. For instance, \Drupal\node\Entity\Node specifies:
* @code
* entity_keys = {

View File

@ -314,10 +314,10 @@ class FieldInfoTest extends FieldUnitTestBase {
// Now rebuild the field info cache, and set a variable which will cause
// the cache to be cleared while it's being rebuilt; see
// field_test_entity_info(). Ensure the test field is still in the returned
// field_test_entity_type_build(). Ensure the test field is still in the returned
// array.
field_info_cache_clear();
\Drupal::state()->set('field_test.clear_info_cache_in_hook_entity_info', TRUE);
\Drupal::state()->set('field_test.clear_info_cache_in_hook_entity_type_build', TRUE);
$fields = field_info_fields();
$this->assertTrue(isset($fields[$field->uuid]), 'The test field is found in the array returned by field_info_fields() even if its cache is cleared while being rebuilt.');
}

View File

@ -7,24 +7,24 @@ use Drupal\Core\Entity\EntityInterface;
*/
/**
* Implements hook_entity_info().
* Implements hook_entity_type_build().
*/
function field_test_entity_info() {
function field_test_entity_type_build() {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
// If requested, clear the field cache while this is being called. See
// Drupal\field\Tests\FieldInfoTest::testFieldInfoCache().
if (\Drupal::state()->get('field_test.clear_info_cache_in_hook_entity_info')) {
if (\Drupal::state()->get('field_test.clear_info_cache_in_hook_entity_type_build')) {
field_info_cache_clear();
}
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function field_test_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
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_info[$entity_type]->set('translatable', $translatable);
$entity_types[$entity_type]->set('translatable', $translatable);
}
}

View File

@ -130,16 +130,16 @@ function field_ui_element_info() {
}
/**
* Implements hook_entity_info().
* Implements hook_entity_type_build().
*/
function field_ui_entity_info(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_info['field_instance_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldInstanceConfigDeleteForm');
$entity_info['field_config']->setListClass('Drupal\field_ui\FieldConfigListController');
function field_ui_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['field_instance_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldInstanceConfigDeleteForm');
$entity_types['field_config']->setListClass('Drupal\field_ui\FieldConfigListController');
foreach ($entity_info as $info) {
if ($bundle = $info->getBundleOf()) {
$info
foreach ($entity_types as $entity_type) {
if ($bundle = $entity_type->getBundleOf()) {
$entity_type
->setLinkTemplate('field_ui-fields', "field_ui.overview_$bundle")
->setLinkTemplate('field_ui-form-display', "field_ui.form_display_overview_$bundle")
->setLinkTemplate('field_ui-display', "field_ui.display_overview_$bundle");

View File

@ -203,12 +203,12 @@ function forum_menu_local_tasks(&$data, $route_name) {
}
/**
* Implements hook_entity_info().
* Implements hook_entity_type_build().
*/
function forum_entity_info(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
function forum_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
// Register forum specific form controllers.
$entity_info['taxonomy_term']
$entity_types['taxonomy_term']
->setFormClass('forum', 'Drupal\forum\Form\ForumFormController')
->setFormClass('container', 'Drupal\forum\Form\ContainerFormController')
->setLinkTemplate('forum-delete-form', 'forum.delete')

View File

@ -106,11 +106,11 @@ function menu_menu_link_defaults() {
}
/**
* Implements hook_entity_info().
* Implements hook_entity_type_build().
*/
function menu_entity_info(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_info['menu']
function menu_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['menu']
->setFormClass('add', 'Drupal\menu\MenuFormController')
->setFormClass('edit', 'Drupal\menu\MenuFormController')
->setFormClass('delete', 'Drupal\menu\Form\MenuDeleteForm')
@ -119,7 +119,7 @@ function menu_entity_info(&$entity_info) {
->setLinkTemplate('delete-form', 'menu.delete_menu')
->setLinkTemplate('edit-form', 'menu.menu_edit');
$entity_info['menu_link']
$entity_types['menu_link']
->setFormClass('delete', 'Drupal\menu\Form\MenuLinkDeleteForm')
->setFormClass('reset', 'Drupal\menu\Form\MenuLinkResetForm')
->setLinkTemplate('delete-form', 'menu.link_delete');

View File

@ -341,7 +341,7 @@ function node_type_get_names() {
return $cache->data;
}
// Not using node_type_get_types() or entity_load_multiple() here, to allow
// this function being used in hook_entity_info() implementations.
// this function being used in hook_entity_type_build() implementations.
// @todo Consider to convert this into a generic config entity helper.
$config_names = config_get_storage_names_with_prefix('node.type.');
$names = array();

View File

@ -99,6 +99,6 @@ class TypeLinkManager implements TypeLinkManagerInterface {
}
// These URIs only change when entity info changes, so cache it permanently
// and only clear it when entity_info is cleared.
$this->cache->set('rest:links:types', $data, Cache::PERMANENT, array('entity_info' => TRUE));
$this->cache->set('rest:links:types', $data, Cache::PERMANENT, array('entity_types' => TRUE));
}
}

View File

@ -99,18 +99,18 @@ function hook_ENTITY_TYPE_create_access(\Drupal\Core\Session\AccountInterface $a
* Modules may implement this hook to add information to defined entity types,
* as defined in \Drupal\Core\Entity\EntityTypeInterface.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_info
* @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
* An associative array of all entity type definitions, keyed by the entity
* type name. Passed by reference.
*
* @see \Drupal\Core\Entity\Entity
* @see \Drupal\Core\Entity\EntityTypeInterface
*/
function hook_entity_info(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
function hook_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
// Add a form controller for a custom node form without overriding the default
// node form. To override the default node form, use hook_entity_info_alter().
$entity_info['node']->setFormClass('mymodule_foo', 'Drupal\mymodule\NodeFooFormController');
// node form. To override the default node form, use hook_entity_type_alter().
$entity_types['node']->setFormClass('mymodule_foo', 'Drupal\mymodule\NodeFooFormController');
}
/**
@ -122,20 +122,20 @@ function hook_entity_info(&$entity_info) {
* provided by modules can be altered here.
*
* Do not use this hook to add information to entity types, unless you are just
* filling-in default values. Use hook_entity_info() instead.
* filling-in default values. Use hook_entity_type_build() instead.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_info
* @param \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
* An associative array of all entity type definitions, keyed by the entity
* type name. Passed by reference.
*
* @see \Drupal\Core\Entity\Entity
* @see \Drupal\Core\Entity\EntityTypeInterface
*/
function hook_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
function hook_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\EntityStorageControllerInterface interface.
$entity_info['node']->setStorageClass('Drupal\mymodule\MyCustomNodeStorageController');
$entity_types['node']->setStorageClass('Drupal\mymodule\MyCustomNodeStorageController');
}
/**

View File

@ -6,9 +6,9 @@
*/
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function entity_cache_test_dependency_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_info['entity_cache_test']->set('label', \Drupal::state()->get('entity_cache_test.label') ?: 'Entity Cache Test');
function entity_cache_test_dependency_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['entity_cache_test']->set('label', \Drupal::state()->get('entity_cache_test.label') ?: 'Entity Cache Test');
}

View File

@ -58,16 +58,16 @@ function entity_test_entity_types($filter = NULL) {
}
/**
* Implements hook_entity_info_alter().
* Implements hook_entity_type_alter().
*/
function entity_test_entity_info_alter(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
function entity_test_entity_type_alter(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
foreach (entity_test_entity_types() as $entity_type) {
// Optionally specify a translation handler for testing translations.
if (\Drupal::state()->get('entity_test.translation')) {
$translation = $entity_info[$entity_type]->get('translation');
$translation = $entity_types[$entity_type]->get('translation');
$translation[$entity_type] = TRUE;
$entity_info[$entity_type]->set('translation', $translation);
$entity_types[$entity_type]->set('translation', $translation);
}
}
}

View File

@ -86,11 +86,11 @@ function views_ui_menu_link_defaults() {
}
/**
* Implements hook_entity_info().
* Implements hook_entity_type_build().
*/
function views_ui_entity_info(&$entity_info) {
/** @var $entity_info \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_info['view']
function views_ui_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['view']
->setFormClass('edit', 'Drupal\views_ui\ViewEditFormController')
->setFormClass('add', 'Drupal\views_ui\ViewAddFormController')
->setFormClass('preview', 'Drupal\views_ui\ViewPreviewFormController')

View File

@ -106,7 +106,7 @@ class EntityManagerTest extends UnitTestCase {
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->moduleHandler->expects($this->any())
->method('getImplementations')
->with('entity_info')
->with('entity_type_build')
->will($this->returnValue(array()));
$this->cache = $this->getMock('Drupal\Core\Cache\CacheBackendInterface');