Ajax callback for loading the style description for the currently selected style.
array $form: A nested array of form elements comprising the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
array The form element representing the style description.
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;
}