Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / migrate_plus / src / Plugin / migrate / process / Transliteration.php
1 <?php
2
3 namespace Drupal\migrate_plus\Plugin\migrate\process;
4
5 use Drupal\Component\Transliteration\TransliterationInterface;
6 use Drupal\Core\Language\LanguageInterface;
7 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
8 use Drupal\migrate\ProcessPluginBase;
9 use Drupal\migrate\MigrateExecutableInterface;
10 use Drupal\migrate\Row;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
12
13 /**
14  * Transliterates text from Unicode to US-ASCII.
15  *
16  * The transliteration process plugin takes the source value and runs it through
17  * the transliteration service. Letters will have language decorations and
18  * accents removed.
19  *
20  * Example:
21  *
22  * @code
23  * process:
24  *   bar:
25  *     plugin: transliteration
26  *     source: foo
27  * @endcode
28  *
29  * If the value of foo in the source is 'áéí!' then the destination value of
30  * bar will be 'aei!'.
31  *
32  * @see \Drupal\migrate\Plugin\MigrateProcessInterface
33  *
34  * @MigrateProcessPlugin(
35  *   id = "transliteration"
36  * )
37  */
38 class Transliteration extends ProcessPluginBase implements ContainerFactoryPluginInterface {
39
40   /**
41    * The transliteration service.
42    *
43    * @var \Drupal\Component\Transliteration\TransliterationInterface
44    */
45   protected $transliteration;
46
47   /**
48    * Constructs a Transliteration plugin.
49    *
50    * @param array $configuration
51    *   The plugin configuration.
52    * @param string $plugin_id
53    *   The plugin ID.
54    * @param mixed $plugin_definition
55    *   The plugin definition.
56    * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration
57    *   The transliteration service.
58    */
59   public function __construct(array $configuration, $plugin_id, $plugin_definition, TransliterationInterface $transliteration) {
60     parent::__construct($configuration, $plugin_id, $plugin_definition);
61     $this->transliteration = $transliteration;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
68     return new static(
69       $configuration,
70       $plugin_id,
71       $plugin_definition,
72       $container->get('transliteration')
73     );
74   }
75
76   /**
77    * {@inheritdoc}
78    */
79   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
80     return $this->transliteration->transliterate($value, LanguageInterface::LANGCODE_DEFAULT, '_');
81   }
82
83 }