class CommentTranslationHandler extends ContentTranslationHandler (View source)

Defines the translation handler for comments.

Traits

Provides helper methods to detect changes in an entity object.

Provides dependency injection friendly methods for serialization.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected array $_serviceIds

An array of service IDs keyed by property name used for serialization.

from  DependencySerializationTrait
protected array $_entityStorages

An array of entity type IDs keyed by the property name of their storages.

from  DependencySerializationTrait
protected TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected string $entityTypeId

The type of the entity being translated.

from  ContentTranslationHandler
protected EntityTypeInterface $entityType

Information about the entity type.

from  ContentTranslationHandler
protected LanguageManagerInterface $languageManager

The language manager.

from  ContentTranslationHandler
protected ContentTranslationManagerInterface $manager

The content translation manager.

from  ContentTranslationHandler
protected EntityTypeManagerInterface $entityTypeManager

The entity type manager.

from  ContentTranslationHandler
protected AccountInterface $currentUser

The current user.

from  ContentTranslationHandler
protected FieldStorageDefinitionInterface[] $fieldStorageDefinitions

The array of installed field storage definitions for the entity type, keyed by field name.

from  ContentTranslationHandler
protected MessengerInterface $messenger

The messenger service.

from  ContentTranslationHandler
protected DateFormatterInterface $dateFormatter

The date formatter service.

from  ContentTranslationHandler

Methods

string[]
getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity)

Returns an array of field names to skip when checking for changes.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository)

Initializes an instance of the content translation controller.

createInstance(ContainerInterface $container, EntityTypeInterface $entity_type)

Instantiates a new instance of this entity handler.

getFieldDefinitions()

Returns a set of field definitions to be used to store metadata items.

bool
hasAuthor()

Checks whether the entity type supports author natively.

bool
hasPublishedStatus()

Checks whether the entity type supports published status natively.

bool
hasChangedTime()

Checks whether the entity type supports modification time natively.

bool
hasCreatedTime()

Checks whether the entity type supports creation time natively.

bool
checkFieldStorageDefinitionTranslatability(string $field_name)

Checks the field storage definition for translatability support.

retranslate(EntityInterface $entity, string $langcode = NULL)

Marks translations as outdated.

getTranslationAccess(EntityInterface $entity, $op)

Checks if the user can perform the given operation on translations of the wrapped entity.

string
getSourceLangcode(FormStateInterface $form_state)

Retrieves the source language for the translation being created.

entityFormAlter(array $form, FormStateInterface $form_state, EntityInterface $entity)

Performs the needed alterations to the entity form.

entityFormSharedElements($element, FormStateInterface $form_state, $form)

Process callback: determines which elements get clue in the form.

addTranslatabilityClue(array $element)

Adds a clue about the form element translatability.

entityFormEntityBuild(string $entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)

Entity builder method.

entityFormValidate($form, FormStateInterface $form_state)

Form validation handler for ContentTranslationHandler::entityFormAlter().

entityFormSubmit($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

entityFormSourceChange($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

entityFormDelete($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

entityFormDeleteTranslation($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

string|null
entityFormTitle(EntityInterface $entity)

Returns the title to be used for the entity form page.

static int
getDefaultOwnerId()

Default value callback for the owner base field definition.

Details

protected string[] getFieldsToSkipFromTranslationChangesCheck(ContentEntityInterface $entity)

Returns an array of field names to skip when checking for changes.

Parameters

ContentEntityInterface $entity

A content entity object.

Return Value

string[]

An array of field names.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MessengerInterface $messenger, DateFormatterInterface $date_formatter, EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository)

Initializes an instance of the content translation controller.

Parameters

EntityTypeInterface $entity_type

The info array of the given entity type.

LanguageManagerInterface $language_manager

The language manager.

ContentTranslationManagerInterface $manager

The content translation manager service.

EntityTypeManagerInterface $entity_type_manager

The entity type manager.

AccountInterface $current_user

The current user.

MessengerInterface $messenger

The messenger service.

DateFormatterInterface $date_formatter

The date formatter service.

EntityLastInstalledSchemaRepositoryInterface $entity_last_installed_schema_repository

The installed entity definition repository service.

static EntityHandlerInterface createInstance(ContainerInterface $container, EntityTypeInterface $entity_type)

Instantiates a new instance of this entity handler.

This is a factory method that returns a new instance of this object. The factory should pass any needed dependencies into the constructor of this object, but not the container itself. Every call to this method must return a new instance of this object; that is, it may not implement a singleton.

Parameters

ContainerInterface $container

The service container this object should use.

EntityTypeInterface $entity_type

The entity type definition.

Return Value

EntityHandlerInterface

A new instance of the entity handler.

FieldDefinitionInterface[] getFieldDefinitions()

Returns a set of field definitions to be used to store metadata items.

Return Value

FieldDefinitionInterface[]

protected bool hasAuthor()

Checks whether the entity type supports author natively.

Return Value

bool

TRUE if metadata is natively supported, FALSE otherwise.

protected bool hasPublishedStatus()

Checks whether the entity type supports published status natively.

Return Value

bool

TRUE if metadata is natively supported, FALSE otherwise.

protected bool hasChangedTime()

Checks whether the entity type supports modification time natively.

Return Value

bool

TRUE if metadata is natively supported, FALSE otherwise.

protected bool hasCreatedTime()

Checks whether the entity type supports creation time natively.

Return Value

bool

TRUE if metadata is natively supported, FALSE otherwise.

protected bool checkFieldStorageDefinitionTranslatability(string $field_name)

Checks the field storage definition for translatability support.

Checks whether the given field is defined in the field storage definitions and if its definition specifies it as translatable.

Parameters

string $field_name

The name of the field.

Return Value

bool

TRUE if translatable field storage definition exists, FALSE otherwise.

retranslate(EntityInterface $entity, string $langcode = NULL)

Marks translations as outdated.

Parameters

EntityInterface $entity

The entity being translated.

string $langcode

(optional) The language code of the updated language: all the other translations will be marked as outdated. Defaults to the entity language.

AccessResultInterface getTranslationAccess(EntityInterface $entity, $op)

Checks if the user can perform the given operation on translations of the wrapped entity.

Parameters

EntityInterface $entity

The entity whose translation has to be accessed.

$op

The operation to be performed on the translation. Possible values are:

  • "create"
  • "update"
  • "delete"

Return Value

AccessResultInterface

The access result.

string getSourceLangcode(FormStateInterface $form_state)

Retrieves the source language for the translation being created.

Parameters

FormStateInterface $form_state

The current state of the form.

Return Value

string

The source language code.

entityFormAlter(array $form, FormStateInterface $form_state, EntityInterface $entity)

Performs the needed alterations to the entity form.

Parameters

array $form

The entity form to be altered to provide the translation workflow.

FormStateInterface $form_state

The current state of the form.

EntityInterface $entity

The entity being created or edited.

entityFormSharedElements($element, FormStateInterface $form_state, $form)

Process callback: determines which elements get clue in the form.

Parameters

$element
FormStateInterface $form_state
$form

See also

ContentTranslationHandler::entityFormAlter

protected addTranslatabilityClue(array $element)

Adds a clue about the form element translatability.

If the given element does not have a #title attribute, the function is recursively applied to child elements.

Parameters

array $element

A form element array.

entityFormEntityBuild(string $entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)

Entity builder method.

Parameters

string $entity_type

The type of the entity.

EntityInterface $entity

The entity whose form is being built.

array $form

A nested array form elements comprising the form.

FormStateInterface $form_state

The current state of the form.

entityFormValidate($form, FormStateInterface $form_state)

Form validation handler for ContentTranslationHandler::entityFormAlter().

Validates the submitted content translation metadata.

Parameters

$form
FormStateInterface $form_state

entityFormSubmit($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

Updates metadata fields, which should be updated only after the validation has run and before the entity is saved.

Parameters

$form
FormStateInterface $form_state

entityFormSourceChange($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

Takes care of the source language change.

Parameters

$form
FormStateInterface $form_state

entityFormDelete($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

Takes care of entity deletion.

Parameters

$form
FormStateInterface $form_state

entityFormDeleteTranslation($form, FormStateInterface $form_state)

Form submission handler for ContentTranslationHandler::entityFormAlter().

Takes care of content translation deletion.

Parameters

$form
FormStateInterface $form_state

protected string|null entityFormTitle(EntityInterface $entity)

Returns the title to be used for the entity form page.

Parameters

EntityInterface $entity

The entity whose form is being altered.

Return Value

string|null

The label of the entity, or NULL if there is no label defined.

static int getDefaultOwnerId()

Default value callback for the owner base field definition.

Return Value

int

The user ID.