You are here

protected function D3ViewsDataMapping::formRepeatedSubRow in d3.js 7

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

File

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

Class

D3ViewsDataMapping

Code

protected function formRepeatedSubRow(&$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, $k . $x, $form_state);
    $this
      ->formRow($fields[$key][$k . $x], $f, $form_state, $default_values);
    $x++;
  } while (isset($options[$key][$k . $x]));

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

  // 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, $k . $x, $form_state);
    $this
      ->formRow($fields[$key][$k . $x], $f, $form_state, $default_values);
  }
  else {

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

        // Unset the previous one.
        unset($fields[$key][$k . ($x + 1)]);
      }
      $count++;
      $x--;
    }
  }
}