class Language

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

Drupal 6/7 language source from database.

Available configuration keys:

  • fetch_all: (optional) If not empty, all source languages are retrieved and available as "languages" source property. Each language is an array with the same structure as a source row.
  • domain_negotiation: (optional) If not empty and domain negotiation is enabled in the source database, the "domain_negotiation_used" source property is set to TRUE.

Example:


plugin: language
fetch_all: true
domain_negotiation: true

In this example, available languages are retrieved from the source database. Given that fetch_all and domain_negotiation are specified, each row also contains all languages and the domain negotiation status, if enabled.

For additional configuration keys, refer to the parent classes.

Plugin annotation


@MigrateSource(
  id = "language",
  source_module = "locale"
)

Hierarchy

Expanded class hierarchy of Language

See also

\Drupal\migrate\Plugin\migrate\source\SqlBase

\Drupal\migrate\Plugin\migrate\source\SourcePluginBase

393 string references to 'Language'
AccountSettingsForm::buildForm in core/modules/user/src/AccountSettingsForm.php
block.block.umami_languageswitcher.yml in core/profiles/demo_umami/config/install/block.block.umami_languageswitcher.yml
core/profiles/demo_umami/config/install/block.block.umami_languageswitcher.yml
BlockContentTypeForm::form in core/modules/block_content/src/BlockContentTypeForm.php
BlockForm::buildVisibilityInterface in core/modules/block/src/BlockForm.php
Helper function for building the visibility UI form.
BlockLanguageTest::testLanguageBlockVisibilityLanguageDelete in core/modules/block/tests/src/Functional/BlockLanguageTest.php
Tests if the visibility settings are removed if the language is deleted.

... See full list

File

core/modules/language/src/Plugin/migrate/source/Language.php, line 41

Namespace

Drupal\language\Plugin\migrate\source
View source
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);
  }

}

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