Language.php

Same filename in this branch
  1. 8.9.x core/modules/language/src/Plugin/Condition/Language.php
  2. 8.9.x core/modules/ckeditor/src/Plugin/CKEditorPlugin/Language.php
  3. 8.9.x core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php
  4. 8.9.x core/lib/Drupal/Core/Language/Language.php
Same filename and directory in other branches
  1. 9 core/modules/language/src/Plugin/migrate/source/Language.php
  2. 9 core/modules/language/src/Plugin/Condition/Language.php
  3. 9 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php
  4. 9 core/modules/ckeditor/src/Plugin/CKEditorPlugin/Language.php
  5. 9 core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php
  6. 9 core/lib/Drupal/Core/Language/Language.php
  7. 10 core/modules/language/src/Plugin/migrate/source/Language.php
  8. 10 core/modules/language/src/Plugin/Condition/Language.php
  9. 10 core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php
  10. 10 core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php
  11. 10 core/lib/Drupal/Core/Language/Language.php
  12. 11.x core/modules/language/src/Plugin/migrate/source/Language.php
  13. 11.x core/modules/language/src/Plugin/Condition/Language.php
  14. 11.x core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/Language.php
  15. 11.x core/lib/Drupal/Core/TypedData/Plugin/DataType/Language.php
  16. 11.x core/lib/Drupal/Core/Language/Language.php

Namespace

Drupal\language\Plugin\migrate\source

File

core/modules/language/src/Plugin/migrate/source/Language.php

View source
<?php

namespace Drupal\language\Plugin\migrate\source;

use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

/**
 * @MigrateSource(
 *   id = "language",
 *   source_module = "locale"
 * )
 */
class Language extends DrupalSqlBase {
    
    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'language' => $this->t('The language code.'),
            'name' => $this->t('The English name of the language.'),
            'native' => $this->t('The native name of the language.'),
            'direction' => $this->t('The language direction. (0 = LTR, 1 = RTL)'),
            'enabled' => $this->t('Whether the language is enabled.'),
            'plurals' => $this->t('Number of plural indexes in this language.'),
            'formula' => $this->t('PHP formula to get plural indexes.'),
            'domain' => $this->t('Domain to use for this language.'),
            'prefix' => $this->t('Path prefix used for this language.'),
            'weight' => $this->t('The language weight when listed.'),
            'javascript' => $this->t('Location of the JavaScript translation file.'),
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function getIds() {
        return [
            'language' => [
                'type' => 'string',
            ],
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function query() {
        return $this->select('languages')
            ->fields('languages');
    }
    
    /**
     * {@inheritdoc}
     */
    public function prepareRow(Row $row) {
        if (!empty($this->configuration['fetch_all'])) {
            // Get an array of all languages.
            $languages = $this->query()
                ->execute()
                ->fetchAll();
            $row->setSourceProperty('languages', $languages);
        }
        if (!empty($this->configuration['domain_negotiation'])) {
            // Check if domain negotiation is used to be able to fill in the default
            // language domain, which may be empty. In D6, domain negotiation is used
            // when the 'language_negotiation' variable is set to '3', and in D7, when
            // the 'locale_language_negotiation_url_part' variable is set to '1'.
            if ($this->variableGet('language_negotiation', 0) == 3 || $this->variableGet('locale_language_negotiation_url_part', 0) == 1) {
                $row->setSourceProperty('domain_negotiation_used', TRUE);
            }
        }
        return parent::prepareRow($row);
    }

}

Classes

Title Deprecated Summary
Language Plugin annotation @MigrateSource( id = "language", source_module = "locale" )

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