Skip to content

Commit 1a9a48e

Browse files
LOBsTerrjmolivas
authored andcommitted
Add additional information for field type plugin, field widget plugin and field formatter plugin (#3809)
1 parent 3917092 commit 1a9a48e

File tree

1 file changed

+103
-5
lines changed

1 file changed

+103
-5
lines changed

src/Command/Debug/PluginCommand.php

+103-5
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,117 @@ protected function execute(InputInterface $input, OutputInterface $output)
107107
$this->trans('commands.debug.plugin.table-headers.definition-key'),
108108
$this->trans('commands.debug.plugin.table-headers.definition-value')
109109
];
110+
111+
$tableRows = $this->prepareTableRows($definition);
112+
113+
ksort($tableRows);
114+
$this->getIo()->table($tableHeader, array_values($tableRows));
115+
116+
$this->displayPluginData($pluginType, $pluginId);
117+
return true;
118+
}
119+
120+
/**
121+
* Displays additional plugin data.
122+
*
123+
* @param string $pluginType
124+
* Plugin type.
125+
* @param $pluginId
126+
* Plugin ID.
127+
*/
128+
protected function displayPluginData($pluginType, $pluginId) {
129+
switch ($pluginType) {
130+
case 'field.field_type':
131+
$this->getFieldTypeData($pluginId);
132+
break;
133+
134+
case 'field.formatter':
135+
$this->getFieldFormatterData($pluginId);
136+
break;
137+
138+
case 'field.widget':
139+
$this->getFieldWidgetData($pluginId);
140+
break;
141+
}
142+
}
143+
144+
/**
145+
* Get field type plugin additional data.
146+
*
147+
* @param string $pluginId
148+
* Plugin ID.
149+
*/
150+
protected function getFieldTypeData($pluginId) {
151+
$settings = $this->container->get('plugin.manager.field.field_type')->getDefaultFieldSettings($pluginId);
152+
$this->displaySettingsTable($settings);
153+
}
154+
155+
/**
156+
* Get field formatter plugin additional data.
157+
*
158+
* @param string $pluginId
159+
* Plugin ID.
160+
*/
161+
protected function getFieldFormatterData($pluginId) {
162+
$settings = $this->container->get('plugin.manager.field.formatter')->getDefaultSettings($pluginId);
163+
$this->displaySettingsTable($settings);
164+
}
165+
166+
/**
167+
* Get field widget plugin additional data.
168+
*
169+
* @param string $pluginId
170+
* Plugin ID.
171+
*/
172+
protected function getFieldWidgetData($pluginId) {
173+
$settings = $this->container->get('plugin.manager.field.widget')->getDefaultSettings($pluginId);
174+
$this->displaySettingsTable($settings);
175+
}
176+
177+
/**
178+
* Displays settings table.
179+
*
180+
* @param array $settings
181+
* Settings array.
182+
*/
183+
protected function displaySettingsTable($settings) {
184+
$tableHeader = [
185+
$this->trans('commands.debug.plugin.table-headers.setting'),
186+
$this->trans('commands.debug.plugin.table-headers.definition-value')
187+
];
188+
189+
$tableRows = $this->prepareTableRows($settings);
190+
191+
if (count($tableRows) > 0) {
192+
$this->getIo()->newLine(1);
193+
$this->getIo()->info(
194+
$this->trans('commands.debug.plugin.messages.plugin-info')
195+
);
196+
$this->getIo()->table($tableHeader, array_values($tableRows));
197+
}
198+
}
199+
200+
/**
201+
* Prepare table rows.
202+
*
203+
* @param array $items
204+
* Data array.
205+
*
206+
* @return array
207+
* Table rows.
208+
*/
209+
protected function prepareTableRows($items) {
110210
$tableRows = [];
111-
foreach ($definition as $key => $value) {
211+
foreach ($items as $key => $value) {
112212
if (is_object($value) && method_exists($value, '__toString')) {
113213
$value = (string) $value;
114214
} elseif (is_array($value) || is_object($value)) {
115215
$value = Yaml::dump($value);
116216
} elseif (is_bool($value)) {
117217
$value = ($value) ? 'TRUE' : 'FALSE';
118218
}
119-
$tableRows[$key] = [$key, $value];
219+
$tableRows[] = [$key, $value];
120220
}
121-
ksort($tableRows);
122-
$this->getIo()->table($tableHeader, array_values($tableRows));
123-
return true;
221+
return $tableRows;
124222
}
125223
}

0 commit comments

Comments
 (0)