You are here

function template_preprocess_paragraphs_sets_add_dialog in Paragraphs Sets 8

Same name and namespace in other branches
  1. 8.2 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 156
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']['#buttons_title'],
    'sets' => [],
    'sets_title' => t('Paragraph Sets'),
  ];
  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];
    }
  }
}