|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TPageTopAnchorBehavior class file. |
|
5
|
|
|
* |
|
6
|
|
|
* @author Brad Anderson <[email protected]> |
|
7
|
|
|
* @link https://github.com/pradosoft/prado |
|
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Prado\Util\Behaviors; |
|
12
|
|
|
|
|
13
|
|
|
use Prado\Util\TBehavior; |
|
14
|
|
|
use Prado\TPropertyValue; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* TPageTopAnchorBehavior class. |
|
18
|
|
|
* |
|
19
|
|
|
* TPageTopAnchorBehavior adds an "<a name='top'>" anchor at the top of |
|
20
|
|
|
* every page just before the TForm. |
|
21
|
|
|
* @author Brad Anderson <[email protected]> |
|
22
|
|
|
* @package Prado\Util\Behaviors |
|
23
|
|
|
* @since 4.2.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class TPageTopAnchorBehavior extends TBehavior |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var string the page theme is set to this parameter key |
|
29
|
|
|
*/ |
|
30
|
|
|
private $_topAnchor = 'top'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* This handles the TPage.OnSaveStateComplete event to place the |
|
34
|
|
|
* '<a name="">' at the last moment and have least interference with |
|
35
|
|
|
* anything else |
|
36
|
|
|
* @return array of events as keys and methods as values |
|
37
|
|
|
*/ |
|
38
|
|
|
public function events() |
|
39
|
|
|
{ |
|
40
|
|
|
return ['OnSaveStateComplete' => 'addFormANameAnchor']; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* This method places an '<a name="">' before the TForm |
|
45
|
|
|
* @param $page object raising the event |
|
46
|
|
|
* @param $param mixed the parameter of the raised event |
|
47
|
|
|
*/ |
|
48
|
|
|
public function addFormANameAnchor($page, $param) |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
$topanchor = '<a name="' . $this->_topAnchor . '"></a>'; |
|
51
|
|
|
|
|
52
|
|
|
if ($form = $page->getForm()) { |
|
53
|
|
|
$form->getParent()->getControls()->insertBefore($form, $topanchor); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string the top anchor name, defaults to 'top'. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getTopAnchor() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->_topAnchor; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param $value string the top anchor name. |
|
67
|
|
|
*/ |
|
68
|
|
|
public function setTopAnchor($value) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->_topAnchor = TPropertyValue::ensureString($value); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.