diff --git a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php index 3dbbb39..316ad94 100644 --- a/core/lib/Drupal/Core/Entity/Annotation/EntityType.php +++ b/core/lib/Drupal/Core/Entity/Annotation/EntityType.php @@ -12,6 +12,11 @@ /** * Defines an Entity type annotation object. * + * Additional information can be provided by modules: hook_entity_info() can be + * implemented to define new properties, while hook_entity_info_alter() can be + * implemented to alter existing data and fill-in defaults. Module-specific + * properties should be documented in the hook implementations defining them. + * * @Annotation */ class EntityType extends Plugin { @@ -54,9 +59,6 @@ class EntityType extends Plugin { * - access: The name of the class that is used for access checks. The class * must implement \Drupal\Core\Entity\EntityAccessControllerInterface. * Defaults to \Drupal\Core\Entity\EntityAccessController. - * - translation: The name of the controller class that should be used to - * handle the translation process. The class must implement - * \Drupal\content_translation\ContentTranslationControllerInterface. * * @todo Interfaces from outside \Drupal\Core or \Drupal\Component should not * be used here. @@ -161,13 +163,6 @@ class EntityType extends Plugin { public $translatable = FALSE; /** - * @todo content_translation_entity_info_alter() uses this but it is undocumented. - * - * @var array - */ - public $translation = array(); - - /** * The name of the entity type for which bundles are provided. * * It can be used by other modules to act accordingly; for example, diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 73dcca9..c1ed2a0 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -75,6 +75,30 @@ function content_translation_language_types_info_alter(array &$language_types) { /** * Implements hook_entity_info_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 + * for more details on all the entity info keys that may be defined. + * + * To make Content Translation automatically support an entity type some keys + * may need to be defined, but none of them is required unless the entity path + * is different from the usual /ENTITY_TYPE/{ENTITY_TYPE} pattern (for instance + * "/taxonomy/term/{taxonomy_term}"), in which case at least the 'canonical' key + * in the 'links' entity info property must be defined. + * + * Every entity type needs a translation controller to be translated. This can + * be specified through the 'translation' key in the 'controllers' entity info + * property. If an entity type is translatable and no translation controller is + * defined, \Drupal\content_translation\ContentTranslationController will be + * assumed. Every translation controller class must implement + * \Drupal\content_translation\ContentTranslationControllerInterface. + * + * If the entity paths match the default pattern above and there is no need for + * an entity-specific translation controller class, Content Translation will + * provide built-in support for the entity. However enabling translation for + * each translatable bundle will be required. + * + * @see \Drupal\Core\Entity\Annotation\EntityType */ function content_translation_entity_info_alter(array &$entity_info) { // Provide defaults for translation info. @@ -91,6 +115,8 @@ function content_translation_entity_info_alter(array &$entity_info) { $info['links'] += array( 'drupal:content-translation-overview' => "content_translation.translation_overview_$entity_type", ); + // @todo Remove this as soon as menu access checks rely on the + // controller. See https://drupal.org/node/2155787. $info['translation']['content_translation'] += array( 'access_callback' => 'content_translation_translate_access', ); diff --git a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationControllerInterface.php b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationControllerInterface.php index ed68e8f..39e307b 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationControllerInterface.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/ContentTranslationControllerInterface.php @@ -14,31 +14,6 @@ * * Defines a set of methods to allow any entity to be processed by the entity * translation UI. - * - * 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 - * for more details on all the entity info keys that may be defined. - * - * To make Content Translation automatically support an entity type some keys - * may need to be defined, but none of them is required unless the entity path - * is different from ENTITY_TYPE/%ENTITY_TYPE (e.g. taxonomy/term/1), in which - * case at least the 'canonical' key in the 'links' entity info property must be - * defined. - * - * Every entity type needs a translation controller to be translated. This can - * be specified through the "controllers['translation']" key in the entity - * info. If an entity type is enabled for translation and no translation - * controller is defined, - * \Drupal\content_translation\ContentTranslationController will be assumed. - * Every translation controller class must implement - * \Drupal\content_translation\ContentTranslationControllerInterface. - * - * If the entity paths match the default patterns above and there is no need for - * an entity-specific translation controller class, Content Translation will - * provide built-in support for the entity. It will still be required to enable - * translation for each translatable bundle. - * - * @see \Drupal\Core\Entity\EntityManagerInterface */ interface ContentTranslationControllerInterface { diff --git a/core/modules/system/entity.api.php b/core/modules/system/entity.api.php index 5b880cd..295f260 100644 --- a/core/modules/system/entity.api.php +++ b/core/modules/system/entity.api.php @@ -96,14 +96,15 @@ function hook_ENTITY_TYPE_create_access(\Drupal\Core\Session\AccountInterface $a /** * Add to entity type definitions. * - * Modules may implement this hook to add information to defined entity types. + * Modules may implement this hook to add information to defined entity types, + * as defined in the related annotation object. * * @param array $entity_info * 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\EntityManagerInterface + * @see \Drupal\Core\Entity\Annotation\EntityType * @see entity_get_info() */ function hook_entity_info(&$entity_info) { @@ -114,6 +115,32 @@ function hook_entity_info(&$entity_info) { } /** + * Alter the entity type definitions. + * + * Modules may implement this hook to alter the information that defines an + * entity type. All properties that are available in + * \Drupal\Core\Entity\Annotation\EntityType and all the ones additionally + * 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. + * + * @param array $entity_info + * 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\Annotation\EntityType + * @see entity_get_info() + */ +function hook_entity_info_alter(&$entity_info) { + // Set the controller class for nodes to an alternate implementation of the + // Drupal\Core\Entity\EntityStorageControllerInterface interface. + $entity_info['node']['controllers']['storage'] = 'Drupal\mymodule\MyCustomNodeStorageController'; + $entity_info['node']['controllers'] += array('my_module_controller' => 'Drupal\mymodule\MyModuleController'); +} + +/** * Alter the view modes for entity types. * * @param array $view_modes @@ -221,30 +248,6 @@ function hook_entity_bundle_delete($entity_type, $bundle) { } /** - * Alter the entity type definitions. - * - * Modules may implement this hook to alter the information that defines an - * entity type. All properties that are available in - * \Drupal\Core\Entity\EntityManagerInterface can be altered here. - * - * Do not use this hook to add information to entity types. Use - * hook_entity_info() for that instead. - * - * @param array $entity_info - * 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\EntityManagerInterface - * @see entity_get_info() - */ -function hook_entity_info_alter(&$entity_info) { - // Set the controller class for nodes to an alternate implementation of the - // Drupal\Core\Entity\EntityStorageControllerInterface interface. - $entity_info['node']['controllers']['storage'] = 'Drupal\mymodule\MyCustomNodeStorageController'; -} - -/** * Act on a newly created entity. * * This hook runs after a new entity object has just been instantiated. It can