You are here

public function AjaxController::getTable in Paragraphs table 8

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

File

src/Controller/AjaxController.php, line 192

Class

AjaxController
Returns responses for paragraphs item routes.

Namespace

Drupal\paragraphs_table\Controller

Code

public function getTable($entities, $components, $setting = []) {
  $data = FALSE;
  foreach ($entities as $delta => $entity) {
    $table_entity = $this->renderBuild
      ->build($entity);
    foreach ($components as $field_name => $field) {
      $table_entity[$field_name]['#label_display'] = 'hidden';
      $value = trim(render($table_entity[$field_name]));
      if (!is_numeric($value) && empty($value) && !empty($setting["empty_cell_value"])) {
        $value = $setting["empty_cell_value"];
      }
      $data[$delta][] = $value;
    }
    if (!empty($setting['show_operation'])) {
      $parent = $entity
        ->getParentEntity();
      $destination = implode('/', [
        $parent
          ->getEntityTypeId(),
        $parent
          ->id(),
      ]);
      $data[$delta]['operation'] = $this
        ->paragraphsTableLinksAction($entity
        ->id(), $destination);
    }
  }
  return $data;
}