AmpMergeMetadata.php in Accelerated Mobile Pages (AMP) 8
File
src/Utility/AmpMergeMetadata.php
View source
<?php
namespace Drupal\amp\Utility;
use Drupal\amp\AmpMetadataInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class AmpMergeMetadata {
protected $metadataEntities;
protected $ampGlobalMetadata;
protected $ampNodeTypeMetadata;
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->metadataEntities = $this->entityTypeManager
->getStorage('amp_metadata')
->loadMultiple();
$this->ampGlobalMetadata = [];
$this->ampNodeTypeMetadata = [];
}
public function getMergedMetadata($node_type) {
foreach ($this->metadataEntities as $metadata_entity) {
$is_global = $is_type = FALSE;
$is_global = $metadata_entity
->isGlobal();
$is_type = $metadata_entity
->getNodeType() === $node_type;
if ($is_global || $is_type) {
$entity_settings = [];
if (!empty($org_name = $metadata_entity
->getOrganizationName())) {
$entity_settings['org_name'] = $org_name;
}
if (!empty($org_logo_fid = $metadata_entity
->getOrganizationLogoFid())) {
$entity_settings['org_logo_fid'] = $org_logo_fid;
}
if (!empty($org_logo_style_id = $metadata_entity
->getOrganizationLogoImageStyleId())) {
$entity_settings['org_logo_style_id'] = $org_logo_style_id;
}
if (!empty($schema_type = $metadata_entity
->getContentSchemaType())) {
$entity_settings['schema_type'] = $schema_type;
}
if (!empty($content_headline_token = $metadata_entity
->getContentHeadlineToken())) {
$entity_settings['content_headline_token'] = $content_headline_token;
}
if (!empty($content_author_token = $metadata_entity
->getContentAuthorToken())) {
$entity_settings['content_author_token'] = $content_author_token;
}
if (!empty($content_description_token = $metadata_entity
->getContentDescriptionToken())) {
$entity_settings['content_description_token'] = $content_description_token;
}
if (!empty($content_image_token = $metadata_entity
->getContentImageToken())) {
$entity_settings['content_image_token'] = $content_image_token;
}
if (!empty($content_image_style_id = $metadata_entity
->getContentImageStyleId())) {
$entity_settings['content_image_style_id'] = $content_image_style_id;
}
if ($is_global) {
$this->ampGlobalMetadata = $entity_settings;
}
elseif ($is_type) {
$this->ampNodeTypeMetadata = $entity_settings;
}
}
}
return array_merge($this->ampGlobalMetadata, $this->ampNodeTypeMetadata);
}
}