You are here

public static function ChartDataCollectorTable::tableOperationSubmit in Charts 8.4

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

Submit callback for table add and delete operations.

File

src/Element/ChartDataCollectorTable.php, line 390

Class

ChartDataCollectorTable
Provides a chart data collector table form element.

Namespace

Drupal\charts\Element

Code

public static function tableOperationSubmit(array $form, FormStateInterface $form_state) {
  $triggering_element = $form_state
    ->getTriggeringElement();
  $operation_on = $triggering_element['#operation_on'];
  $operation = $triggering_element['#operation'];
  $length = $operation === 'add' ? -4 : -3;
  $element_parents = array_slice($triggering_element['#parents'], 0, $length);
  if (!$element_parents) {
    $length = $operation == 'add' ? -4 : -3;
    $element_parents = array_slice($triggering_element['#array_parents'], 0, $length);
  }
  $element_state = self::getElementState($element_parents, $form_state);
  $index = $triggering_element['#' . $operation_on . '_index'] ?? NULL;
  if ($operation_on === 'row') {
    $element_state = self::tableRowOperation($element_state, $form_state, $operation, $index);
  }
  else {
    $element_state = self::tableColumnOperation($element_state, $form_state, $operation, $index);
  }
  self::setElementState($element_parents, $form_state, $element_state);
  $form_state
    ->setRebuild();
}