protected function AjaxController::getComponents in Paragraphs table 8
1 call to AjaxController::getComponents()
- AjaxController::json in src/
Controller/ AjaxController.php - Return output JSON object value.
File
- src/
Controller/ AjaxController.php, line 116
Class
- AjaxController
- Returns responses for paragraphs item routes.
Namespace
Drupal\paragraphs_table\ControllerCode
protected function getComponents($paragraph_field, $view_mode = 'default') {
$field_definition = $paragraph_field
->getFieldDefinition();
$targetBundle = array_key_first($field_definition
->getSetting("handler_settings")["target_bundles"]);
$targetType = $field_definition
->getSetting('target_type');
$fieldsDefinitions = $this
->entityTypeManager()
->getStorage($targetType)
->create([
'type' => $targetBundle,
])
->getFieldDefinitions();
$repository = \Drupal::service('entity_display.repository');
$viewDisplay = $repository
->getViewDisplay($targetType, $targetBundle, $view_mode);
$components = $viewDisplay
->getComponents();
uasort($components, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
foreach ($components as $field_name => $component) {
if ($fieldsDefinitions[$field_name] instanceof FieldConfigInterface) {
$this->fieldsDefinition[$field_name] = $fieldsDefinitions[$field_name];
$components[$field_name]['title'] = $fieldsDefinitions[$field_name]
->getLabel();
}
}
$storage = $this
->entityTypeManager()
->getStorage('entity_view_display');
$this->renderBuild = $storage
->load(implode('.', [
$targetType,
$targetBundle,
$view_mode,
]));
return $components;
}