TActiveHtmlArea::setText()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 20
rs 10
1
<?php
2
3
/**
4
 * TActiveHtmlArea class file.
5
 *
6
 * @author LANDWEHR Computer und Software GmbH <[email protected]>
7
 * @link https://github.com/pradosoft/prado4
8
 * @license https://github.com/pradosoft/prado4/blob/master/LICENSE
9
 */
10
11
namespace Prado\Web\UI\ActiveControls;
12
13
use Prado\Web\UI\WebControls\THtmlArea;
14
use Prado\Web\UI\ActiveControls\ICallbackEventHandler;
15
use Prado\Web\UI\ActiveControls\IActiveControl;
16
use Prado\Web\UI\ActiveControls\TActiveControlAdapter;
17
18
/**
19
 * TActiveHtmlArea class
20
 *
21
 * TActiveHtmlArea is the active counterpart to {@see \Prado\Web\UI\WebControls\THtmlArea} with added support
22
 * for callback handling and the possibility of setting the content of the WYSIWYG
23
 * text editor during callback.
24
 *
25
 * Please refer to the original documentation of {@see \Prado\Web\UI\WebControls\THtmlArea} for basic usage.
26
 *
27
 * @author LANDWEHR Computer und Software GmbH <[email protected]>
28
 * @since 4.0
29
 * @method TActiveControlAdapter getAdapter()
30
 */
31
class TActiveHtmlArea extends THtmlArea implements IActiveControl, ICallbackEventHandler
32
{
33
	/**
34
	 * Creates a new callback control, sets the adapter to
35
	 * TActiveControlAdapter. If you override this class, be sure to set the
36
	 * adapter appropriately by, for example, by calling this constructor.
37
	 */
38
	public function __construct()
39
	{
40
		parent::__construct();
41
		$this->setAdapter(new TActiveControlAdapter($this));
42
	}
43
44
	/**
45
	 * @return TBaseActiveCallbackControl standard callback control options.
46
	 */
47
	public function getActiveControl()
48
	{
49
		return $this->getAdapter()->getBaseActiveControl();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getAdapter...>getBaseActiveControl() also could return the type Prado\Web\UI\ActiveControls\TBaseActiveControl which includes types incompatible with the return type mandated by Prado\Web\UI\ActiveContr...rol::getActiveControl() of Prado\Web\UI\ActiveContr...seActiveCallbackControl. Consider adding a type-check to rule them out.
Loading history...
50
	}
51
52
	/**
53
	 * @return TCallbackClientSide client side request options.
54
	 */
55
	public function getClientSide()
56
	{
57
		return $this->getActiveControl()->getClientSide();
58
	}
59
60
	/**
61
	 * Client-side Text property can only be updated after the OnLoad stage. Setting WYSIWYG
62
	 * text editor content is only available if {@see getEnableVisualEdit} is enabled.
63
	 * @param string $value text content for the textbox
64
	 */
65
	public function setText($value)
66
	{
67
		parent::setText($value);
68
		if ($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData()) {
69
			if ($this->getEnableVisualEdit()) {
70
				$value = str_ireplace(["\r\n", "\n"], "", $value);
71
				$command = "tinyMCE.getInstanceById('{$this->getClientID()}').execCommand('mceSetContent',false,'{$value}')";
72
				$this->getPage()->getCallbackClient()->evaluateScript($command);
73
			} else {
74
				$this->getPage()->getCallbackClient()->setValue($this, $value);
75
			}
76
		}
77
	}
78
79
	/**
80
	 * Raises the callback event. This method is required by {@see
81
	 * ICallbackEventHandler} interface.
82
	 * This method is mainly used by framework and control developers.
83
	 * @param TCallbackEventParameter $param the event parameter
84
	 */
85
	public function raiseCallbackEvent($param)
86
	{
87
		$this->onCallback($param);
88
	}
89
90
	/**
91
	 * This method is invoked when a callback is requested. The method raises
92
	 * 'OnCallback' event to fire up the event handlers. If you override this
93
	 * method, be sure to call the parent implementation so that the event
94
	 * handler can be invoked.
95
	 * @param TCallbackEventParameter $param event parameter to be passed to the event handlers
96
	 */
97
	public function onCallback($param)
98
	{
99
		$this->raiseEvent('OnCallback', $this, $param);
100
	}
101
}
102