You are here

function template_preprocess_paragraphs_sets_add_dialog in Paragraphs Sets 8.2

Same name and namespace in other branches
  1. 8 paragraphs_sets.module \template_preprocess_paragraphs_sets_add_dialog()

Prepares variables for modal form add widget template.

Default template: paragraphs-sets-add-dialog.html.twig.

Parameters

array $variables: An associative array containing:

  • buttons: An array of buttons to display in the modal form.

File

./paragraphs_sets.module, line 532
Main functions of paragraphs_sets.module.

Code

function template_preprocess_paragraphs_sets_add_dialog(array &$variables) {

  // Define variables for the template.
  $variables += [
    'buttons' => [],
    'buttons_title' => $variables['element']['#widget_title_plural'],
    'sets' => [],
    'sets_title' => t('@title sets', [
      '@title' => $variables['element']['#widget_title'],
    ]),
  ];
  foreach (Element::children($variables['element']) as $key) {
    if ($key == 'add_modal_form_area') {

      // $add variable for the add button.
      $variables['add'] = $variables['element'][$key];
    }
    elseif (strpos($key, 'append_selection_button_') === 0) {

      // Buttons for the paragraph sets in the modal form.
      $variables['sets'][$key] = $variables['element'][$key];
    }
    else {

      // Buttons for the paragraph types in the modal form.
      $variables['buttons'][$key] = $variables['element'][$key];
    }
  }
}