Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ContentTranslationHandler.php

function ContentTranslationHandler::getFieldDefinitions

Overrides ContentTranslationHandlerInterface::getFieldDefinitions

File

core/modules/content_translation/src/ContentTranslationHandler.php, line 118

Class

ContentTranslationHandler
Base class for content translation handlers.

Namespace

Drupal\content_translation

Code

public function getFieldDefinitions() {
    $definitions = [];
    $definitions['content_translation_source'] = BaseFieldDefinition::create('language')->setLabel($this->t('Translation source'))
        ->setDescription($this->t('The source language from which this translation was created.'))
        ->setDefaultValue(LanguageInterface::LANGCODE_NOT_SPECIFIED)
        ->setInitialValue(LanguageInterface::LANGCODE_NOT_SPECIFIED)
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE);
    $definitions['content_translation_outdated'] = BaseFieldDefinition::create('boolean')->setLabel($this->t('Translation outdated'))
        ->setDescription($this->t('A boolean indicating whether this translation needs to be updated.'))
        ->setDefaultValue(FALSE)
        ->setInitialValue(FALSE)
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE);
    if (!$this->hasAuthor()) {
        $definitions['content_translation_uid'] = BaseFieldDefinition::create('entity_reference')->setLabel($this->t('Translation author'))
            ->setDescription($this->t('The author of this translation.'))
            ->setSetting('target_type', 'user')
            ->setSetting('handler', 'default')
            ->setRevisionable(TRUE)
            ->setDefaultValueCallback(static::class . '::getDefaultOwnerId')
            ->setTranslatable(TRUE);
    }
    if (!$this->hasPublishedStatus()) {
        $definitions['content_translation_status'] = BaseFieldDefinition::create('boolean')->setLabel($this->t('Translation status'))
            ->setDescription($this->t('A boolean indicating whether the translation is visible to non-translators.'))
            ->setDefaultValue(TRUE)
            ->setInitialValue(TRUE)
            ->setRevisionable(TRUE)
            ->setTranslatable(TRUE);
    }
    if (!$this->hasCreatedTime()) {
        $definitions['content_translation_created'] = BaseFieldDefinition::create('created')->setLabel($this->t('Translation created time'))
            ->setDescription($this->t('The Unix timestamp when the translation was created.'))
            ->setRevisionable(TRUE)
            ->setTranslatable(TRUE);
    }
    if (!$this->hasChangedTime()) {
        $definitions['content_translation_changed'] = BaseFieldDefinition::create('changed')->setLabel($this->t('Translation changed time'))
            ->setDescription($this->t('The Unix timestamp when the translation was most recently saved.'))
            ->setRevisionable(TRUE)
            ->setTranslatable(TRUE);
    }
    return $definitions;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal