You are here

public function QuickEditImageController::getInfo in Drupal 10

Returns JSON representing an image field's metadata.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity of which an image field is being rendered.

string $field_name: The name of the (image) field that is being rendered

string $langcode: The language code of the field that is being rendered.

string $view_mode_id: The view mode of the field that is being rendered.

Return value

\Drupal\Core\Cache\CacheableJsonResponse The JSON response.

1 string reference to 'QuickEditImageController::getInfo'
quickedit.routing.yml in core/modules/quickedit/quickedit.routing.yml
core/modules/quickedit/quickedit.routing.yml

File

core/modules/quickedit/src/Controller/QuickEditImageController.php, line 187

Class

QuickEditImageController
Returns responses for our image routes.

Namespace

Drupal\quickedit\Controller

Code

public function getInfo(EntityInterface $entity, $field_name, $langcode, $view_mode_id) {
  $field = $this
    ->getField($entity, $field_name, $langcode);
  $settings = $field
    ->getFieldDefinition()
    ->getSettings();
  $info = [
    'alt' => $field->alt,
    'title' => $field->title,
    'alt_field' => $settings['alt_field'],
    'title_field' => $settings['title_field'],
    'alt_field_required' => $settings['alt_field_required'],
    'title_field_required' => $settings['title_field_required'],
  ];
  $response = new CacheableJsonResponse($info);
  $response
    ->addCacheableDependency($entity);
  return $response;
}