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

Breadcrumb

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

function LanguageNegotiation::transform

Overrides ProcessPluginBase::transform

File

core/modules/language/src/Plugin/migrate/process/LanguageNegotiation.php, line 23

Class

LanguageNegotiation
Processes the arrays for the language types' negotiation methods and weights.

Namespace

Drupal\language\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $new_value = [
        'enabled' => [],
        'method_weights' => [],
    ];
    if (!is_array($value)) {
        throw new MigrateException('The input should be an array');
    }
    // If no weights are provided, use the keys by flipping the array.
    if (empty($value[1])) {
        $new_value['enabled'] = array_flip(array_map([
            $this,
            'mapNewMethods',
        ], array_keys($value[0])));
        unset($new_value['method_weights']);
    }
    else {
        foreach ($value[1] as $method => $weight) {
            $new_method = $this->mapNewMethods($method);
            $new_value['method_weights'][$new_method] = $weight;
            if (in_array($method, array_keys($value[0]))) {
                $new_value['enabled'][$new_method] = $weight;
            }
        }
    }
    return $new_value;
}

API Navigation

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