PHP code example of lekoala / silverstripe-pure-modal

1. Go to this page and download the library: Download lekoala/silverstripe-pure-modal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lekoala / silverstripe-pure-modal example snippets


$myHtmlContent = "<p>Some content here</p>";
$ImportStuff = new PureModal('ImportStuff', 'Import Stuff', $myHtmlContent);
$fields->addFieldToTab('Root.Stuff', $ImportStuff);
$ImportStuff->setIframeAction('import_stuff');
$ImportStuff->setIframeTop(true);

public function import_stuff(HTTPRequest $req)
{
    $Stuff = $this->getRequestedRecord();
    $fields = new FieldList([
        new FileField('File'),
        new HiddenField('StuffID', null, $Stuff->ID),
    ]);
    $actions = new FieldList([
        new FormAction('doUpload', 'Upload')
    ]);
    $form = new Form(Controller::curr(), 'MyForm', $fields, $actions);

    return PureModal::renderDialog($this, ['Form' => $form]);
}

    public function getCMSActions()
    {
        $actions = parent::getCMSActions();
        $doDeny = new PureModalAction("doDeny", "Deny");
        $predefinedText = <<<TEXT
Dear Customer,

Your request has been denied.

Best regards,
TEXT;
        $iframeFields = new FieldList([
            new DropdownField("SelectReason", "Select reason"),
            new TextareaField("EnterText", "Enter custom text", $predefinedText),
        ]);
        $doDeny->setFieldList($iframeFields);
        $doDeny->setShouldRefresh(true);
        $doDeny->setDialogButtonTitle('Deny the request'); // customised modal submit button
        $actions->push($doDeny);
    }

    public function doDeny($data)
    {
        $this->DeniedReason = $data['EnterText'];
        $this->Status = "denied";
        $this->write();
        return 'Denied';
    }

    public function getCMSActions()
    {
        $actions = parent::getCMSActions();
        $doDeny = new PureModalAction("noopInfo", "Information");

        // .. add fields

        $doDeny->setShowDialogButton(false);
        $actions->push($doDeny);
    }