function QuickEditImageController::getInfo

Same name in this branch
  1. 9 core/modules/image/src/Controller/QuickEditImageController.php \Drupal\image\Controller\QuickEditImageController::getInfo()
Same name in other branches
  1. 8.9.x core/modules/image/src/Controller/QuickEditImageController.php \Drupal\image\Controller\QuickEditImageController::getInfo()

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.