Passed
Push — master ( d99cea...339592 )
by Fabio
05:58
created

TActiveHtmlArea5::onCallback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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