https://github.com/lekoala/silverstripe-pure-modal
Dead simple modals for SilverStripe (works in the admin too!)
https://github.com/lekoala/silverstripe-pure-modal
modal php silverstripe silverstripe-module
Last synced: about 1 year ago
JSON representation
Dead simple modals for SilverStripe (works in the admin too!)
- Host: GitHub
- URL: https://github.com/lekoala/silverstripe-pure-modal
- Owner: lekoala
- License: mit
- Created: 2021-06-24T10:34:19.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-14T14:47:56.000Z (over 1 year ago)
- Last Synced: 2025-03-29T12:11:24.053Z (over 1 year ago)
- Topics: modal, php, silverstripe, silverstripe-module
- Language: PHP
- Homepage:
- Size: 57.6 KB
- Stars: 10
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# SilverStripe Pure Modal module

[](https://scrutinizer-ci.com/g/lekoala/silverstripe-pure-modal/)
[](https://codecov.io/gh/lekoala/silverstripe-pure-modal)
## Intro
Dead simple modals for SilverStripe (works in the admin too!)
## Sample usage
Simply pass the content to display in the modal. The modal will be accessible through a button in the fieldset
You can also set an iframe to be displayed within the modal in case you want to display a form for example.
```php
$myHtmlContent = "
Some content here
";
$ImportStuff = new PureModal('ImportStuff', 'Import Stuff', $myHtmlContent);
$fields->addFieldToTab('Root.Stuff', $ImportStuff);
$ImportStuff->setIframeAction('import_stuff');
$ImportStuff->setIframeTop(true);
```
And here is a sample `import_stuff` method
```php
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]);
}
```
## Modal action
This feature require my [cms-actions](https://github.com/lekoala/silverstripe-cms-actions) module.
```php
public function getCMSActions()
{
$actions = parent::getCMSActions();
$doDeny = new PureModalAction("doDeny", "Deny");
$predefinedText = <<setFieldList($iframeFields);
$doDeny->setShouldRefresh(true);
$doDeny->setDialogButtonTitle('Deny the request'); // customised modal submit button
$actions->push($doDeny);
}
```
It creates a button that opens a modal with a set of fields. These fields
are submitted alongside the form.
```php
public function doDeny($data)
{
$this->DeniedReason = $data['EnterText'];
$this->Status = "denied";
$this->write();
return 'Denied';
}
```
You can remove the submit button from the modal itself, for example to make it an information window only.
By doing like this:
```php
public function getCMSActions()
{
$actions = parent::getCMSActions();
$doDeny = new PureModalAction("noopInfo", "Information");
// .. add fields
$doDeny->setShowDialogButton(false);
$actions->push($doDeny);
}
```
## Compatibility
Tested with ^5
## Maintainer
LeKoala - thomas@lekoala.be