public QuickEditController::metadata(Request $request)
Returns the metadata for a set of fields.
Given a list of field quick edit IDs as POST parameters, run access checks on the entity and field level to determine whether the current user may edit them. Also retrieves other metadata.
Return value
\Symfony\Component\HttpFoundation\JsonResponse The JSON response.
File
- core/modules/quickedit/src/QuickEditController.php, line 94
Class
- QuickEditController
- Returns responses for Quick Edit module routes.
Namespace
Drupal\quickedit
Code
public function metadata(Request $request) { $fields = $request->request->get('fields'); if (!isset($fields)) { throw new NotFoundHttpException(); } $entities = $request->request->get('entities'); $metadata = array(); foreach ($fields as $field) { list($entity_type, $entity_id, $field_name, $langcode, $view_mode) = explode('/', $field); // Load the entity. if (!$entity_type || !$this->entityManager()->getDefinition($entity_type)) { throw new NotFoundHttpException(); } $entity = $this->entityManager()->getStorage($entity_type)->load($entity_id); if (!$entity) { throw new NotFoundHttpException(); } // Validate the field name and language. if (!$field_name || !$entity->hasField($field_name)) { throw new NotFoundHttpException(); } if (!$langcode || !$entity->hasTranslation($langcode)) { throw new NotFoundHttpException(); } $entity = $entity->getTranslation($langcode); // If the entity information for this field is requested, include it. $entity_id = $entity->getEntityTypeId() . '/' . $entity_id; if (is_array($entities) && in_array($entity_id, $entities) && !isset($metadata[$entity_id])) { $metadata[$entity_id] = $this->metadataGenerator->generateEntityMetadata($entity); } $metadata[$field] = $this->metadataGenerator->generateFieldMetadata($entity->get($field_name), $view_mode); } return new JsonResponse($metadata); }
Please login to continue.