Returns the metadata for a set of fields.
Given a list of field 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.
\Symfony\Component\HttpFoundation\JsonResponse The JSON response.
public function metadata(Request $request) {
$fields = $request->request
->get('fields');
if (!isset($fields)) {
throw new NotFoundHttpException();
}
$metadataGenerator = $this->container
->get('edit.metadata.generator');
$metadata = array();
foreach ($fields as $field) {
list($entity_type, $entity_id, $field_name, $langcode, $view_mode) = explode('/', $field);
// Load the entity.
if (!$entity_type || !entity_get_info($entity_type)) {
throw new NotFoundHttpException();
}
$entity = entity_load($entity_type, $entity_id);
if (!$entity) {
throw new NotFoundHttpException();
}
// Validate the field name and language.
if (!$field_name || !($instance = field_info_instance($entity
->entityType(), $field_name, $entity
->bundle()))) {
throw new NotFoundHttpException();
}
if (!$langcode || field_valid_language($langcode) !== $langcode) {
throw new NotFoundHttpException();
}
$metadata[$field] = $metadataGenerator
->generate($entity, $instance, $langcode, $view_mode);
}
return new JsonResponse($metadata);
}