Skip to content

Commit

Permalink
Refactor to avoid method_exists call
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 authored and nmalevanec committed Aug 23, 2018
1 parent fba597e commit 79b0b41
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 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\Exception\LocalizedException;
use Magento\Framework\View;

/**
Expand Down Expand Up @@ -34,6 +35,14 @@ 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';

/**
* Constant body attribute class
*/
Expand Down Expand Up @@ -340,6 +349,34 @@ public function getDescription()
return $this->metadata['description'];
}

/**
* Get rendered metadata
* @param string $fieldName
* @return string
* @throws LocalizedException
*/
public function getRenderedMetaTagValue(string $fieldName)
{
switch ($fieldName) {
case self::META_DESCRIPTION:
return $this->getDescription();
case self::META_CONTENT_TYPE:
return $this->getContentType();
case self::META_MEDIA_TYPE:
return $this->getMediaType();
case self::META_CHARSET:
return $this->getCharset();
case self::META_KEYWORDS:
return $this->getKeywords();
case self::META_ROBOTS:
return $this->getRobots();
case self::META_TITLE:
return $this->getMetaTitle();
default:
throw new LocalizedException(__('No rendered meta function for %1', $fieldName));
}
}

/**
* @param string $title
*/
Expand All @@ -348,6 +385,21 @@ public function setMetaTitle($title)
$this->setMetadata('title', $title);
}

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

return $this->metadata['title'];
}

/**
* @param string $keywords
* @return void
Expand Down

0 comments on commit 79b0b41

Please sign in to comment.