4dabef12f0e93c83b0ba6e4fb588e3f0ee018440
[yaffs-website] / web / core / lib / Drupal / Core / TypedData / TranslatableInterface.php
1 <?php
2
3 namespace Drupal\Core\TypedData;
4
5 /**
6  * Interface for translatable data.
7  *
8  * Classes implementing this interface do not necessarily support translations.
9  *
10  * To detect whether an entity type supports translation, call
11  * EntityTypeInterface::isTranslatable().
12  *
13  * Many entity interfaces are composed of numerous other interfaces such as this
14  * one, which allow implementations to pick and choose which features to support
15  * through stub implementations of various interface methods. This means that
16  * even if an entity class implements TranslatableInterface, it might only have
17  * a stub implementation and not a functional one.
18  *
19  * @see \Drupal\Core\Entity\EntityTypeInterface::isTranslatable()
20  * @see https://www.drupal.org/docs/8/api/entity-api/structure-of-an-entity-annotation
21  * @see https://www.drupal.org/docs/8/api/entity-api/entity-translation-api
22  */
23 interface TranslatableInterface {
24
25   /**
26    * Returns the translation language.
27    *
28    * @return \Drupal\Core\Language\LanguageInterface
29    *   The language object.
30    */
31   public function language();
32
33   /**
34    * Checks whether the translation is the default one.
35    *
36    * @return bool
37    *   TRUE if the translation is the default one, FALSE otherwise.
38    */
39   public function isDefaultTranslation();
40
41   /**
42    * Checks whether the translation is new.
43    *
44    * @return bool
45    *   TRUE if the translation is new, FALSE otherwise.
46    */
47   public function isNewTranslation();
48
49   /**
50    * Returns the languages the data is translated to.
51    *
52    * @param bool $include_default
53    *   (optional) Whether the default language should be included. Defaults to
54    *   TRUE.
55    *
56    * @return \Drupal\Core\Language\LanguageInterface[]
57    *   An associative array of language objects, keyed by language codes.
58    */
59   public function getTranslationLanguages($include_default = TRUE);
60
61   /**
62    * Gets a translation of the data.
63    *
64    * The returned translation has to be of the same type than this typed data
65    * object.
66    *
67    * @param $langcode
68    *   The language code of the translation to get or
69    *   LanguageInterface::LANGCODE_DEFAULT
70    *   to get the data in default language.
71    *
72    * @return $this
73    *   A typed data object for the translated data.
74    *
75    * @throws \InvalidArgumentException
76    *   If an invalid or non-existing translation language is specified.
77    */
78   public function getTranslation($langcode);
79
80   /**
81    * Returns the translatable object referring to the original language.
82    *
83    * @return $this
84    *   The translation object referring to the original language.
85    */
86   public function getUntranslated();
87
88   /**
89    * Checks there is a translation for the given language code.
90    *
91    * @param string $langcode
92    *   The language code identifying the translation.
93    *
94    * @return bool
95    *   TRUE if the translation exists, FALSE otherwise.
96    */
97   public function hasTranslation($langcode);
98
99   /**
100    * Adds a new translation to the translatable object.
101    *
102    * @param string $langcode
103    *   The language code identifying the translation.
104    * @param array $values
105    *   (optional) An array of initial values to be assigned to the translatable
106    *   fields. Defaults to none.
107    *
108    * @return $this
109    *
110    * @throws \InvalidArgumentException
111    *   If an invalid or existing translation language is specified.
112    */
113   public function addTranslation($langcode, array $values = []);
114
115   /**
116    * Removes the translation identified by the given language code.
117    *
118    * @param string $langcode
119    *   The language code identifying the translation to be removed.
120    */
121   public function removeTranslation($langcode);
122
123   /**
124    * Returns the translation support status.
125    *
126    * @return bool
127    *   TRUE if the object has translation support enabled.
128    */
129   public function isTranslatable();
130
131 }