public static function ParagraphsFeatures::registerFormWidgetFeatures in Paragraphs Features 2.x
Same name and namespace in other branches
- 8 src/ParagraphsFeatures.php \Drupal\paragraphs_features\ParagraphsFeatures::registerFormWidgetFeatures()
Register features for paragraphs field widget.
Parameters
array $elements: Render array for the field widget.
\Drupal\paragraphs\Plugin\Field\FieldWidget\ParagraphsWidget $widget: Field widget object.
string $fieldWrapperId: Field Wrapper ID, usually provided by ::getWrapperId().
1 call to ParagraphsFeatures::registerFormWidgetFeatures()
File
- src/
ParagraphsFeatures.php, line 58
Class
- ParagraphsFeatures
- Paragraphs features class.
Namespace
Drupal\paragraphs_featuresCode
public static function registerFormWidgetFeatures(array &$elements, ParagraphsWidget $widget, $fieldWrapperId) {
if (!in_array(\Drupal::theme()
->getActiveTheme()
->getName(), [
'claro',
'gin',
])) {
return;
}
foreach (static::$availableFeatures as $feature) {
if ($widget
->getThirdPartySetting('paragraphs_features', $feature)) {
$elements['add_more']['#attached']['library'][] = 'paragraphs_features/' . $feature;
$elements['add_more']['#attached']['drupalSettings']['paragraphs_features'][$feature][$fieldWrapperId] = TRUE;
$elements['add_more']['#attached']['drupalSettings']['paragraphs_features'][$feature]['_path'] = drupal_get_path('module', 'paragraphs_features');
}
}
$elements['add_more']['#attached']['library'][] = 'paragraphs_features/drupal.paragraphs_features.scroll_to_element';
foreach (Element::children($elements['add_more']) as $button) {
$elements['add_more'][$button]['#ajax']['callback'] = [
static::class,
'addMoreAjax',
];
}
// This feature is not part of of the foreach above, since it is not a
// javascript feature, it is a direct modification of the form. If the
// feature is not set, it defaults back to paragraphs behavior.
if (!empty($elements['header_actions']['dropdown_actions']['dragdrop_mode'])) {
$elements['header_actions']['dropdown_actions']['dragdrop_mode']['#access'] = (bool) $widget
->getThirdPartySetting('paragraphs_features', 'show_drag_and_drop', TRUE);
}
}