You are here

private static function ChartDataCollectorTable::tableColumnOperation in Charts 8.4

Same name and namespace in other branches
  1. 5.0.x src/Element/ChartDataCollectorTable.php \Drupal\charts\Element\ChartDataCollectorTable::tableColumnOperation()

Performs add or delete operation on the table column.

Parameters

array $element_state: The element state storage.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

string $op: The operation.

null|int $index: The column index.

Return value

array The updated element state storage.

1 call to ChartDataCollectorTable::tableColumnOperation()
ChartDataCollectorTable::tableOperationSubmit in src/Element/ChartDataCollectorTable.php
Submit callback for table add and delete operations.

File

src/Element/ChartDataCollectorTable.php, line 633

Class

ChartDataCollectorTable
Provides a chart data collector table form element.

Namespace

Drupal\charts\Element

Code

private static function tableColumnOperation(array $element_state, FormStateInterface $form_state, $op, $index = NULL) {
  if ($op === 'delete') {
    foreach ($element_state['data_collector_table'] as $row_key => $columns) {
      $row = $element_state['data_collector_table'][$row_key];
      if (count(self::excludeWeightColumnFromRow($row)) === 1) {
        $element_state['data_collector_table'][$row_key][$index]['data'] = '';
      }
      else {
        unset($element_state['data_collector_table'][$row_key][$index]);
      }
    }
  }
  else {
    foreach ($element_state['data_collector_table'] as $row_key => $columns) {
      $element_state['data_collector_table'][$row_key][]['data'] = '';
    }
  }
  return $element_state;
}