public function InlineParagraphsBrowserWidgetTrait::formElement in Paragraphs Browser 8
File
- src/
Plugin/ Field/ FieldWidget/ InlineParagraphsBrowserWidgetTrait.php, line 80 - Paragraphs Previewer widget trait implementation for paragraphs.
Class
- InlineParagraphsBrowserWidgetTrait
- Trait of Plugin implementation of the 'entity_reference paragraphs' widget.
Namespace
Drupal\paragraphs_browser\Plugin\Field\FieldWidgetCode
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
// Call parent function
$element = parent::formElement($items, $delta, $element, $form, $form_state);
// Add styles
$form['#attached']['library'][] = 'paragraphs_browser/modal';
$type = $element['#paragraph_type'];
$current_title = $element['top']['paragraph_type_title']['info']['#markup'];
// Get Paragraph group info
$paragraph_types = \Drupal::entityTypeManager()
->getStorage('paragraphs_browser_type')
->loadMultiple();
foreach ($paragraph_types as $paragraph_type) {
$groups = $paragraph_type
->groupManager();
$group_name = $paragraph_type
->getGroupMap($type);
$group = $groups
->getGroup($group_name);
if ($group) {
$element['top']['paragraph_type_title']['info'] = array(
'#markup' => $current_title,
);
}
}
return $element;
}