You are here

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

Prepare publisher information.

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

File

src/Utility/AmpPrepareMetadataJson.php, line 251

Class

AmpPrepareMetadataJson
Class AmpPrepareMetadataJson

Namespace

Drupal\amp\Utility

Code

protected function preparePublisher() {
  if (isset($this->ampMetadataSettings['org_name']) && !empty($this->ampMetadataSettings['org_name']) && isset($this->ampMetadataSettings['org_logo_fid']) && !empty($this->ampMetadataSettings['org_logo_fid'])) {

    /** @var FileInterface $org_logo_file */
    if (!empty($org_logo_file = File::load($this->ampMetadataSettings['org_logo_fid'])) && !empty($org_logo_uri = $org_logo_file
      ->getFileUri())) {
      $org_logo_style_id = '';
      if (isset($this->ampMetadataSettings['org_logo_style_id']) && !empty($this->ampMetadataSettings['org_logo_style_id'])) {
        $org_logo_style_id = $this->ampMetadataSettings['org_logo_style_id'];
      }
      $org_logo_info = $this
        ->getImageInformation($org_logo_uri, $org_logo_style_id);
      if (!empty($org_logo_info)) {
        $this->ampPreparedMetadataJson['publisher'] = [
          '@type' => 'Organization',
          'name' => PlainTextOutput::renderFromHtml(\Drupal::service('token')
            ->replace($this->ampMetadataSettings['org_name'], [
            'node' => $this->node,
          ])),
          'logo' => [
            '@type' => 'ImageObject',
            'url' => $org_logo_info['url'],
            'width' => $org_logo_info['width'],
            'height' => $org_logo_info['height'],
          ],
        ];
      }
    }
  }
}