4b01043538a6fe3924fe6c82674d118c26821b3c
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d8 / plugin / migrate / process.twig
1 <?php
2
3 namespace Drupal\{{ machine_name }}\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\MigrateExecutableInterface;
9 use Drupal\migrate\ProcessPluginBase;
10 use Drupal\migrate\Row;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
12
13 /**
14  * Provides {{ plugin_id|article }} plugin.
15  *
16  * Usage:
17  *
18  * @code
19  * process:
20  *   bar:
21  *     plugin: {{ plugin_id }}
22  *     source: foo
23  * @endcode
24  *
25  * @MigrateProcessPlugin(
26  *   id = "{{ plugin_id }}"
27  * )
28  *
29  * @DCG
30  * ContainerFactoryPluginInterface is optional here. If you have no need for
31  * external services just remove it and all other stuff except transform()
32  * method.
33  */
34 class {{ class }} extends ProcessPluginBase implements ContainerFactoryPluginInterface {
35
36   /**
37    * The transliteration service.
38    *
39    * @var \Drupal\Component\Transliteration\TransliterationInterface
40    */
41   protected $transliteration;
42
43   /**
44    * Constructs {{ class|article }} plugin.
45    *
46    * @param array $configuration
47    *   The plugin configuration.
48    * @param string $plugin_id
49    *   The plugin ID.
50    * @param mixed $plugin_definition
51    *   The plugin definition.
52    * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration
53    *   The transliteration service.
54    */
55   public function __construct(array $configuration, $plugin_id, $plugin_definition, TransliterationInterface $transliteration) {
56     parent::__construct($configuration, $plugin_id, $plugin_definition);
57     $this->transliteration = $transliteration;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
64     return new static(
65       $configuration,
66       $plugin_id,
67       $plugin_definition,
68       $container->get('transliteration')
69     );
70   }
71
72   /**
73    * {@inheritdoc}
74    */
75   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
76     return $this->transliteration->transliterate($value, LanguageInterface::LANGCODE_DEFAULT);
77   }
78
79 }