You are here

protected function D3ViewsDataMapping::formRepeatedRow in d3.js 7

1 call to D3ViewsDataMapping::formRepeatedRow()
D3ViewsDataMapping::formRepeated in modules/d3_views/includes/D3ViewsDataMapping.inc

File

modules/d3_views/includes/D3ViewsDataMapping.inc, line 188

Class

D3ViewsDataMapping

Code

protected function formRepeatedRow(&$form, $form_state, $key, $k = NULL) {
  $library = $this->library
    ->value();
  $fields =& $form['fields'];
  $f = $k ? $library['views']['fields'][$key][$k] : $library['views']['fields'][$key];
  $options = $this->plugin
    ->getFieldOptions($form_state);
  $x = 0;

  // Loop through the values set in options.
  do {
    $default_values = $this->plugin
      ->getDefaultValues($key . $x, $k, $form_state);
    $this
      ->formRow($fields[$key . $x], $f, $form_state, $default_values);
    $x++;
  } while (isset($options[$key . $x]));

  // Delete the original row that hasn't been concatenated with a integer.
  unset($fields[$key]);

  // If there is only one value and it is empty, that means they haven't set anything yet.
  if ($x == 1 && (empty($default_values->field) || $default_values->field == '_none')) {
    return;
  }

  // Add an additional row if the previous row is true.
  if ($default_values->field && $default_values->field != '__none') {

    // Should always return a blank value.
    $default_values = $this->plugin
      ->getDefaultValues($key . $x, $k, $form_state);
    $this
      ->formRow($fields[$key . $x], $f, $form_state, $default_values);
  }
  else {

    // If the previous row is false, find any other straggelers.
    $count = 0;
    $x--;
    while (empty($options[$key . $x]['field']) || $options[$key . $x]['field'] == '__none') {

      // If they just initiated it, break out.
      if ($count > 0) {
        unset($fields[$key . ($x + 1)]);
      }
      $count++;
      $x--;
    }
  }
}