Skip to content

Commit 71b504c

Browse files
author
Mikaël Capelle
committed
Update Modal helper documentation.
1 parent f4b528d commit 71b504c

File tree

2 files changed

+145
-38
lines changed

2 files changed

+145
-38
lines changed

src/View/Helper/BootstrapModalHelper.php

Lines changed: 141 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class BootstrapModalHelper extends Helper {
6565
* - `aria-hidden` HTML attribute. Default is `'true'`.
6666
* - `body` If `$title` is a string, set to `false` to not open the body after
6767
* the panel header. Default is `true`.
68-
* - `close` Set to `false` to no add a close button to the modal. Default is `true`.
68+
* - `close` Set to `false` to not add a close button to the modal. Default is `true`.
6969
* - `id` Identifier of the modal. If specified, a `aria-labelledby` HTML attribute
7070
* will be added to the modal and the header will be set accordingly.
7171
* - `role` HTML attribute. Default is `'dialog'`.
@@ -148,7 +148,7 @@ public function create($title = null, $options = []) {
148148
* If `$buttons` is not null, the `footer()` method will be used to create the modal
149149
* footer using `$buttons` and `$options`:
150150
*
151-
* ```
151+
* ```php
152152
* echo $this->Modal->end([$this->Form->button('Save'), $this->Form->button('Close')]);
153153
* ```
154154
*
@@ -196,8 +196,22 @@ protected function _part($part, $content = null, $options = []) {
196196
return $out;
197197
}
198198

199-
// TODO: Update doc below this point.
200-
199+
/**
200+
* Create or open a modal header.
201+
*
202+
* ### Options
203+
*
204+
* - `close` Set to `false` to not add a close button to the modal. Default is `true`
205+
* - Other attributes for the modal header `<div>`.
206+
*
207+
* @param string|null $text The modal header content, or null to only open the header.
208+
* @param array $options Array of options. See above.
209+
*
210+
* @return string A formated opening tag for the modal header or the complete modal
211+
* header.
212+
*
213+
* @see `BootstrapModalHelper::header`
214+
*/
201215
protected function _createHeader($title = null, $options = []) {
202216
$options += [
203217
'close' => true
@@ -227,44 +241,93 @@ protected function _createHeader($title = null, $options = []) {
227241

228242
return $this->_part('header', $out, $options);
229243
}
230-
231-
protected function _createBody ($text = null, $options = []) {
244+
/**
245+
* Create or open a modal body.
246+
*
247+
* @param string|null $text The modal body content, or null to only open the body.
248+
* @param array $options Array of options for the body `<div>`.
249+
*
250+
* @return string A formated opening tag for the modal body or the complete modal
251+
* body.
252+
*
253+
* @see `BootstrapModalHelper::body`
254+
*/
255+
protected function _createBody($text = null, $options = []) {
232256
$options = $this->addClass($options, 'modal-body');
233257
return $this->_part('body', $text, $options);
234258
}
235259

236-
protected function _createFooter ($buttons = null, $options = []) {
260+
/**
261+
* Create or open a modal footer.
262+
*
263+
* If `$content` is `null` and the `'close'` option (see below) is `true`, a close
264+
* button is created inside the footer.
265+
*
266+
* ### Options
267+
*
268+
* - `close` Set to `true` to add a close button to the footer if `$content` is
269+
* empty. Default is `true`.
270+
* Other attributes for the footer div.
271+
*
272+
* @param string|null $content The modal footer content, or null to only open the footer.
273+
* @param array $options Array of options. See above.
274+
*
275+
* @return string A formated opening tag for the modal footer or the complete modal
276+
* footer.
277+
*/
278+
protected function _createFooter($content = null, $options = []) {
237279
$options += [
238280
'close' => true
239281
];
240282
$close = $options['close'];
241283
unset($options['close']);
242284

243-
$content = '';
244-
if (!$buttons && $close) {
285+
if (!$content && $close) {
245286
$content .= '<button type="button" class="btn btn-default" data-dismiss="modal">'
246287
.__('Close')
247288
.'</button>' ;
248289
}
249-
$content .= $buttons;
250290

251291
$options = $this->addClass($options, 'modal-footer');
252-
return $this->_part('footer', $buttons, $options);
292+
return $this->_part('footer', $content, $options);
253293
}
254294

255295
/**
296+
* Create or open a modal header.
256297
*
257-
* Create / Start the header. If $info is specified as a string, create and return the
258-
* whole header, otherwize only open the header.
298+
* If `$text` is a string, create a modal header using the specified content
299+
* and `$options`.
259300
*
260-
* @param array|string $info If string, use as the modal title, otherwize works as $options.
261-
* @param array $options Options for the header div.
301+
* ```php
302+
* echo $this->Modal->header('Header Content', ['class' => 'my-class']);
303+
* ```
304+
*
305+
* If `$text` is `null`, create a formated opening tag for a modal header using the
306+
* specified `$options`.
307+
*
308+
* ```php
309+
* echo $this->Modal->header(null, ['class' => 'my-class']);
310+
* ```
311+
*
312+
* If `$text` is an array, used it as `$options` and create a formated opening tag for
313+
* a modal header.
262314
*
263-
* Special option (if $info is string):
264-
* - close: Add the 'close' button in the header (default true).
315+
* ```php
316+
* echo $this->Modal->header(['class' => 'my-class']);
317+
* ```
265318
*
266-
**/
267-
public function header ($info = null, $options = []) {
319+
* ### Options
320+
*
321+
* - `close` Set to `false` to not add a close button to the modal. Default is `true`
322+
* - Other attributes for the modal header `<div>`.
323+
*
324+
* @param string|array $text The modal header content, or an array of options.
325+
* @param array $options Array of options. See above.
326+
*
327+
* @return string A formated opening tag for the modal header or the complete modal
328+
* header.
329+
*/
330+
public function header($info = null, $options = []) {
268331
if (is_array($info)) {
269332
$options = $info;
270333
$info = null;
@@ -273,16 +336,36 @@ public function header ($info = null, $options = []) {
273336
}
274337

275338
/**
339+
* Create or open a modal body.
276340
*
277-
* Create / Start the body. If $info is not null, it is used as the body content,
278-
* otherwize start the body div.
341+
* If `$content` is a string, create a modal body using the specified content and
342+
* `$options`.
279343
*
280-
* @param array|string $info If string, use as the body content, otherwize works as $options.
281-
* @param array $options Options for the footer div.
344+
* ```php
345+
* echo $this->Modal->body('Modal Content', ['class' => 'my-class']);
346+
* ```
282347
*
348+
* If `$content` is `null`, create a formated opening tag for a modal body using the
349+
* specified `$options`.
283350
*
284-
**/
285-
public function body ($info = null, $options = []) {
351+
* ```php
352+
* echo $this->Modal->body(null, ['class' => 'my-class']);
353+
* ```
354+
*
355+
* If `$content` is an array, used it as `$options` and create a formated opening tag for
356+
* a modal body.
357+
*
358+
* ```php
359+
* echo $this->Modal->body(['class' => 'my-class']);
360+
* ```
361+
*
362+
* @param array|string $info The body content, or `null`, or an array of options.
363+
* `$options`.
364+
* @param array $options Array of options for the modal body `<div>`.
365+
*
366+
* @return string
367+
*/
368+
public function body($info = null, $options = []) {
286369
if (is_array($info)) {
287370
$options = $info;
288371
$info = null;
@@ -291,19 +374,43 @@ public function body ($info = null, $options = []) {
291374
}
292375

293376
/**
377+
* Create or open a modal footer.
378+
*
379+
* If `$buttons` is a string, create a modal footer using the specified content
380+
* and `$options`.
381+
*
382+
* ```php
383+
* echo $this->Modal->footer('Footer Content', ['class' => 'my-class']);
384+
* ```
385+
*
386+
* If `$buttons` is `null`, create a **formated opening tag** for a modal footer using the
387+
* specified `$options`.
388+
*
389+
* ```php
390+
* echo $this->Modal->footer(null, ['class' => 'my-class']);
391+
* ```
392+
*
393+
* If `$buttons` is an associative array, used it as `$options` and create a
394+
* **formated opening tag** for a modal footer.
395+
*
396+
* ```php
397+
* echo $this->Modal->footer(['class' => 'my-class']);
398+
* ```
294399
*
295-
* Create / Start the footer. If $buttons is specified as an associative arrays or as null,
296-
* start the footer, otherwize create the footer with the specified buttons.
400+
* If `$buttons` is a non-associative array, its elements are glued together to
401+
* create the content. This can be used to generate a footer with buttons:
297402
*
298-
* @param array|string $buttons If string, use as the footer content, if list, concatenate
299-
* values in the list as content (use for buttons purpose), otherwize works as $options.
300-
* @param array $options Options for the footer div.
403+
* ```php
404+
* echo $this->Modal->footer([$this->Form->button('Close'), $this->Form->button('Save')]);
405+
* ```
301406
*
302-
* Special option (if $buttons is NOT NULL but empty):
303-
* - close: Add the 'close' button to the footer (default true).
407+
* @param string|array $buttons The footer content, or `null`, or an array of options.
408+
* @param array $options Array of options for the modal footer `<div>`.
304409
*
305-
**/
306-
public function footer ($buttons = null, $options = []) {
410+
* @return string A formated opening tag for the modal footer or the complete modal
411+
* footer.
412+
*/
413+
public function footer($buttons = null, $options = []) {
307414
if (is_array($buttons)) {
308415
if (!empty($buttons) && $this->_isAssociativeArray($buttons)) {
309416
$options = $buttons;

src/View/Helper/BootstrapPanelHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public function end($content = null, $options = []) {
315315
return $res ;
316316
}
317317

318-
/**
318+
\ /**
319319
* Cleans the current panel part and return necessary HTML closing elements.
320320
*
321321
* @return string An HTML string containing closing elements.
@@ -357,7 +357,7 @@ protected function _isOpen() {
357357
* @return string A formated opening tag for the panel header or the complete panel
358358
* header.
359359
*/
360-
protected function _createHeader ($title, $options = [], $titleOptions = []) {
360+
protected function _createHeader($title, $options = [], $titleOptions = []) {
361361
if (empty($titleOptions)) {
362362
$titleOptions = $options['title'] ;
363363
}
@@ -409,7 +409,7 @@ protected function _createHeader ($title, $options = [], $titleOptions = []) {
409409
* @return string A formated opening tag for the panel body or the complete panel
410410
* body.
411411
*/
412-
protected function _createBody ($text = null, $options = []) {
412+
protected function _createBody($text = null, $options = []) {
413413
$options = $this->addClass($options, 'panel-body');
414414
$body = $this->Html->tag('div', $text, $options);
415415
if ($this->_collapsible) {
@@ -436,7 +436,7 @@ protected function _createBody ($text = null, $options = []) {
436436
* @return string A formated opening tag for the panel footer or the complete panel
437437
* footer.
438438
*/
439-
protected function _createFooter ($text = null, $options = []) {
439+
protected function _createFooter($text = null, $options = []) {
440440
$options = $this->addClass($options, 'panel-footer');
441441
return $this->_cleanCurrent().$this->Html->tag('div', $text, $options) ;
442442
}

0 commit comments

Comments
 (0)