X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FCommand%2FDrupal_8%2FPluginManager.php;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FCommand%2FDrupal_8%2FPluginManager.php;h=c80bb0b36525335cb5bc76808affca2e6999e08b;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/PluginManager.php b/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/PluginManager.php new file mode 100644 index 000000000..c80bb0b36 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_8/PluginManager.php @@ -0,0 +1,111 @@ +setValidator(function ($value) { + if (!preg_match('/^[a-z][a-z0-9_\.]*[a-z0-9]$/', $value)) { + throw new \UnexpectedValueException('The value is not correct machine name.'); + } + return $value; + }); + + $discovery_types = [ + 'annotation' => 'Annotation', + 'yaml' => 'YAML', + 'hook' => 'Hook', + ]; + $choices = Utils::prepareChoices($discovery_types); + $questions['discovery'] = new ChoiceQuestion('Discovery type', $choices, 'Annotation'); + + $vars = &$this->collectVars($input, $output, $questions); + + $vars['class_prefix'] = Utils::camelize($vars['plugin_type']); + $vars['discovery'] = array_search($vars['discovery'], $discovery_types); + + $common_files = [ + 'model.services.yml', + 'src/ExampleInterface.php', + 'src/ExamplePluginManager.php', + ]; + + $files = []; + switch ($vars['discovery']) { + case 'annotation': + $files = [ + 'src/Annotation/Example.php', + 'src/ExamplePluginBase.php', + 'src/Plugin/Example/Foo.php', + ]; + break; + + case 'yaml': + $files = [ + 'model.examples.yml', + 'src/ExampleDefault.php', + ]; + break; + + case 'hook': + $files = [ + 'model.module', + 'src/ExampleDefault.php', + ]; + break; + } + + $files = array_merge($common_files, $files); + + $templates_path = 'd8/plugin-manager/' . $vars['discovery'] . '/'; + + $path_placeholders = ['model', 'Example', 'examples']; + $path_replacements = [ + $vars['machine_name'], + $vars['class_prefix'], + Utils::pluralize($vars['plugin_type']), + ]; + + foreach ($files as $file) { + $asset = $this->addFile() + ->path(str_replace($path_placeholders, $path_replacements, $file)) + ->template($templates_path . $file . '.twig'); + if ($file === 'model.services.yml') { + $asset->action('append')->headerSize(1); + } + elseif ($file == 'model.module') { + $asset + ->action('append') + ->headerTemplate('d8/file-docs/module.twig') + ->headerSize(7); + } + } + } + +}