DefaultLangcode.php

Same filename in other branches
  1. 9 core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php
  2. 10 core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php
  3. 11.x core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php

Namespace

Drupal\language\Plugin\migrate\destination

File

core/modules/language/src/Plugin/migrate/destination/DefaultLangcode.php

View source
<?php

namespace Drupal\language\Plugin\migrate\destination;

use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\migrate\MigrateException;
use Drupal\migrate\Plugin\migrate\destination\Config;
use Drupal\migrate\Row;

/**
 * Provides a destination plugin for the default langcode config.
 *
 * @MigrateDestination(
 *   id = "default_langcode"
 * )
 */
class DefaultLangcode extends Config {
    
    /**
     * {@inheritdoc}
     */
    public function import(Row $row, array $old_destination_id_values = []) {
        $destination = $row->getDestination();
        $langcode = $destination['default_langcode'];
        // Check if the language exists.
        if (ConfigurableLanguage::load($langcode) === NULL) {
            throw new MigrateException("The language '{$langcode}' does not exist on this site.");
        }
        $this->config
            ->set('default_langcode', $destination['default_langcode']);
        $this->config
            ->save();
        return [
            $this->config
                ->getName(),
        ];
    }

}

Classes

Title Deprecated Summary
DefaultLangcode Provides a destination plugin for the default langcode config.

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