Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow specifying option 'block' => true to get same funtionality as `…

…inline` => false for helpers.
  • Loading branch information...
commit 2ebf1d123fe820ca97af80ba9c7c98567d0c8155 1 parent 5df6c15
@ADmad ADmad authored
View
6 src/View/Helper/FormHelper.php
@@ -1377,7 +1377,8 @@ public function postButton($title, $url, $options = array()) {
* - `data` - Array with key/value to pass in input hidden
* - `method` - Request method to use. Set to 'delete' to simulate HTTP/1.1 DELETE request. Defaults to 'post'.
* - `confirm` - Can be used instead of $confirmMessage.
- * - `block` - Choose a custom block to append the form tag to.
+ * - `block` - Set to true to append form to view block "postLink" or provide
+ * custom block name.
* - Other options are the same of HtmlHelper::link() method.
* - The option `onclick` will be replaced.
*
@@ -1431,6 +1432,9 @@ public function postLink($title, $url = null, $options = array(), $confirmMessag
$out .= $this->formatTemplate('formend', []);
if ($options['block']) {
+ if ($options['block'] === true) {
+ $options['block'] = __FUNCTION__;
+ }
$this->_View->append($options['block'], $out);
$out = '';
}
View
35 src/View/Helper/HtmlHelper.php
@@ -183,13 +183,18 @@ public function docType($type = 'html5') {
*
* `$this->Html->meta('icon', 'favicon.ico');
*
+ * Append the meta tag to custom view block "meta":
+ *
+ * `$this->Html->meta('description', 'A great page', array('block' => true));`
+ *
* Append the meta tag to custom view block:
*
* `$this->Html->meta('description', 'A great page', array('block' => 'metaTags'));`
*
* ### Options
*
- * - `block` Choose a block to append the meta tag to.
+ * - `block` - Set to true to append output to view block "meta" or provide
+ * custom block name.
*
* @param string $type The title of the external resource
* @param string|array $url The address of the external resource or string for content attribute
@@ -255,6 +260,9 @@ public function meta($type, $url = null, $options = array()) {
if (empty($options['block'])) {
return $out;
}
+ if ($options['block'] === true) {
+ $options['block'] = __FUNCTION__;
+ }
$this->_View->append($options['block'], $out);
}
@@ -356,13 +364,18 @@ public function link($title, $url = null, $options = array(), $confirmMessage =
*
* `echo $this->Html->css(array('one.css', 'two.css'));`
*
+ * Add the stylesheet to view block "css":
+ *
+ * `$this->Html->css('styles.css', array('block' => true));`
+ *
* Add the stylesheet to a custom block:
*
* `$this->Html->css('styles.css', array('block' => 'layoutCss'));`
*
* ### Options
*
- * - `block` Set the name of the block link/style tag will be appended to.
+ * - `block` Set to true to append output to view block "css" or provide
+ * custom block name.
* - `plugin` False value will prevent parsing path as a plugin
* - `rel` Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported.
* - `fullBase` If true the URL will get a full address for the css file.
@@ -423,6 +436,9 @@ public function css($path, $options = array()) {
if (empty($options['block'])) {
return $out;
}
+ if ($options['block'] === true) {
+ $options['block'] = __FUNCTION__;
+ }
$this->_View->append($options['block'], $out);
}
@@ -449,7 +465,8 @@ public function css($path, $options = array()) {
*
* ### Options
*
- * - `block` The name of the block you want the script appended to. Leave undefined to output inline.
+ * - `block` Set to true to append output to view block "script" or provide
+ * custom block name.
* - `once` Whether or not the script should be checked for uniqueness. If true scripts will only be
* included once, use false to allow the same script to be included more than once per request.
* - `plugin` False value will prevent parsing path as a plugin
@@ -491,6 +508,9 @@ public function script($url, $options = array()) {
if (empty($options['block'])) {
return $out;
}
+ if ($options['block'] === true) {
+ $options['block'] = __FUNCTION__;
+ }
$this->_View->append($options['block'], $out);
}
@@ -500,7 +520,8 @@ public function script($url, $options = array()) {
* ### Options
*
* - `safe` (boolean) Whether or not the $script should be wrapped in <![CDATA[ ]]>
- * - `block` Which block you want this script block appended to.
+ * - `block` Set to true to append output to view block "script" or provide
+ * custom block name.
*
* @param string $script The script to wrap
* @param array $options The options to use. Options not listed above will be
@@ -523,6 +544,9 @@ public function scriptBlock($script, $options = array()) {
if (empty($options['block'])) {
return $out;
}
+ if ($options['block'] === true) {
+ $options['block'] = 'script';
+ }
$this->_View->append($options['block'], $out);
}
@@ -534,7 +558,8 @@ public function scriptBlock($script, $options = array()) {
* ### Options
*
* - `safe` Whether the code block should contain a CDATA
- * - `block` View block the output should be appended to
+ * - `block` Set to true to append output to view block "script" or provide
+ * custom block name.
*
* @param array $options Options for the code block.
* @return void
View
4 tests/TestCase/View/Helper/FormHelperTest.php
@@ -5046,7 +5046,7 @@ public function testPostLinkAfterGetForm() {
* @return void
*/
public function testPostLinkFormBuffer() {
- $result = $this->Form->postLink('Delete', '/posts/delete/1', array('block' => 'postLink'));
+ $result = $this->Form->postLink('Delete', '/posts/delete/1', array('block' => true));
$this->assertTags($result, array(
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
'Delete',
@@ -5064,7 +5064,7 @@ public function testPostLinkFormBuffer() {
));
$result = $this->Form->postLink('Delete', '/posts/delete/2',
- array('block' => 'postLink', 'method' => 'DELETE')
+ array('block' => true, 'method' => 'DELETE')
);
$this->assertTags($result, array(
'a' => array('href' => '#', 'onclick' => 'preg:/document\.post_\w+\.submit\(\); event\.returnValue = false; return false;/'),
View
38 tests/TestCase/View/Helper/HtmlHelperTest.php
@@ -560,8 +560,17 @@ public function testCssLink() {
$this->View->expects($this->at(0))
->method('append')
+ ->with('css', $this->matchesRegularExpression('/css_in_head.css/'));
+
+ $this->View->expects($this->at(1))
+ ->method('append')
->with('css', $this->matchesRegularExpression('/more_css_in_head.css/'));
- $this->Html->css('more_css_in_head.css', array('block' => 'css'));
+
+ $result = $this->Html->css('css_in_head', array('block' => true));
+ $this->assertNull($result);
+
+ $result = $this->Html->css('more_css_in_head', array('block' => true));
+ $this->assertNull($result);
$result = $this->Html->css('screen', array('rel' => 'import'));
$expected = array(
@@ -598,6 +607,12 @@ public function testCssLinkBC() {
'/style'
);
$this->assertTags($result, $expected);
+
+ $result = $this->Html->css('css_in_head', null, array('block' => true));
+ $this->assertNull($result);
+
+ $result = $this->Html->css('more_css_in_head', null, array('block' => true));
+ $this->assertNull($result);
}
/**
@@ -960,8 +975,15 @@ public function testPluginScript() {
public function testScriptWithBlocks() {
$this->View->expects($this->at(0))
->method('append')
+ ->with('script', $this->matchesRegularExpression('/script_in_head.js/'));
+
+ $this->View->expects($this->at(1))
+ ->method('append')
->with('headScripts', $this->matchesRegularExpression('/second_script.js/'));
+ $result = $this->Html->script('script_in_head', array('block' => true));
+ $this->assertNull($result);
+
$result = $this->Html->script('second_script', array('block' => 'headScripts'));
$this->assertNull($result);
}
@@ -1057,8 +1079,15 @@ public function testScriptBlock() {
$this->View->expects($this->at(0))
->method('append')
+ ->with('script', $this->matchesRegularExpression('/window\.foo\s\=\s2;/'));
+
+ $this->View->expects($this->at(1))
+ ->method('append')
->with('scriptTop', $this->stringContains('alert('));
+ $result = $this->Html->scriptBlock('window.foo = 2;', array('block' => true));
+ $this->assertNull($result);
+
$result = $this->Html->scriptBlock('alert("hi")', array('block' => 'scriptTop'));
$this->assertNull($result);
@@ -1119,8 +1148,7 @@ public function testScriptStartAndScriptEnd() {
$this->View->expects($this->once())
->method('append');
-
- $result = $this->Html->scriptStart(array('safe' => false, 'block' => 'scripts'));
+ $result = $this->Html->scriptStart(array('safe' => false, 'block' => true));
$this->assertNull($result);
echo 'this is some javascript';
@@ -1581,13 +1609,13 @@ public function testMetaIcon() {
public function testMetaWithBlocks() {
$this->View->expects($this->at(0))
->method('append')
- ->with('metas', $this->stringContains('ROBOTS'));
+ ->with('meta', $this->stringContains('ROBOTS'));
$this->View->expects($this->at(1))
->method('append')
->with('metaTags', $this->stringContains('favicon.ico'));
- $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('block' => 'metas'));
+ $result = $this->Html->meta(array('name' => 'ROBOTS', 'content' => 'ALL'), null, array('block' => true));
$this->assertNull($result);
$result = $this->Html->meta('icon', 'favicon.ico', array('block' => 'metaTags'));
Please sign in to comment.
Something went wrong with that request. Please try again.