mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Removing $inline parameter from HtmlHelper::meta() inline is now an option.
This commit is contained in:
parent
b021461630
commit
7344c0ce7d
2 changed files with 22 additions and 16 deletions
|
@ -209,15 +209,21 @@ class HtmlHelper extends AppHelper {
|
||||||
/**
|
/**
|
||||||
* Creates a link to an external resource and handles basic meta tags
|
* Creates a link to an external resource and handles basic meta tags
|
||||||
*
|
*
|
||||||
|
* #### Options
|
||||||
|
*
|
||||||
|
* - `inline` Whether or not the link element should be output inline, or in scripts_for_layout.
|
||||||
|
*
|
||||||
* @param string $type The title of the external resource
|
* @param string $type The title of the external resource
|
||||||
* @param mixed $url The address of the external resource or string for content attribute
|
* @param mixed $url The address of the external resource or string for content attribute
|
||||||
* @param array $attributes Other attributes for the generated tag. If the type attribute is html,
|
* @param array $options Other attributes for the generated tag. If the type attribute is html,
|
||||||
* rss, atom, or icon, the mime-type is returned.
|
* rss, atom, or icon, the mime-type is returned.
|
||||||
* @param boolean $inline If set to false, the generated tag appears in the head tag of the layout.
|
|
||||||
* @return string A completed <link /> element.
|
* @return string A completed <link /> element.
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function meta($type, $url = null, $attributes = array(), $inline = true) {
|
function meta($type, $url = null, $options = array()) {
|
||||||
|
$inline = isset($options['inline']) ? $options['inline'] : true;
|
||||||
|
unset($options['inline']);
|
||||||
|
|
||||||
if (!is_array($type)) {
|
if (!is_array($type)) {
|
||||||
$types = array(
|
$types = array(
|
||||||
'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $url),
|
'rss' => array('type' => 'application/rss+xml', 'rel' => 'alternate', 'title' => $type, 'link' => $url),
|
||||||
|
@ -233,34 +239,34 @@ class HtmlHelper extends AppHelper {
|
||||||
|
|
||||||
if (isset($types[$type])) {
|
if (isset($types[$type])) {
|
||||||
$type = $types[$type];
|
$type = $types[$type];
|
||||||
} elseif (!isset($attributes['type']) && $url !== null) {
|
} elseif (!isset($options['type']) && $url !== null) {
|
||||||
if (is_array($url) && isset($url['ext'])) {
|
if (is_array($url) && isset($url['ext'])) {
|
||||||
$type = $types[$url['ext']];
|
$type = $types[$url['ext']];
|
||||||
} else {
|
} else {
|
||||||
$type = $types['rss'];
|
$type = $types['rss'];
|
||||||
}
|
}
|
||||||
} elseif (isset($attributes['type']) && isset($types[$attributes['type']])) {
|
} elseif (isset($options['type']) && isset($types[$options['type']])) {
|
||||||
$type = $types[$attributes['type']];
|
$type = $types[$options['type']];
|
||||||
unset($attributes['type']);
|
unset($options['type']);
|
||||||
} else {
|
} else {
|
||||||
$type = array();
|
$type = array();
|
||||||
}
|
}
|
||||||
} elseif ($url !== null) {
|
} elseif ($url !== null) {
|
||||||
$inline = $url;
|
$inline = $url;
|
||||||
}
|
}
|
||||||
$attributes = array_merge($type, $attributes);
|
$options = array_merge($type, $options);
|
||||||
$out = null;
|
$out = null;
|
||||||
|
|
||||||
if (isset($attributes['link'])) {
|
if (isset($options['link'])) {
|
||||||
if (isset($attributes['rel']) && $attributes['rel'] === 'icon') {
|
if (isset($options['rel']) && $options['rel'] === 'icon') {
|
||||||
$out = sprintf($this->tags['metalink'], $attributes['link'], $this->_parseAttributes($attributes, array('link'), ' ', ' '));
|
$out = sprintf($this->tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
|
||||||
$attributes['rel'] = 'shortcut icon';
|
$options['rel'] = 'shortcut icon';
|
||||||
} else {
|
} else {
|
||||||
$attributes['link'] = $this->url($attributes['link'], true);
|
$options['link'] = $this->url($options['link'], true);
|
||||||
}
|
}
|
||||||
$out .= sprintf($this->tags['metalink'], $attributes['link'], $this->_parseAttributes($attributes, array('link'), ' ', ' '));
|
$out .= sprintf($this->tags['metalink'], $options['link'], $this->_parseAttributes($options, array('link'), ' ', ' '));
|
||||||
} else {
|
} else {
|
||||||
$out = sprintf($this->tags['meta'], $this->_parseAttributes($attributes, array('type')));
|
$out = sprintf($this->tags['meta'], $this->_parseAttributes($options, array('type')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($inline) {
|
if ($inline) {
|
||||||
|
|
|
@ -1049,7 +1049,7 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
|
$result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'));
|
||||||
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
|
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
|
||||||
|
|
||||||
$this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array(), false));
|
$this->assertNull($this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('inline' => false)));
|
||||||
$view =& ClassRegistry::getObject('view');
|
$view =& ClassRegistry::getObject('view');
|
||||||
$result = $view->__scripts[0];
|
$result = $view->__scripts[0];
|
||||||
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
|
$this->assertTags($result, array('meta' => array('name' => 'ROBOTS', 'content' => 'ALL')));
|
||||||
|
|
Loading…
Add table
Reference in a new issue