Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions app/code/Magento/Catalog/Helper/Product/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ private function preparePageMetadata(ResultPage $resultPage, $product)
$pageLayout = $resultPage->getLayout();
$pageConfig = $resultPage->getConfig();

$title = $product->getMetaTitle();
if ($title) {
$pageConfig->getTitle()->set($title);
} else {
$pageConfig->getTitle()->set($product->getName());
}
$metaTitle = $product->getMetaTitle();
$pageConfig->setMetaTitle($metaTitle);
$pageConfig->getTitle()->set($metaTitle ?: $product->getName());

$keyword = $product->getMetaKeyword();
$currentCategory = $this->_coreRegistry->registry('current_category');
Expand Down
84 changes: 59 additions & 25 deletions lib/internal/Magento/Framework/View/Page/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\Framework\View\Page;

use Magento\Framework\App;
use Magento\Framework\App\Area;
use Magento\Framework\View;

/**
Expand Down Expand Up @@ -34,6 +35,15 @@ class Config
const ELEMENT_TYPE_HEAD = 'head';
/**#@-*/

const META_DESCRIPTION = 'description';
const META_CONTENT_TYPE = 'content_type';
const META_MEDIA_TYPE = 'media_type';
const META_CHARSET = 'charset';
const META_TITLE = 'title';
const META_KEYWORDS = 'keywords';
const META_ROBOTS = 'robots';
const META_X_UI_COMPATIBLE = 'x_ua_compatible';

/**
* Constant body attribute class
*/
Expand Down Expand Up @@ -245,7 +255,7 @@ public function getMetadata()
*/
public function setContentType($contentType)
{
$this->setMetadata('content_type', $contentType);
$this->setMetadata(self::META_CONTENT_TYPE, $contentType);
}

/**
Expand All @@ -256,10 +266,10 @@ public function setContentType($contentType)
public function getContentType()
{
$this->build();
if (strtolower($this->metadata['content_type']) === 'auto') {
$this->metadata['content_type'] = $this->getMediaType() . '; charset=' . $this->getCharset();
if (strtolower($this->metadata[self::META_CONTENT_TYPE]) === 'auto') {
$this->metadata[self::META_CONTENT_TYPE] = $this->getMediaType() . '; charset=' . $this->getCharset();
}
return $this->metadata['content_type'];
return $this->metadata[self::META_CONTENT_TYPE];
}

/**
Expand All @@ -268,7 +278,7 @@ public function getContentType()
*/
public function setMediaType($mediaType)
{
$this->setMetadata('media_type', $mediaType);
$this->setMetadata(self::META_MEDIA_TYPE, $mediaType);
}

/**
Expand All @@ -279,13 +289,13 @@ public function setMediaType($mediaType)
public function getMediaType()
{
$this->build();
if (empty($this->metadata['media_type'])) {
$this->metadata['media_type'] = $this->scopeConfig->getValue(
if (empty($this->metadata[self::META_MEDIA_TYPE])) {
$this->metadata[self::META_MEDIA_TYPE] = $this->scopeConfig->getValue(
'design/head/default_media_type',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
return $this->metadata['media_type'];
return $this->metadata[self::META_MEDIA_TYPE];
}

/**
Expand All @@ -294,7 +304,7 @@ public function getMediaType()
*/
public function setCharset($charset)
{
$this->setMetadata('charset', $charset);
$this->setMetadata(self::META_CHARSET, $charset);
}

/**
Expand All @@ -305,13 +315,13 @@ public function setCharset($charset)
public function getCharset()
{
$this->build();
if (empty($this->metadata['charset'])) {
$this->metadata['charset'] = $this->scopeConfig->getValue(
if (empty($this->metadata[self::META_CHARSET])) {
$this->metadata[self::META_CHARSET] = $this->scopeConfig->getValue(
'design/head/default_charset',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
return $this->metadata['charset'];
return $this->metadata[self::META_CHARSET];
}

/**
Expand All @@ -320,7 +330,7 @@ public function getCharset()
*/
public function setDescription($description)
{
$this->setMetadata('description', $description);
$this->setMetadata(self::META_DESCRIPTION, $description);
}

/**
Expand All @@ -331,13 +341,36 @@ public function setDescription($description)
public function getDescription()
{
$this->build();
if (empty($this->metadata['description'])) {
$this->metadata['description'] = $this->scopeConfig->getValue(
if (empty($this->metadata[self::META_DESCRIPTION])) {
$this->metadata[self::META_DESCRIPTION] = $this->scopeConfig->getValue(
'design/head/default_description',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
return $this->metadata['description'];
return $this->metadata[self::META_DESCRIPTION];
}

/**
* @param string $title
*/
public function setMetaTitle($title)
{
$this->setMetadata(self::META_TITLE, $title);
}

/**
* Retrieve meta title
*
* @return string
*/
public function getMetaTitle()
{
$this->build();
if (empty($this->metadata[self::META_TITLE])) {
return '';
}

return $this->metadata[self::META_TITLE];
}

/**
Expand All @@ -346,7 +379,7 @@ public function getDescription()
*/
public function setKeywords($keywords)
{
$this->setMetadata('keywords', $keywords);
$this->setMetadata(self::META_KEYWORDS, $keywords);
}

/**
Expand All @@ -357,13 +390,13 @@ public function setKeywords($keywords)
public function getKeywords()
{
$this->build();
if (empty($this->metadata['keywords'])) {
$this->metadata['keywords'] = $this->scopeConfig->getValue(
if (empty($this->metadata[self::META_KEYWORDS])) {
$this->metadata[self::META_KEYWORDS] = $this->scopeConfig->getValue(
'design/head/default_keywords',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
return $this->metadata['keywords'];
return $this->metadata[self::META_KEYWORDS];
}

/**
Expand All @@ -372,27 +405,28 @@ public function getKeywords()
*/
public function setRobots($robots)
{
$this->setMetadata('robots', $robots);
$this->setMetadata(self::META_ROBOTS, $robots);
}

/**
* Retrieve URL to robots file
*
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getRobots()
{
if ($this->getAreaResolver()->getAreaCode() !== 'frontend') {
if ($this->getAreaResolver()->getAreaCode() !== Area::AREA_FRONTEND) {
return 'NOINDEX,NOFOLLOW';
}
$this->build();
if (empty($this->metadata['robots'])) {
$this->metadata['robots'] = $this->scopeConfig->getValue(
if (empty($this->metadata[self::META_ROBOTS])) {
$this->metadata[self::META_ROBOTS] = $this->scopeConfig->getValue(
'design/search_engine_robots/default_robots',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
return $this->metadata['robots'];
return $this->metadata[self::META_ROBOTS];
}

/**
Expand Down
16 changes: 9 additions & 7 deletions lib/internal/Magento/Framework/View/Page/Config/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\View\Page\Config;

use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Asset\GroupedCollection;
use Magento\Framework\View\Page\Config;

Expand All @@ -21,7 +23,7 @@ class Renderer implements RendererInterface
protected $assetTypeOrder = ['css', 'ico', 'js'];

/**
* @var \Magento\Framework\View\Page\Config
* @var Config
*/
protected $pageConfig;

Expand Down Expand Up @@ -51,7 +53,7 @@ class Renderer implements RendererInterface
protected $urlBuilder;

/**
* @param \Magento\Framework\View\Page\Config $pageConfig
* @param Config $pageConfig
* @param \Magento\Framework\View\Asset\MergeService $assetMergeService
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\Escaper $escaper
Expand Down Expand Up @@ -159,19 +161,19 @@ protected function getMetadataTemplate($name)
}

switch ($name) {
case 'charset':
case Config::META_CHARSET:
$metadataTemplate = '<meta charset="%content"/>' . "\n";
break;

case 'content_type':
case Config::META_CONTENT_TYPE:
$metadataTemplate = '<meta http-equiv="Content-Type" content="%content"/>' . "\n";
break;

case 'x_ua_compatible':
case Config::META_X_UI_COMPATIBLE:
$metadataTemplate = '<meta http-equiv="X-UA-Compatible" content="%content"/>' . "\n";
break;

case 'media_type':
case Config::META_MEDIA_TYPE:
$metadataTemplate = false;
break;

Expand Down Expand Up @@ -358,7 +360,7 @@ protected function renderAssetHtml(\Magento\Framework\View\Asset\PropertyGroup $
);
$result .= sprintf($template, $asset->getUrl());
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
} catch (LocalizedException $e) {
$this->logger->critical($e);
$result .= sprintf($template, $this->urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']));
}
Expand Down