class ProductTranslationHandler in Commerce Core 8.2
Defines the translation handler for products.
Based on NodeTranslationHandler.
Hierarchy
- class \Drupal\content_translation\ContentTranslationHandler implements ContentTranslationHandlerInterface, EntityHandlerInterface uses DependencySerializationTrait, EntityChangesDetectionTrait, StringTranslationTrait
- class \Drupal\commerce_product\ProductTranslationHandler
Expanded class hierarchy of ProductTranslationHandler
File
- modules/
product/ src/ ProductTranslationHandler.php, line 14
Namespace
Drupal\commerce_productView source
class ProductTranslationHandler extends ContentTranslationHandler {
/**
* {@inheritdoc}
*/
public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
parent::entityFormAlter($form, $form_state, $entity);
// Move the translation fieldset to a vertical tab.
if (isset($form['content_translation'])) {
$form['content_translation'] += [
'#group' => 'advanced',
'#attributes' => [
'class' => [
'product-translation-options',
],
],
];
$form['content_translation']['#weight'] = 100;
// The basic product values will be used, no need for specific elements.
$form['content_translation']['status']['#access'] = FALSE;
$form['content_translation']['name']['#access'] = FALSE;
$form['content_translation']['created']['#access'] = FALSE;
}
$form_object = $form_state
->getFormObject();
$form_langcode = $form_object
->getFormLangcode($form_state);
$translations = $entity
->getTranslationLanguages();
// Change the submit button labels to inform the user that
// publishing/unpublishing won't apply to all translations.
if (!$entity
->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) {
foreach ([
'publish',
'unpublish',
'submit',
] as $button) {
if (isset($form['actions'][$button])) {
$form['actions'][$button]['#value'] .= ' ' . t('(this translation)');
}
}
}
}
/**
* {@inheritdoc}
*/
public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
/** @var \Drupal\commerce_product\Entity\ProductInterface $entity */
if ($form_state
->hasValue('content_translation')) {
$translation =& $form_state
->getValue('content_translation');
$translation['status'] = $entity
->isPublished();
$account = $entity->uid->entity;
$translation['uid'] = $account ? $account
->id() : 0;
$translation['created'] = \Drupal::service('date.formatter')
->format($entity->created->value, 'custom', 'Y-m-d H:i:s O');
}
parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentTranslationHandler:: |
protected | property | The current user. | |
ContentTranslationHandler:: |
protected | property | The date formatter service. | |
ContentTranslationHandler:: |
protected | property | Information about the entity type. | |
ContentTranslationHandler:: |
protected | property | The type of the entity being translated. | |
ContentTranslationHandler:: |
protected | property | The entity type manager. | |
ContentTranslationHandler:: |
protected | property | The array of installed field storage definitions for the entity type, keyed by field name. | |
ContentTranslationHandler:: |
protected | property | The language manager. | |
ContentTranslationHandler:: |
protected | property | The content translation manager. | |
ContentTranslationHandler:: |
protected | property | The messenger service. | |
ContentTranslationHandler:: |
protected | function | Adds a clue about the form element translatability. | |
ContentTranslationHandler:: |
protected | function | Checks the field storage definition for translatability support. | |
ContentTranslationHandler:: |
public static | function |
Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface:: |
|
ContentTranslationHandler:: |
public | function | Form submission handler for ContentTranslationHandler::entityFormAlter(). | |
ContentTranslationHandler:: |
public | function | Form submission handler for ContentTranslationHandler::entityFormAlter(). | |
ContentTranslationHandler:: |
public | function | Process callback: determines which elements get clue in the form. | |
ContentTranslationHandler:: |
public | function | Form submission handler for ContentTranslationHandler::entityFormAlter(). | |
ContentTranslationHandler:: |
public | function | Form submission handler for ContentTranslationHandler::entityFormAlter(). | |
ContentTranslationHandler:: |
protected | function | Returns the title to be used for the entity form page. | 3 |
ContentTranslationHandler:: |
public | function | Form validation handler for ContentTranslationHandler::entityFormAlter(). | |
ContentTranslationHandler:: |
public static | function | Default value callback for the owner base field definition. | |
ContentTranslationHandler:: |
public | function |
Returns a set of field definitions to be used to store metadata items. Overrides ContentTranslationHandlerInterface:: |
|
ContentTranslationHandler:: |
public | function |
Retrieves the source language for the translation being created. Overrides ContentTranslationHandlerInterface:: |
|
ContentTranslationHandler:: |
public | function |
Checks if the user can perform the given operation on translations of the
wrapped entity. Overrides ContentTranslationHandlerInterface:: |
|
ContentTranslationHandler:: |
protected | function | Checks whether the entity type supports author natively. | |
ContentTranslationHandler:: |
protected | function | Checks whether the entity type supports modification time natively. | |
ContentTranslationHandler:: |
protected | function | Checks whether the entity type supports creation time natively. | 1 |
ContentTranslationHandler:: |
protected | function | Checks whether the entity type supports published status natively. | 1 |
ContentTranslationHandler:: |
public | function |
Marks translations as outdated. Overrides ContentTranslationHandlerInterface:: |
|
ContentTranslationHandler:: |
public | function | Initializes an instance of the content translation controller. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityChangesDetectionTrait:: |
protected | function | Returns an array of field names to skip when checking for changes. | |
ProductTranslationHandler:: |
public | function |
Performs the needed alterations to the entity form. Overrides ContentTranslationHandler:: |
|
ProductTranslationHandler:: |
public | function |
Entity builder method. Overrides ContentTranslationHandler:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |