-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathPlugin.php
More file actions
97 lines (84 loc) · 3.91 KB
/
Plugin.php
File metadata and controls
97 lines (84 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace DrupalCodeBuilder\Generator;
use DrupalCodeBuilder\Definition\PropertyListInterface;
use DrupalCodeBuilder\Generator\Render\ClassAnnotation;
use DrupalCodeBuilder\Definition\MergingGeneratorDefinition;
use DrupalCodeBuilder\Definition\PropertyDefinition;
use DrupalCodeBuilder\Definition\VariantGeneratorDefinition;
use CaseConverter\CaseString;
use MutableTypedData\Definition\DefaultDefinition;
/**
* Generator for a plugin.
*/
class Plugin extends BaseGenerator {
/**
* {@inheritdoc}
*/
protected static $dataType = 'mutable';
/**
* {@inheritdoc}
*/
public static function addToGeneratorDefinition(PropertyListInterface $definition) {
// We still need this because ComponentCollector gets a standalone data
// item for this generator.
// TODO: figure this out!
$plugin_data_task = \DrupalCodeBuilder\Factory::getTask('ReportPluginData');
$services_data_task = \DrupalCodeBuilder\Factory::getTask('ReportServiceData');
$definition->setProperties([
'plugin_type' => PropertyDefinition::create('string')
->setLabel('Plugin type')
->setOptionsProvider($plugin_data_task)
// TODO: contains the code to support using the plugin folder name.
// TODO: restore this later, but currently there's no CLI UI for this
// version so not needed yet.
// 'XXprocessing' => function(DataItem $component_data) {
// // Validate the plugin type, and find it if given a folder rather than
// // a type.
// $task_report_plugins = \DrupalCodeBuilder\Factory::getTask('ReportPluginData');
// $plugin_types_data = $task_report_plugins->listPluginData(static::$discoveryType);
// // Try to find the intended plugin type.
// if (isset($plugin_types_data[$component_data->value])) {
// $plugin_data = $plugin_types_data[$component_data->value];
// }
// else {
// // Convert a namespace separator into a directory separator.
// $value = str_replace('\\', '/', $value);
// $plugin_types_data_by_subdirectory = $task_report_plugins->listPluginDataBySubdirectory();
// if (isset($plugin_types_data_by_subdirectory[$value])) {
// $plugin_data = $plugin_types_data_by_subdirectory[$value];
// // Set the plugin ID in the the property.
// $component_data[$property_name] = $plugin_data['type_id'];
// }
// else {
// // Nothing found. Throw exception.
// $discovery_type = static::$discoveryType;
// throw new InvalidInputException("Plugin type {$value} not found in list of {$discovery_type} plugins.");
// }
// }
// // Set the plugin type data.
// // Bit of a cheat, as undeclared data property!
// $component_data['plugin_type_data'] = $plugin_data;
// },
// ];
])
->setVariantMappingProvider($plugin_data_task)
->setVariants([
'annotation' => VariantGeneratorDefinition::create()
->setLabel('Annotation plugin')
->setGenerator('PluginAnnotationDiscovery'),
'attribute' => VariantGeneratorDefinition::create()
->setLabel('Attribute plugin')
->setGenerator('PluginAttributeDiscovery'),
'yaml' => VariantGeneratorDefinition::create()
->setLabel('YAML plugin')
->setGenerator('PluginYamlDiscovery'),
// Special cases. Note that these must be set up in ReportPluginData.
'element_info' => VariantGeneratorDefinition::create()
->setLabel('Validaton constraint')
->setGenerator('PluginRenderElement'),
'validation.constraint' => VariantGeneratorDefinition::create()
->setLabel('Validaton constraint')
->setGenerator('PluginValidationConstraint'),
]);
}
}