Skip to content

Commit

Permalink
extend HeadMeta view helper to allow microdata
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Tylkowski committed Mar 12, 2013
1 parent 5d1efb6 commit 81d4f08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
20 changes: 16 additions & 4 deletions library/Zend/View/Helper/HeadMeta.php
Expand Up @@ -3,8 +3,9 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_View
*/

namespace Zend\View\Helper;
Expand All @@ -17,14 +18,16 @@
* Zend_Layout_View_Helper_HeadMeta
*
* @see http://www.w3.org/TR/xhtml1/dtds.html
* @package Zend_View
* @subpackage Helper
*/
class HeadMeta extends Placeholder\Container\AbstractStandalone
{
/**
* Types of attributes
* @var array
*/
protected $typeKeys = array('name', 'http-equiv', 'charset', 'property');
protected $typeKeys = array('name', 'http-equiv', 'charset', 'property', 'itemprop');
protected $requiredKeys = array('content');
protected $modifierKeys = array('lang', 'scheme');

Expand Down Expand Up @@ -91,6 +94,8 @@ protected function normalizeType($type)
return 'http-equiv';
case 'Property':
return 'property';
case 'Itemprop':
return 'itemprop';
default:
throw new Exception\DomainException(sprintf(
'Invalid type "%s" passed to normalizeType',
Expand Down Expand Up @@ -123,7 +128,7 @@ protected function normalizeType($type)
*/
public function __call($method, $args)
{
if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property)$/', $method, $matches)) {
if (preg_match('/^(?P<action>set|(pre|ap)pend|offsetSet)(?P<type>Name|HttpEquiv|Property|Itemprop)$/', $method, $matches)) {
$action = $matches['action'];
$type = $this->normalizeType($matches['type']);
$argc = count($args);
Expand Down Expand Up @@ -182,7 +187,7 @@ public function setCharset($charset)
* Determine if item is valid
*
* @param mixed $item
* @return bool
* @return boolean
*/
protected function isValid($item)
{
Expand All @@ -198,6 +203,13 @@ protected function isValid($item)
|| (! $this->view->plugin('doctype')->isHtml5() && $item->type !== 'charset'))) {
return false;
}

// <meta itemprop= ... /> is only supported with doctype html
if (! $this->view->plugin('doctype')->isHtml5()
&& $item->type === 'itemprop'){

return false;
}

// <meta property= ... /> is only supported with doctype RDFa
if (!$this->view->plugin('doctype')->isRdfa()
Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/View/Helper/HeadMetaTest.php
Expand Up @@ -3,7 +3,7 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_View
*/
Expand Down

0 comments on commit 81d4f08

Please sign in to comment.