/** * Adds the OG meta tags for the provided content * @param \ride\web\cms\orm\ContentProperties $properties * @param \ride\library\cms\content\Content $content * @param \ride\library\image\ImageUrlGenerator $imageUrlGenerator * @return null */ protected function setMetaOg(ContentProperties $contentProperties, $content, ImageUrlGenerator $imageUrlGenerator) { $modelMeta = $this->model->getMeta(); $modelTable = $modelMeta->getModelTable(); // get formats $titleFormat = $contentProperties->getOgTitleFormat(); if (!$titleFormat) { $titleFormat = $modelTable->getFormat(EntryFormatter::FORMAT_TITLE, false); if ($titleFormat == null) { $titleFormat = $this->model->getName() . ' #{id}'; } } $teaserFormat = $contentProperties->getOgTeaserFormat(); if (!$teaserFormat && $modelTable->hasFormat(EntryFormatter::FORMAT_TEASER)) { $teaserFormat = $modelTable->getFormat(EntryFormatter::FORMAT_TEASER); } $imageFormat = $contentProperties->getOgImageFormat(); if (!$imageFormat && $modelTable->hasFormat(EntryFormatter::FORMAT_IMAGE)) { $imageFormat = $modelTable->getFormat(EntryFormatter::FORMAT_IMAGE); } // add meta $entryFormatter = $this->model->getOrmManager()->getEntryFormatter(); $node = $this->properties->getNode(); $node->setMeta($this->locale, 'og:title', $entryFormatter->formatEntry($content->data, $titleFormat)); if ($teaserFormat) { $teaser = $entryFormatter->formatEntry($content->data, $teaserFormat); if ($teaser) { $node->setMeta($this->locale, 'og:description', $teaser); } } if ($imageFormat) { $image = $entryFormatter->formatEntry($content->data, $imageFormat); if ($image) { $node->setMeta($this->locale, 'og:image', $imageUrlGenerator->generateUrl($image)); } } }