class NodeTranslationHandler

Same name and namespace in other branches
  1. 9 core/modules/node/src/NodeTranslationHandler.php \Drupal\node\NodeTranslationHandler
  2. 8.9.x core/modules/node/src/NodeTranslationHandler.php \Drupal\node\NodeTranslationHandler
  3. 10 core/modules/node/src/NodeTranslationHandler.php \Drupal\node\NodeTranslationHandler

Defines the translation handler for nodes.

Hierarchy

Expanded class hierarchy of NodeTranslationHandler

File

core/modules/node/src/NodeTranslationHandler.php, line 12

Namespace

Drupal\node
View source
class NodeTranslationHandler extends ContentTranslationHandler {
    
    /**
     * {@inheritdoc}
     */
    public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
        parent::entityFormAlter($form, $form_state, $entity);
        if (isset($form['content_translation'])) {
            // We do not need to show these values on node forms: they inherit the
            // basic node property values.
            $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();
        $status_translatable = NULL;
        // Change the submit button labels if there was a status field they affect
        // in which case their publishing / unpublishing may or may not apply
        // to all translations.
        if (!$entity->isNew() && (!isset($translations[$form_langcode]) || count($translations) > 1)) {
            foreach ($entity->getFieldDefinitions() as $property_name => $definition) {
                if ($property_name == 'status') {
                    $status_translatable = $definition->isTranslatable();
                }
            }
            if (isset($status_translatable)) {
                if (isset($form['actions']['submit'])) {
                    $form['actions']['submit']['#value'] .= ' ' . ($status_translatable ? t('(this translation)') : t('(all translations)'));
                }
            }
        }
    }
    
    /**
     * {@inheritdoc}
     */
    protected function entityFormTitle(EntityInterface $entity) {
        $type_name = node_get_type_label($entity);
        return t('<em>Edit @type</em> @title', [
            '@type' => $type_name,
            '@title' => $entity->label(),
        ]);
    }
    
    /**
     * {@inheritdoc}
     */
    public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
        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'] = $this->dateFormatter
                ->format($entity->created->value, 'custom', 'Y-m-d H:i:s O');
        }
        parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ContentTranslationHandler::$entityTypeId protected property The type of the entity being translated.
ContentTranslationHandler::$fieldStorageDefinitions protected property Installed field storage definitions for the entity type.
ContentTranslationHandler::addTranslatabilityClue protected function Adds a clue about the form element translatability.
ContentTranslationHandler::checkFieldStorageDefinitionTranslatability protected function Checks the field storage definition for translatability support.
ContentTranslationHandler::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance
ContentTranslationHandler::entityFormDelete public function Form submission handler for ContentTranslationHandler::entityFormAlter().
ContentTranslationHandler::entityFormDeleteTranslationUrl protected function Form submission handler for ContentTranslationHandler::entityFormAlter().
ContentTranslationHandler::entityFormSharedElements public function Process callback: determines which elements get clue in the form.
ContentTranslationHandler::entityFormSourceChange public function Form submission handler for ContentTranslationHandler::entityFormAlter().
ContentTranslationHandler::entityFormSubmit public function Form submission handler for ContentTranslationHandler::entityFormAlter().
ContentTranslationHandler::entityFormValidate public function Form validation handler for ContentTranslationHandler::entityFormAlter().
ContentTranslationHandler::getDefaultOwnerId public static function Default value callback for the owner base field definition.
ContentTranslationHandler::getFieldDefinitions public function Returns a set of field definitions to be used to store metadata items. Overrides ContentTranslationHandlerInterface::getFieldDefinitions
ContentTranslationHandler::getSourceLangcode public function Retrieves the source language for the translation being created. Overrides ContentTranslationHandlerInterface::getSourceLangcode
ContentTranslationHandler::getTranslationAccess public function Checks that the user can perform the operation on the entity translation. Overrides ContentTranslationHandlerInterface::getTranslationAccess
ContentTranslationHandler::hasAuthor protected function Checks whether the entity type supports author natively.
ContentTranslationHandler::hasChangedTime protected function Checks whether the entity type supports modification time natively.
ContentTranslationHandler::hasCreatedTime protected function Checks whether the entity type supports creation time natively. 1
ContentTranslationHandler::hasPublishedStatus protected function Checks whether the entity type supports published status natively. 1
ContentTranslationHandler::retranslate public function Marks translations as outdated. Overrides ContentTranslationHandlerInterface::retranslate
ContentTranslationHandler::__construct public function Initializes an instance of the content translation controller.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
EntityChangesDetectionTrait::getFieldsToSkipFromTranslationChangesCheck protected function Returns an array of field names to skip when checking for changes.
NodeTranslationHandler::entityFormAlter public function Performs the needed alterations to the entity form. Overrides ContentTranslationHandler::entityFormAlter
NodeTranslationHandler::entityFormEntityBuild public function Entity builder method. Overrides ContentTranslationHandler::entityFormEntityBuild
NodeTranslationHandler::entityFormTitle protected function Returns the title to be used for the entity form page. Overrides ContentTranslationHandler::entityFormTitle
StringTranslationTrait::$stringTranslation protected property The string translation service. 3
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

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