Newer
Older
Angie Byron
committed
<?php
/**
* @file
Alex Pott
committed
* Definition of Drupal\content_translation\ContentTranslationControllerInterface.
Angie Byron
committed
*/
Alex Pott
committed
namespace Drupal\content_translation;
Angie Byron
committed
use Drupal\Core\Entity\EntityInterface;
/**
Alex Pott
committed
* Interface for providing content translation.
Angie Byron
committed
*
* Defines a set of methods to allow any entity to be processed by the entity
* translation UI.
*
Alex Pott
committed
* The content translation UI relies on the entity info to provide its features.
Angie Byron
committed
* 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.
*
Alex Pott
committed
* To make Content Translation automatically support an entity type some keys
Angie Byron
committed
* 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:
* - menu_base_path: ENTITY_TYPE/%ENTITY_TYPE
* - menu_view_path: ENTITY_TYPE/%ENTITY_TYPE
* - menu_edit_path: ENTITY_TYPE/%ENTITY_TYPE/edit
* 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 "controllers['translation']" key in the entity
Angie Byron
committed
* info. If an entity type is enabled for translation and no translation
Alex Pott
committed
* controller is defined, Drupal\content_translation\ContentTranslationController
Angie Byron
committed
* will be assumed. Every translation controller class must implement
Alex Pott
committed
* Drupal\content_translation\ContentTranslationControllerInterface.
Angie Byron
committed
*
* If the entity paths match the default patterns above and there is no need for
Alex Pott
committed
* an entity-specific translation controller class, Content Translation will
Angie Byron
committed
* 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
Alex Pott
committed
* the translation UI. The content translation info is an associative array that
Angie Byron
committed
* has to match the following structure. Two nested arrays keyed respectively
Alex Pott
committed
* by the 'translation' key and the 'content_translation' key. Elements:
Angie Byron
committed
* - access callback: The access callback for the translation pages. Defaults to
* 'entity_translation_translate_access'.
* - access arguments: The access arguments for the translation pages. By
* default only the entity object is passed to the access callback.
*
* This is how entity info would look for a module defining a new translatable
* entity type:
* @code
* 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' => array(
Alex Pott
committed
* 'content_translation' => array(
Angie Byron
committed
* 'access_callback' => 'mymodule_myentity_translate_access',
* 'access_arguments' => array(2),
* ),
* ),
* );
Alex Pott
committed
* $info['myentity']['controllers'] += array('translation' => 'Drupal\mymodule\MyContentTranslationController');
Angie Byron
committed
* }
* @endcode
*
* @see \Drupal\Core\Entity\EntityManager
*/
Alex Pott
committed
interface ContentTranslationControllerInterface {
Angie Byron
committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/**
* 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);
/**
Angie Byron
committed
* Checks if the user can perform the given operation on translations of the
* wrapped entity.
Angie Byron
committed
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity whose translation has to be accessed.
Angie Byron
committed
* @param $op
* The operation to be performed on the translation. Possible values are:
* - "create"
* - "update"
* - "delete"
Angie Byron
committed
*
* @return boolean
* TRUE if the operation may be performed, FALSE otherwise.
*/
Angie Byron
committed
public function getTranslationAccess(EntityInterface $entity, $op);
Angie Byron
committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* 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);
}