You are here

protected function AmpPrepareMetadataJson::prepareContentImage in Accelerated Mobile Pages (AMP) 8

Prepare content image information.

1 call to AmpPrepareMetadataJson::prepareContentImage()
AmpPrepareMetadataJson::prepareMetadataJson in src/Utility/AmpPrepareMetadataJson.php
Prepares a metadata array to be ready for JSON conversion.

File

src/Utility/AmpPrepareMetadataJson.php, line 214

Class

AmpPrepareMetadataJson
Class AmpPrepareMetadataJson

Namespace

Drupal\amp\Utility

Code

protected function prepareContentImage() {
  if (isset($this->ampMetadataSettings['content_image_token']) && !empty($this->ampMetadataSettings['content_image_token'])) {
    $content_image_uri = $this
      ->getUriFromImageTokenString($this->ampMetadataSettings['content_image_token']);
    if (!empty($content_image_uri)) {
      $content_image_style_id = '';
      if (isset($this->ampMetadataSettings['content_image_style_id']) && !empty($this->ampMetadataSettings['content_image_style_id'])) {
        $content_image_style_id = $this->ampMetadataSettings['content_image_style_id'];
      }
      $content_image_info = $this
        ->getImageInformation($content_image_uri, $content_image_style_id);
      if (!empty($content_image_info)) {
        $this->ampPreparedMetadataJson['image'] = [
          '@type' => 'ImageObject',
          'url' => $content_image_info['url'],
          'width' => $content_image_info['width'],
          'height' => $content_image_info['height'],
        ];
      }
    }
  }
}