-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontroller.php
377 lines (332 loc) · 9.29 KB
/
controller.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php
/**
* Block Boilerplate Controller File.
*
* @author Oliver Green <[email protected]>
* @license See attached license file
*/
namespace Application\Block\BlockBoilerplate;
use SimpleXMLElement;
use Concrete\Core\Block\BlockController;
defined('C5_EXECUTE') or die('Access Denied.');
/**
* Block Controller Class.
*
* Start building standards complient concrete5 blocks from me.
*
* @author Oliver Green <[email protected]>
* @license See attached license file
*/
class Controller extends BlockController
{
/**
* The block types name.
*
* @var string
*/
protected $btName = 'Block Boilerplate';
/**
* The block types description.
*
* @var string
*/
protected $btDescription = 'A block boilerplate to start building from.';
/**
* The block types handle.
*
* @var string
*/
protected $btHandle = 'block-boilerplate';
/**
* The block types default set within the 'add block' fly out panel.
*
* Valid sets included with the core are:
* basic, navigation, forms, social & multimedia.
*
* Leaving the value as null will add the block type to the 'other' set.
*
* @var string
*/
protected $btDefaultSet = null;
/**
* The block types table name;
* If left as null, the blocks handle will be used to form the table name.
*
* @var string
*/
protected $btTable = 'btBlockBoilerplate';
/**
* The blocks form width.
*
* @var string
*/
protected $btInterfaceWidth = '400';
/**
* The blocks form height.
*
* @var string
*/
protected $btInterfaceHeight = '400';
/* @section advanced */
/**
* Is this an internal block type?
* If set to true the block will not be shown in the 'add block' flyout panel?
*
* @var bool
*/
protected $btIsInternal = false;
/**
* Does the block support inline addition?
*
* @var bool
*/
protected $btSupportsInlineAdd = false;
/**
* Does the block support inline editing?
*
* @var bool
*/
protected $btSupportsInlineEdit = false;
/**
* If true, container classes will not be wrapped around this block type in
* edit mode (if the theme in question supports a grid framework).
*
* @var bool
*/
protected $btIgnorePageThemeGridFrameworkContainer = false;
/**
* Prevents the block from being aliased when duplicating a page or creating
* a page from defaults, if true the block will be duplicated instead.
*
* @var bool
*/
protected $btCopyWhenPropagate = false;
/**
* Returns whether this block type is included in all versions. Default is
* false - block types are typically versioned but sometimes it makes
* sense not to do so.
*
* @return bool
*/
protected $btIncludeAll = false;
/**
* Here you can defined helpers that the blocks add
* and edit forms require. They will be loaded automatically.
*
* @var array
*/
protected $helpers = ['form'];
/**
* When block caching is enabled, this means that the block's database record
* data will also be cached.
*
* @var bool
*/
protected $btCacheBlockRecord = true;
/**
* When block caching is enabled, enabling this boolean means that the output
* of the block will be saved and delivered without rendering the view()
* function or hitting the database at all.
*
* @var bool
*/
protected $btCacheBlockOutput = false;
/**
* When block caching is enabled and output caching is enabled for a block,
* this is the value in seconds that the cache will last before being refreshed.
* (specified in seconds).
*
* @var bool
*/
protected $btCacheBlockOutputLifetime = 3600;
/**
* This determines whether a block will cache its output on POST. Some blocks
* can cache their output but must serve uncached output on POST in order to
* show error messages, etc.
*
* @var bool
*/
protected $btCacheBlockOutputOnPost = false;
/**
* Determines whether a block that can cache its output will continue to cache
* its output even if the current user viewing it is logged in.
*
* @var bool
*/
protected $btCacheBlockOutputForRegisteredUsers = false;
/**
* When this block is exported, any database columns found in this array will
* automatically be swapped for links to specific pages. Upon import they will
* map to the specific page found at that path, regardless of its ID.
*
* @var array
*/
protected $btExportPageColumns = [];
/**
* When this block is exported, any database columns found in this array will
* automatically be swapped for links to specific files, by file name. Upon
* import they will map to the specific file with that filename, regardless
* of its file ID.
*
* @var array
*/
protected $btExportFileColumns = [];
/**
* When this block is exported, any database columns found in this array will
* automatically be swapped for references to a particular page type. Upon import
* they will map to that specific page type ID based on the handle specified.
*
* @var array
*/
protected $btExportPageTypeColumns = [];
/**
* When this block is exported, any database columns found in this array will
* automatically be swapped for a reference to a specific RSS feed object. Upon
* import they will map to the specific feed, regardless of its ID in the database.
*
* @var array
*/
protected $btExportPageFeedColumns = [];
/**
* Wraps the block view in a container element with the class specified here.
*
* @var string
*/
protected $btWrapperClass = '';
/* @endsection advanced */
/**
* Runs when the blocks view template is rendered.
*
* @return void
*/
public function view()
{
//
}
/**
* Run when the blocks add template is rendered.
*
* @return void
*/
public function add()
{
$this->form();
}
/**
* Run when the blocks edit template is rendered.
*
* @return void
*/
public function edit()
{
$this->form();
}
/**
* Called by the add and edit templates are rendered, as they often share logic.
*
* @return void
*/
public function form()
{
/*
* Set variables for your blocks view here...
*
* $this->set('data', $my_data)
*
* The in view.php the variable $data will be available with the
* contents of the $my_data.
*/
}
/**
* Run when the add or edit forms are submitted. This should return true if
* validation is successful or a Concrete\Core\Error\Error() object if it fails.
*
* @param $data
* @return bool|Error
*/
public function validate($data)
{
$errors = new \Concrete\Core\Error\Error();
/**
* if ('Oliver' !== $data['name']) {
* $errors['name'] = "You input the incorrect name.";
* }.
*/
if ($errors->has()) {
return $errors;
}
return true;
}
/**
* Run when the block add or edit form is submitted. The variables
* within the data array are mapped to columns found in the blocks table. Any
* post-processing of the blocks data before storage should be completed here.
*
* @param $data
* @return
*/
public function save($data)
{
/*
* if (isset($data['name']) && '' === trim($data['name'])) {
* unset($data['name']);
* }
*/
parent::save($data);
}
/**
* This happens automatically in Concrete5 when versioning blocks and pages.
*
* @param int $newBlockId
* @return void|BlockRecord
*/
public function duplicate($newBlockId)
{
return parent::duplicate($newBlockId);
}
/**
* Runs when a block is deleted. This may not happen very often since a
* block is only completed deleted when all versions that reference
* that block, including the original, have themselves been deleted.
*
* @return [type] [description]
*/
public function delete()
{
parent::delete();
}
/**
* Provides text for the page search indexing routine. This method should
* return simple, unformatted plain text, not HTML.
*
* @return string
*/
public function getSearchableContent()
{
return '';
}
/* @section advanced */
/**
* Runs when a block is being exported.
*
* @param SimpleXMLElement $blockNode
* @return void
*/
public function export(SimpleXMLElement $blockNode)
{
parent::export($blockNode);
}
/**
* Runs when a block is being imported.
*
* @param Page $page
* @param string $areaHandle
* @param SimpleXMLElement $blockNode
* @return void
*/
public function import($page, $areaHandle, SimpleXMLElement $blockNode)
{
parent::import($page, $areaHandle, $blockNode);
}
/* @endsection advanced */
}