/
CorePageProperty.php
122 lines (101 loc) · 3.78 KB
/
CorePageProperty.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace Concrete\Core\Page\Type\Composer\Control\CorePageProperty;
use Loader;
use Environment;
use Concrete\Core\Page\Page;
use Controller;
abstract class CorePageProperty extends \Concrete\Core\Page\Type\Composer\Control\Control
{
protected $propertyHandle;
protected $ptComposerControlTypeHandle = 'core_page_property';
private static $ptComposerSaveRequest = null;
private static $ptComposerRequestControlsProcessed = array();
public function addAssetsToRequest(Controller $cnt)
{
}
public static function clearComposerRequestProcessControls()
{
self::$ptComposerRequestControlsProcessed = array();
}
public function removePageTypeComposerControlFromPage()
{
return false;
}
public function isPageTypeComposerControlValueEmpty()
{
return $this->getPageTypeComposerControlDraftValue() != '';
}
public function export($node)
{
$node->addAttribute('handle', $this->getCorePagePropertyHandle());
}
public static function getPageTypeComposerSaveRequest()
{
if (null === self::$ptComposerSaveRequest) {
self::$ptComposerSaveRequest = array();
}
return self::$ptComposerSaveRequest;
}
public function shouldPageTypeComposerControlStripEmptyValuesFromPage()
{
return false;
}
public function pageTypeComposerFormControlSupportsValidation()
{
return true;
}
public function addPageTypeComposerControlRequestValue($key, $value)
{
self::$ptComposerSaveRequest[$key] = $value;
}
public function setCorePagePropertyHandle($propertyHandle)
{
$this->setPageTypeComposerControlIdentifier($propertyHandle);
$this->propertyHandle = $propertyHandle;
}
public function getCorePagePropertyHandle()
{
return $this->propertyHandle;
}
public function getPageTypeComposerControlCustomTemplates()
{
return array();
}
public function publishToPage(Page $c, $data, $controls)
{
array_push(self::$ptComposerRequestControlsProcessed, $this);
// now we check to see if we have any more core controls to process in this request
$coreControls = array();
foreach ($controls as $cnt) {
if ($cnt->getPageTypeComposerControlTypeHandle() == $this->ptComposerControlTypeHandle) {
$coreControls[] = $controls;
}
}
if (count(self::$ptComposerRequestControlsProcessed) == count($coreControls)) {
// this was the last one. so we're going to loop through our saved request
// and do the page update once, rather than four times.
$c->update(self::$ptComposerSaveRequest);
}
}
public function render($label, $customTemplate, $description)
{
$env = Environment::get();
$form = Loader::helper('form');
$set = $this->getPageTypeComposerFormLayoutSetControlObject()->getPageTypeComposerFormLayoutSetObject();
$control = $this;
if ($customTemplate) {
$rec = $env->getRecord(DIRNAME_ELEMENTS . '/' . DIRNAME_PAGE_TYPES . '/' . DIRNAME_COMPOSER . '/' . DIRNAME_COMPOSER_ELEMENTS_CONTROLS . '/' . $this->ptComposerControlTypeHandle . '/' . $this->propertyHandle . '/' . DIRNAME_BLOCK_TEMPLATES_COMPOSER . '/' . $customTemplate);
if ($rec->exists()) {
$template = $rec->file;
}
}
if (!isset($template)) {
$template = $env->getPath(DIRNAME_ELEMENTS . '/' . DIRNAME_PAGE_TYPES . '/' . DIRNAME_COMPOSER . '/' . DIRNAME_COMPOSER_ELEMENTS_CONTROLS . '/' . $this->ptComposerControlTypeHandle . '/' . $this->propertyHandle . '.php');
}
include $template;
}
public function validate()
{
return true;
}
}