Skip to content

Commit 12c5169

Browse files
author
Florian Krämer
committed
Refactoring the helper a little
1 parent 299baed commit 12c5169

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

Test/Case/View/Helper/TinyMceHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function testEditor() {
134134
$this->TinyMCE->configs = $this->configs;
135135
$this->TinyMCE->editor('simple');
136136

137-
$this->expectException('OutOfBoundsException');
137+
$this->expectException('RuntimeException');
138138
$this->TinyMCE->editor('invalid-config');
139139
}
140140

View/Helper/TinyMCEHelper.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ class TinyMCEHelper extends AppHelper {
2323
*
2424
* @var array
2525
*/
26-
public $helpers = array('Html');
26+
public $helpers = array(
27+
'Html'
28+
);
2729

2830
/**
2931
* Configuration
@@ -37,7 +39,10 @@ class TinyMCEHelper extends AppHelper {
3739
*
3840
* @var array
3941
*/
40-
protected $_defaults = array();
42+
protected $_defaults = array(
43+
'script' => '/TinyMCE/js/tiny_mce/tiny_mce.js',
44+
'loadScript' => true,
45+
);
4146

4247
/**
4348
* Constructor
@@ -51,12 +56,14 @@ public function __construct(View $View, $settings = array()) {
5156
if (!empty($configs) && is_array($configs)) {
5257
$this->configs = $configs;
5358
}
59+
$this->settings = array_merge($this->_defaults, $settings);
5460
}
5561

5662
/**
5763
* Adds a new editor to the script block in the head
5864
*
5965
* @see http://www.tinymce.com/wiki.php/Configuration for a list of keys
66+
* @throws RuntimeException
6067
* @param mixed If array camel cased TinyMCE Init config keys, if string it checks if a config with that name exists
6168
* @return void
6269
*/
@@ -65,7 +72,7 @@ public function editor($options = array()) {
6572
if (isset($this->configs[$options])) {
6673
$options = $this->configs[$options];
6774
} else {
68-
throw new OutOfBoundsException(sprintf(__('Invalid TinyMCE configuration preset %s'), $options));
75+
throw new RuntimeException(sprintf(__('Invalid TinyMCE configuration preset %s'), $options));
6976
}
7077
}
7178
$options = array_merge($this->_defaults, $options);
@@ -74,6 +81,7 @@ public function editor($options = array()) {
7481
foreach ($options as $option => $value) {
7582
$lines .= Inflector::underscore($option) . ' : "' . $value . '",' . "\n";
7683
}
84+
7785
// remove last comma from lines to avoid the editor breaking in Internet Explorer
7886
$lines = rtrim($lines);
7987
$lines = rtrim($lines, ',');
@@ -92,7 +100,9 @@ public function beforeRender($viewFile) {
92100
if ($appOptions !== false && is_array($appOptions)) {
93101
$this->_defaults = $appOptions;
94102
}
95-
$this->Html->script('/TinyMCE/js/tiny_mce/tiny_mce.js', array('inline' => false));
103+
if ($this->settings['loadScript'] === true) {
104+
$this->Html->script($this->settings['script'], array('inline' => false));
105+
}
96106
}
97107

98108
}

0 commit comments

Comments
 (0)