You are here

public function AjaxController::getResults in Paragraphs table 8

1 call to AjaxController::getResults()
AjaxController::json in src/Controller/AjaxController.php
Return output JSON object value.

File

src/Controller/AjaxController.php, line 143

Class

AjaxController
Returns responses for paragraphs item routes.

Namespace

Drupal\paragraphs_table\Controller

Code

public function getResults($entities, $components, $setting = []) {
  $data = FALSE;
  foreach ($entities as $delta => $entity) {
    $table_entity = $this->renderBuild
      ->build($entity);
    $objectData = new \stdClass();
    foreach ($components as $field_name => $field) {
      $table_entity[$field_name]['#label_display'] = 'hidden';
      $value = trim(strip_tags(render($table_entity[$field_name])));
      if (in_array($this->fieldsDefinition[$field_name]
        ->getType(), [
        'integer',
        'list_integer',
        'number_integer',
      ])) {
        $value = (int) $value;
      }
      if (in_array($this->fieldsDefinition[$field_name]
        ->getType(), [
        'boolean',
      ])) {
        $list_value = $table_entity[$field_name]["#items"]
          ->getValue();
        $value = (int) $list_value[0]['value'];
      }
      if (in_array($this->fieldsDefinition[$field_name]
        ->getType(), [
        'decimal',
        'list_decimal',
        'number_decimal',
        'float',
        'list_float',
        'number_float',
      ])) {
        $value = (double) $value;
      }
      if (!is_numeric($value) && empty($value) && !empty($setting["empty_cell_value"])) {
        $value = $setting["empty_cell_value"];
      }
      $objectData->{$field_name} = $value;
    }
    if (!empty($setting['show_operation'])) {
      $parent = $entity
        ->getParentEntity();
      $destination = implode('/', [
        $parent
          ->getEntityTypeId(),
        $parent
          ->id(),
      ]);
      $objectData->operation = $this
        ->paragraphsTableLinksAction($entity
        ->id(), $destination);
    }
    $data[$delta] = $objectData;
  }
  return $data;
}