Interface for providing entity translation.
Defines a set of methods to allow any entity to be processed by the entity translation UI.
The entity 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 Entity 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 'menu_base_path' key must be defined. This is used to determine the view and edit paths if they follow the standard path patterns. Otherwise the 'menu_view_path' and 'menu_edit_path' keys must be defined. If an entity type is enabled for translation and no menu path key is defined, the following defaults will be assumed:
The menu base path is also used to reliably alter menu router information to provide the translation overview page for any entity. If the entity uses a menu loader different from %ENTITY_TYPE also the 'menu path wildcard' info key needs to be defined.
Every entity type needs a translation controller to be translated. This can be specified through the 'translation_controller_class' key in the entity info. If an entity type is enabled for translation and no translation controller is defined, Drupal\translation_entity\EntityTranslationController will be assumed. Every translation controller class must implement Drupal\translation_entity\EntityTranslationControllerInterface.
If the entity paths match the default patterns above and there is no need for an entity-specific translation controller class, Entity Translation will provide built-in support for the entity. It will still be required to enable translation for each translatable bundle.
Additionally some more entity info keys can be defined to further customize the translation UI. The entity translation info is an associative array that has to match the following structure. Two nested arrays keyed respectively by the 'translation' key and the 'entity_translation' key: the first one is the key defined by the core entity system, while the second one registers Entity Tanslation as a field translation handler. Elements:
This is how entity info would look for a module defining a new translatable entity type:
function mymodule_entity_info_alter(array &$info) {
$info['myentity'] += array(
'menu_base_path' => 'mymodule/myentity/%my_entity_loader',
'menu_path_wildcard' => '%my_entity_loader',
'translation_controller_class' => 'Drupal\\mymodule\\MyEntityTranslationController',
'translation' => array(
'translation_entity' => array(
'access_callback' => 'mymodule_myentity_translate_access',
'access_arguments' => array(
2,
),
),
),
);
}
Expanded class hierarchy of EntityTranslationControllerInterface
All classes that implement EntityTranslationControllerInterface
\Drupal\Core\Entity\EntityManager
interface EntityTranslationControllerInterface {
/**
* Returns the base path for the current entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to the path should refer to.
*
* @return string
* The entity base path.
*/
public function getBasePath(EntityInterface $entity);
/**
* Returns the path of the entity edit form.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to the path should refer to.
*
* @return string
* The entity edit path.
*/
public function getEditPath(EntityInterface $entity);
/**
* Returns the path of the entity view page.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to the path should refer to.
*
* @return string
* The entity view path.
*/
public function getViewPath(EntityInterface $entity);
/**
* Checks if the user can perform the given operation on the wrapped entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity access should be checked for.
* @param string $op
* The operation to be performed. Possible values are:
* - "view"
* - "update"
* - "delete"
* - "create"
*
* @return
* TRUE if the user is allowed to perform the given operation, FALSE
* otherwise.
*/
public function getAccess(EntityInterface $entity, $op);
/**
* Checks if a user is allowed to edit the given translation.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity whose translation has to be accessed.
* @param string $langcode
* The language code identifying the translation to be accessed.
*
* @return boolean
* TRUE if the operation may be performed, FALSE otherwise.
*/
public function getTranslationAccess(EntityInterface $entity, $langcode);
/**
* Retrieves the source language for the translation being created.
*
* @param array $form_state
* The form state array.
*
* @return string
* The source language code.
*/
public function getSourceLangcode(array $form_state);
/**
* Removes the translation values from the given entity.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity whose values should be removed.
* @param string $langcode
* The language code identifying the translation being deleted.
*/
public function removeTranslation(EntityInterface $entity, $langcode);
/**
* Marks translations as outdated.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being translated.
* @param string $langcode
* (optional) The language code of the updated language: all the other
* translations will be marked as outdated. Defaults to the entity language.
*/
public function retranslate(EntityInterface $entity, $langcode = NULL);
/**
* Performs the needed alterations to the entity form.
*
* @param array $form
* The entity form to be altered to provide the translation workflow.
* @param array $form_state
* The form state array.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity being created or edited.
*/
public function entityFormAlter(array &$form, array &$form_state, EntityInterface $entity);
}
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityTranslationControllerInterface:: |
public | function | Performs the needed alterations to the entity form. | 1 |
EntityTranslationControllerInterface:: |
public | function | Checks if the user can perform the given operation on the wrapped entity. | 1 |
EntityTranslationControllerInterface:: |
public | function | Returns the base path for the current entity. | 1 |
EntityTranslationControllerInterface:: |
public | function | Returns the path of the entity edit form. | 1 |
EntityTranslationControllerInterface:: |
public | function | Retrieves the source language for the translation being created. | 1 |
EntityTranslationControllerInterface:: |
public | function | Checks if a user is allowed to edit the given translation. | 1 |
EntityTranslationControllerInterface:: |
public | function | Returns the path of the entity view page. | 1 |
EntityTranslationControllerInterface:: |
public | function | Removes the translation values from the given entity. | 1 |
EntityTranslationControllerInterface:: |
public | function | Marks translations as outdated. | 1 |