public static function ParagraphsStylePlugin::ajaxStyleSelect in Paragraphs Collection 8
Ajax callback for loading the style description for the currently selected style.
Parameters
array $form: A nested array of form elements comprising the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form element representing the style description.
File
- src/
Plugin/ paragraphs/ Behavior/ ParagraphsStylePlugin.php, line 320
Class
- ParagraphsStylePlugin
- Provides style selection plugin.
Namespace
Drupal\paragraphs_collection\Plugin\paragraphs\BehaviorCode
public static function ajaxStyleSelect(array $form, FormStateInterface $form_state) {
// Gets the style description accordingly.
$select = $form_state
->getTriggeringElement();
$style_discovery = \Drupal::getContainer()
->get('paragraphs_collection.style_discovery');
$styles = $style_discovery
->getStyles();
$description = '';
if (isset($styles[$select['#value']]['description'])) {
$description = $styles[$select['#value']]['description'];
}
// Gets the complete behavior plugin form.
$return_form = NestedArray::getValue($form, array_slice($select['#array_parents'], 0, -2));
$return_form['style_wrapper']['style_description']['#markup'] = $description;
return $return_form;
}