interface TranslatableInterface

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Entity/TranslatableInterface.php \Drupal\Core\Entity\TranslatableInterface
Same name in other branches
  1. 9 core/lib/Drupal/Core/TypedData/TranslatableInterface.php \Drupal\Core\TypedData\TranslatableInterface
  2. 9 core/lib/Drupal/Core/Entity/TranslatableInterface.php \Drupal\Core\Entity\TranslatableInterface
  3. 8.9.x core/lib/Drupal/Core/TypedData/TranslatableInterface.php \Drupal\Core\TypedData\TranslatableInterface
  4. 8.9.x core/lib/Drupal/Core/Entity/TranslatableInterface.php \Drupal\Core\Entity\TranslatableInterface
  5. 10 core/lib/Drupal/Core/TypedData/TranslatableInterface.php \Drupal\Core\TypedData\TranslatableInterface
  6. 10 core/lib/Drupal/Core/Entity/TranslatableInterface.php \Drupal\Core\Entity\TranslatableInterface

Interface for translatable data.

Classes implementing this interface do not necessarily support translations.

To detect whether an entity type supports translation, call EntityTypeInterface::isTranslatable().

Many entity interfaces are composed of numerous other interfaces such as this one, which allow implementations to pick and choose which features to support through stub implementations of various interface methods. This means that even if an entity class implements TranslatableInterface, it might only have a stub implementation and not a functional one.

Hierarchy

Expanded class hierarchy of TranslatableInterface

All classes that implement TranslatableInterface

See also

\Drupal\Core\Entity\EntityTypeInterface::isTranslatable()

https://www.drupal.org/docs/8/api/entity-api/structure-of-an-entity-ann…

https://www.drupal.org/docs/8/api/entity-api/entity-translation-api

11 files declare their use of TranslatableInterface
BulkForm.php in core/modules/views/src/Plugin/views/field/BulkForm.php
ContentModerationState.php in core/modules/content_moderation/src/Entity/ContentModerationState.php
DeleteMultipleForm.php in core/lib/Drupal/Core/Entity/Form/DeleteMultipleForm.php
EntityContentBase.php in core/modules/migrate/src/Plugin/migrate/destination/EntityContentBase.php
EntityReferenceFormatterBase.php in core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/EntityReferenceFormatterBase.php

... See full list

File

core/lib/Drupal/Core/TypedData/TranslatableInterface.php, line 23

Namespace

Drupal\Core\TypedData
View source
interface TranslatableInterface {
    
    /**
     * Returns the translation language.
     *
     * @return \Drupal\Core\Language\LanguageInterface
     *   The language object.
     */
    public function language();
    
    /**
     * Checks whether the translation is the default one.
     *
     * @return bool
     *   TRUE if the translation is the default one, FALSE otherwise.
     */
    public function isDefaultTranslation();
    
    /**
     * Checks whether the translation is new.
     *
     * @return bool
     *   TRUE if the translation is new, FALSE otherwise.
     */
    public function isNewTranslation();
    
    /**
     * Returns the languages the data is translated to.
     *
     * @param bool $include_default
     *   (optional) Whether the default language should be included. Defaults to
     *   TRUE.
     *
     * @return \Drupal\Core\Language\LanguageInterface[]
     *   An associative array of language objects, keyed by language codes.
     */
    public function getTranslationLanguages($include_default = TRUE);
    
    /**
     * Gets a translation of the data.
     *
     * The returned translation has to be of the same type than this typed data
     * object.
     *
     * @param $langcode
     *   The language code of the translation to get or
     *   LanguageInterface::LANGCODE_DEFAULT
     *   to get the data in default language.
     *
     * @return static
     *   A typed data object for the translated data.
     *
     * @throws \InvalidArgumentException
     *   If an invalid or non-existing translation language is specified.
     */
    public function getTranslation($langcode);
    
    /**
     * Returns the translatable object in the language it was created.
     *
     * @return static
     *   The translation object referring to the original language.
     */
    public function getUntranslated();
    
    /**
     * Checks there is a translation for the given language code.
     *
     * @param string $langcode
     *   The language code identifying the translation.
     *
     * @return bool
     *   TRUE if the translation exists, FALSE otherwise.
     */
    public function hasTranslation($langcode);
    
    /**
     * Adds a new translation to the translatable object.
     *
     * To create a translation of an entity prefilled with the original data:
     * @code
     *   $entity->addTranslation($langcode, $entity->toArray())
     * @endcode
     *
     * @param string $langcode
     *   The language code identifying the translation.
     * @param array $values
     *   (optional) An array of initial values to be assigned to the translatable
     *   fields. Defaults to none.
     *
     * @return static
     *   A new entity translation object.
     *
     * @throws \InvalidArgumentException
     *   If an invalid or existing translation language is specified.
     */
    public function addTranslation($langcode, array $values = []);
    
    /**
     * Removes the translation identified by the given language code.
     *
     * @param string $langcode
     *   The language code identifying the translation to be removed.
     */
    public function removeTranslation($langcode);
    
    /**
     * Returns the translation support status.
     *
     * @return bool
     *   TRUE if the object has translation support enabled.
     */
    public function isTranslatable();

}

Members

Title Sort descending Modifiers Object type Summary
TranslatableInterface::addTranslation public function Adds a new translation to the translatable object.
TranslatableInterface::getTranslation public function Gets a translation of the data.
TranslatableInterface::getTranslationLanguages public function Returns the languages the data is translated to.
TranslatableInterface::getUntranslated public function Returns the translatable object in the language it was created.
TranslatableInterface::hasTranslation public function Checks there is a translation for the given language code.
TranslatableInterface::isDefaultTranslation public function Checks whether the translation is the default one.
TranslatableInterface::isNewTranslation public function Checks whether the translation is new.
TranslatableInterface::isTranslatable public function Returns the translation support status.
TranslatableInterface::language public function Returns the translation language.
TranslatableInterface::removeTranslation public function Removes the translation identified by the given language code.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.