You are here

function paragraphs_add_more_submit in Paragraphs 7

Submit function to add another paragraph.

Parameters

array $form: The form structure array.

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

1 string reference to 'paragraphs_add_more_submit'
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 830
Holds functions for the paragraphs widgets.

Code

function paragraphs_add_more_submit(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));
  $field_name = $element['#field_name'];
  $langcode = $element['#language'];
  $parents = $element['#field_parents'];

  // Increment the items count.
  $field_state = field_form_get_state($parents, $field_name, $langcode, $form_state);
  $field = $field_state['field'];
  if ($field['cardinality'] == FIELD_CARDINALITY_UNLIMITED || $field_state['real_items_count'] < $field['cardinality']) {
    $field_state['items_count']++;
  }
  field_form_set_state($parents, $field_name, $langcode, $form_state, $field_state);
  $form_state['rebuild'] = TRUE;
}