public function GutenbergPluginManager::injectPluginSettingsForm in Gutenberg 8
Same name and namespace in other branches
- 8.2 src/GutenbergPluginManager.php \Drupal\gutenberg\GutenbergPluginManager::injectPluginSettingsForm()
Injects the Gutenberg plugins settings forms as a vertical tabs subform.
Parameters
array &$form: A reference to an associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
\Drupal\editor\Entity\Editor $editor: A configured text editor object.
File
- src/
GutenbergPluginManager.php, line 43
Class
- GutenbergPluginManager
- Provides a Gutenberg Plugin plugin manager.
Namespace
Drupal\gutenbergCode
public function injectPluginSettingsForm(array &$form, FormStateInterface $form_state, Editor $editor) {
$definitions = $this
->getDefinitions();
foreach (array_keys($definitions) as $plugin_id) {
$plugin = $this
->createInstance($plugin_id);
if ($plugin instanceof GutenbergPluginConfigurableInterface) {
$plugin_settings_form = [];
$form['plugins'][$plugin_id] = [
'#type' => 'details',
'#title' => $definitions[$plugin_id]['label'],
'#open' => TRUE,
'#group' => 'editor][settings][plugin_settings',
'#attributes' => [
'data-gutenberg-plugin-id' => $plugin_id,
],
];
// Provide enough metadata for the drupal.ckeditor.admin library to
// allow it to automatically show/hide the vertical tab containing the
// settings for this plugin. Only do this if it's a CKEditor plugin that
// just provides buttons, don't do this if it's a contextually enabled
// CKEditor plugin. After all, in the latter case, we can't know when
// its settings should be shown!
$form['plugins'][$plugin_id] += $plugin
->settingsForm($plugin_settings_form, $form_state, $editor);
}
}
}