"Fossies" - the Fresh Open Source Software Archive

Member "drupal-8.9.10/core/modules/field/src/Plugin/migrate/process/d7/FieldOptionTranslation.php" (26 Nov 2020, 1314 Bytes) of package /linux/www/drupal-8.9.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "FieldOptionTranslation.php" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 9.0.8_vs_9.1.0-rc1.

    1 <?php
    2 
    3 namespace Drupal\field\Plugin\migrate\process\d7;
    4 
    5 use Drupal\migrate\MigrateExecutableInterface;
    6 use Drupal\migrate\ProcessPluginBase;
    7 use Drupal\migrate\Row;
    8 
    9 /**
   10  * Determines the allowed values translation for select lists.
   11  *
   12  * @MigrateProcessPlugin(
   13  *   id = "d7_field_option_translation",
   14  *   handle_multiples = TRUE
   15  * )
   16  */
   17 class FieldOptionTranslation extends ProcessPluginBase {
   18 
   19   /**
   20    * {@inheritdoc}
   21    *
   22    * Get the field default/mapped settings.
   23    */
   24   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
   25     list($type, $data) = $value;
   26 
   27     $data = unserialize($data);
   28     $allowed_values = '';
   29     $translation_key = $row->getSourceProperty('property');
   30     $i = 0;
   31     if (isset($data['settings']['allowed_values'])) {
   32       $allowed_values = $data['settings']['allowed_values'];
   33       switch ($type) {
   34         case 'list_string':
   35         case 'list_integer':
   36         case 'list_float':
   37         case 'list_text':
   38           if (isset($allowed_values[$translation_key])) {
   39             $allowed_values = ['label' => $row->getSourceProperty('translation')];
   40             break;
   41           }
   42           break;
   43 
   44         default:
   45       }
   46     }
   47     return ["settings.allowed_values.$translation_key", $allowed_values];
   48   }
   49 
   50 }