public function AjaxController::getData in Paragraphs table 8
1 call to AjaxController::getData()
- AjaxController::json in src/
Controller/ AjaxController.php - Return output JSON object value.
File
- src/
Controller/ AjaxController.php, line 216
Class
- AjaxController
- Returns responses for paragraphs item routes.
Namespace
Drupal\paragraphs_table\ControllerCode
public function getData($entities, $components, $setting = []) {
$data = FALSE;
$header = [];
foreach ($components as $field_name => $field) {
$header[] = $field['title'];
}
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(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"];
}
$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);
}
}
array_unshift($data, $header);
return $data;
}