function ContentTranslationHandler::getFieldDefinitions

Same name in other branches
  1. 9 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::getFieldDefinitions()
  2. 8.9.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::getFieldDefinitions()
  3. 11.x core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::getFieldDefinitions()

Overrides ContentTranslationHandlerInterface::getFieldDefinitions

File

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

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(t('Translation source'))
        ->setDescription(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(t('Translation outdated'))
        ->setDescription(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(t('Translation author'))
            ->setDescription(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(t('Translation status'))
            ->setDescription(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(t('Translation created time'))
            ->setDescription(t('The Unix timestamp when the translation was created.'))
            ->setRevisionable(TRUE)
            ->setTranslatable(TRUE);
    }
    if (!$this->hasChangedTime()) {
        $definitions['content_translation_changed'] = BaseFieldDefinition::create('changed')->setLabel(t('Translation changed time'))
            ->setDescription(t('The Unix timestamp when the translation was most recently saved.'))
            ->setRevisionable(TRUE)
            ->setTranslatable(TRUE);
    }
    return $definitions;
}

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