You are here

public static function ParagraphsActions::preRenderParagraphsActions in Paragraphs 8

Pre render callback for #type 'paragraphs_actions'.

Parameters

array $element: Element arrar of a #type 'paragraphs_actions'.

Return value

array The processed element.

File

src/Element/ParagraphsActions.php, line 55

Class

ParagraphsActions
Provides a render element for a paragraphs actions.

Namespace

Drupal\paragraphs\Element

Code

public static function preRenderParagraphsActions(array $element) {
  $element['#attached']['library'][] = 'paragraphs/drupal.paragraphs.actions';
  if (!empty($element['dropdown_actions'])) {
    foreach (Element::children($element['dropdown_actions']) as $key) {
      $dropdown_action =& $element['dropdown_actions'][$key];
      if (isset($dropdown_action['#ajax'])) {
        $dropdown_action = RenderElement::preRenderAjaxForm($dropdown_action);
      }
      if (empty($dropdown_action['#attributes'])) {
        $dropdown_action['#attributes'] = [
          'class' => [
            'paragraphs-dropdown-action',
          ],
        ];
      }
      else {
        $dropdown_action['#attributes']['class'][] = 'paragraphs-dropdown-action';
      }
    }
  }
  return $element;
}