You are here

function paragraphs_add_more_js in Paragraphs 7

Ajax callback in response to a new empty widget being added to the form.

This returns the new page content to replace the page content made obsolete by the form submission.

Parameters

array $form: The form structure array.

array $form_state: An associative array containing the current state of the form.

See also

field_add_more_submit()

1 string reference to 'paragraphs_add_more_js'
paragraphs_field_multiple_value_form in ./paragraphs.field_widget.inc
Special handling to create form elements for multiple values.

File

./paragraphs.field_widget.inc, line 920
Holds functions for the paragraphs widgets.

Code

function paragraphs_add_more_js(array $form, array $form_state) {
  $button = $form_state['triggering_element'];

  // Go one level up in the form, to the widgets container.
  $element = drupal_array_get_nested_value($form, array_slice($button['#array_parents'], 0, -2));

  // Add a DIV around the delta receiving the Ajax effect.
  $delta = $element['#max_delta'];
  $element[$delta]['#prefix'] = '<div class="ajax-new-content">' . (isset($element[$delta]['#prefix']) ? $element[$delta]['#prefix'] : '');
  $element[$delta]['#suffix'] = (isset($element[$delta]['#suffix']) ? $element[$delta]['#suffix'] : '') . '</div>';
  return $element;
}