src/View/Helper/ModalHelper.php
public function create($title = null, $options = []) {

        if(is_array($title)) {
            $options = $title;
        }

        $this->_currentId = null;
        $this->_current   = null;

        $options += [
            'id' => null,
            'close' => true,
            'body' => true,
            'size' => false,
            'templateVars' => []
        ];

        $dialogOptions = [];

        if($options['id']) {
            $this->_currentId = $options['id'];
            $options['aria-labelledby'] = $this->_currentId.'Label';
        }

        switch($options['size']) {
        case 'lg':
        case 'large':
        case 'modal-lg':
            $size = ' modal-lg';
            break;
        case 'sm':
        case 'small':
        case 'modal-sm':
            $size = ' modal-sm';
            break;
        case false:
            $size = '';
            break;
        default:
            $size = ' '.$options['size'];
            break;
        }
        $dialogOptions = $this->addClass($dialogOptions, $size);

        $dialogStart = $this->formatTemplate('modalDialogStart', [
            'attrs' => $this->templater()->formatAttributes($dialogOptions)
        ]);
        $contentStart = $this->formatTemplate('modalContentStart', []);
        $res = $this->formatTemplate('modalStart', [
            'dialogStart' => $dialogStart,
            'contentStart' => $contentStart,
            'attrs' => $this->templater()->formatAttributes($options, ['body', 'close', 'size']),
            'templateVars' => $options['templateVars']
        ]);
        if(is_string($title) && $title) {
            $res .= $this->_createHeader($title, ['close' => $options['close']]);
            if($options['body']) {
                $res .= $this->_createBody();
            }
        }
        return $res;
    }
public function create($title = null, $options = []) {

        if(is_array($title)) {
            $options = $title;
        }

        $this->_currentId = null;
        $this->_current   = null;

        $options += [
            'id' => null,
            'close' => true,
            'body' => true,
            'size' => false,
            'templateVars' => []
        ];

        $dialogOptions = [];

        if($options['id']) {
            $this->_currentId = $options['id'];
            $options['aria-labelledby'] = $this->_currentId.'Label';
        }

        switch($options['size']) {
        case 'lg':
        case 'large':
        case 'modal-lg':
            $size = ' modal-lg';
            break;
        case 'sm':
        case 'small':
        case 'modal-sm':
            $size = ' modal-sm';
            break;
        case false:
            $size = '';
            break;
        default:
            $size = ' '.$options['size'];
            break;
        }
        $dialogOptions = $this->addClass($dialogOptions, $size);

        $dialogStart = $this->formatTemplate('modalDialogStart', [
            'attrs' => $this->templater()->formatAttributes($dialogOptions)
        ]);
        $contentStart = $this->formatTemplate('modalContentStart', []);
        $res = $this->formatTemplate('modalStart', [
            'dialogStart' => $dialogStart,
            'contentStart' => $contentStart,
            'attrs' => $this->templater()->formatAttributes($options, ['body', 'close', 'size']),
            'templateVars' => $options['templateVars']
        ]);
        if(is_string($title) && $title) {
            $res .= $this->_createHeader($title, ['close' => $options['close']]);
            if($options['body']) {
                $res .= $this->_createBody();
            }
        }
        return $res;
    }
public function create ( $ title = null , $ options = [ ] ) { if ( is_array ( $ title ) ) { $ options = $ title ; } $ this -> _currentId = null ; $ this -> _current = null ; $ options += [ 'id' => null , 'close' => true , 'body' => true , 'size' => false , 'templateVars' => [ ] ] ; $ dialogOptions = [ ] ; if ( $ options [ 'id' ] ) { $ this -> _currentId = $ options [ 'id' ] ; $ options [ 'aria-labelledby' ] = $ this -> _currentId . 'Label' ; } switch ( $ options [ 'size' ] ) { case 'lg' : case 'large' : case 'modal-lg' : $ size = ' modal-lg' ; break ; case 'sm' : case 'small' : case 'modal-sm' : $ size = ' modal-sm' ; break ; case false : $ size = '' ; break ; default : $ size = ' ' . $ options [ 'size' ] ; break ; } $ dialogOptions = $ this -> addClass ( $ dialogOptions , $ size ) ; $ dialogStart = $ this -> formatTemplate ( 'modalDialogStart' , [ 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ dialogOptions ) ] ) ; $ contentStart = $ this -> formatTemplate ( 'modalContentStart' , [ ] ) ; $ res = $ this -> formatTemplate ( 'modalStart' , [ 'dialogStart' => $ dialogStart , 'contentStart' => $ contentStart , 'attrs' => $ this -> templater ( ) -> formatAttributes ( $ options , [ 'body' , 'close' , 'size' ] ) , 'templateVars' => $ options [ 'templateVars' ] ] ) ; if ( is_string ( $ title ) && $ title ) { $ res .= $ this -> _createHeader ( $ title , [ 'close' => $ options [ 'close' ] ] ) ; if ( $ options [ 'body' ] ) { $ res .= $ this -> _createBody ( ) ; } } return $ res ; }
Open a modal

If `$title` is a string, the modal header is created using `$title` as its
content and default options.

```php
echo $this->Modal->create('My Modal Title');
```

If the modal header is created, the modal body is automatically opened after
it, except if the `body` options is specified(see below).

If `$title` is an array, it is used as `$options`.

```php
echo $this->Modal->create(['class' => 'my-modal-class']);
```

### Options

- `body` If `$title` is a string, set to `false` to not open the body after
the panel header. Default is `true`.
- `close` Set to `false` to not add a close button to the modal. Default is `true`.
- `id` Identifier of the modal. If specified, a `aria-labelledby` HTML attribute
will be added to the modal and the header will be set accordingly.
- `size` Size of the modal. Either a shortcut(`'lg'`/`'large'`/`'modal-lg'` or
(`'sm'`/`'small'`/`'modal-sm'`) or `false`(no size specified) or a custom class.
Other options will be passed to the `Html::div` method for creating the
outer modal `<div>`.

@param array|string $title The modal title or an array of options.
@param array $options Array of options. See above.

@return string An HTML string containing opening elements for a modal.
Open a modal