function paragraphs_features_paragraphs_widget_actions_alter in Paragraphs Features 8
Same name and namespace in other branches
- 2.x paragraphs_features.module \paragraphs_features_paragraphs_widget_actions_alter()
Implements hook_paragraphs_widget_actions_alter().
File
- ./
paragraphs_features.module, line 48 - Contains hooks for Paragraphs Feature module.
Code
function paragraphs_features_paragraphs_widget_actions_alter(array &$widget_actions, array &$context) {
/** @var \Drupal\paragraphs\Entity\Paragraph $paragraphs_entity */
$paragraphs_entity = $context['paragraphs_entity'];
foreach ($widget_actions as $grouping => $buttons) {
foreach ($buttons as $button_id => $button_element) {
if ($button_id === 'remove_button') {
$widget_actions[$grouping][$button_id]['#attributes']['data-paragraphs-split-text-type'] = $paragraphs_entity
->getType();
break 2;
}
}
}
/* Render single option for dropdown as button. */
// Get configuration setting for reducing dropdown to button on single option.
$dropdown_to_button = \Drupal::config('paragraphs_features.settings')
->get('dropdown_to_button');
if (!$dropdown_to_button) {
return;
}
// "Add above" feature is added by JS and we don't have it in actions list.
if ($context['element']['top']['#attributes']['class'] && in_array('add-above-on', $context['element']['top']['#attributes']['class'])) {
return;
}
$visible_actions = Element::getVisibleChildren($widget_actions['dropdown_actions']);
if (count($visible_actions) === 1) {
$visible_actions = reset($visible_actions);
$widget_actions['actions'][$visible_actions] = $widget_actions['dropdown_actions'][$visible_actions];
$widget_actions['dropdown_actions'] = [];
}
}