forked from Cyber-Duck/Silverstripe-Block-Page
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrew Mc Cormack
committed
Dec 3, 2017
1 parent
a921ae8
commit f4b4137
Showing
10 changed files
with
282 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
--- | ||
Name: cyber-duck block page config | ||
--- | ||
CyberDuck\BlockPage\Model\ContentBlock: | ||
extensions: | ||
- SilverStripe\Versioned\Versioned | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,79 @@ | |
|
||
namespace CyberDuck\BlockPage\Action; | ||
|
||
use Page; | ||
use CyberDuck\BlockPage\Model\ContentBlock; | ||
use SilverStripe\Control\Controller; | ||
use SilverStripe\Forms\Form; | ||
use SilverStripe\Forms\FormAction; | ||
use SilverStripe\Forms\Tab; | ||
use SilverStripe\Forms\TabSet; | ||
use SilverStripe\ORM\DataObject; | ||
use SilverStripe\Versioned\VersionedGridFieldItemRequest; | ||
|
||
class GridFieldVersionedContentBlockItemRequest extends VersionedGridFieldItemRequest | ||
{ | ||
private static $allowed_actions = [ | ||
'doSelect', | ||
'doSelection', | ||
'ItemEditForm' | ||
]; | ||
|
||
public function ItemEditForm() | ||
{ | ||
$form = parent::ItemEditForm(); | ||
$actions = $form->Actions(); | ||
|
||
if($this->record->getAction() == 'new') { | ||
// remove all actions and add the create action | ||
foreach($actions as $action) { | ||
$actions->remove($action); | ||
} | ||
$button = FormAction::create('doSelect'); | ||
$button->setTitle('Create') | ||
->setUseButtonTag(true) | ||
->setAttribute('data-icon', 'accept') | ||
->addExtraClass('btn action btn-primary font-icon-plus'); | ||
$actions->unshift($button); | ||
} else { | ||
$button = FormAction::create('doSelection'); | ||
$button->setTitle('New Block') | ||
->setAttribute('data-icon', 'accept'); | ||
$actions->unshift($button); | ||
// set fields | ||
$fields = $this->record->getCMSFields(); | ||
$fields->setForm($form); | ||
|
||
$form->fields()->removeByName('Root'); | ||
$form->fields()->push(TabSet::create('Root', Tab::create('Main'))); | ||
$form->fields()->addFieldsToTab('Root.Main', $fields); | ||
|
||
$form->loadDataFrom($this->record); | ||
} | ||
return $form; | ||
} | ||
|
||
public function doSelect() | ||
{ | ||
$request = Controller::curr()->getRequest(); | ||
|
||
$class = $request->postVar('ContentBlock'); | ||
|
||
$block = $class::create(); | ||
$block->write(); | ||
|
||
$page = DataObject::get_by_id(Page::class, $request->postVar('PageID')); | ||
$page->ContentBlocks()->add($block); | ||
|
||
return Controller::curr()->redirect(Controller::join_links($this->gridField->Link('item'), $block->ID, 'edit')); | ||
} | ||
|
||
public function doSelection($data, Form $form) | ||
{ | ||
return Controller::curr()->redirect(Controller::join_links($this->gridField->Link('item'), 'new')); | ||
} | ||
} | ||
/* | ||
use SilverStripe\Control\Controller; | ||
use SilverStripe\Forms\Form; | ||
use SilverStripe\Forms\FormAction; | ||
|
@@ -10,39 +83,11 @@ | |
use SilverStripe\ORM\ValidationResult; | ||
use SilverStripe\Versioned\Versioned; | ||
/** | ||
* CreateBlock_ItemRequest | ||
* | ||
* Request handler for creating new blocks in the CMS | ||
* | ||
* @package silverstripe-block-page | ||
* @license MIT License https://github.com/cyber-duck/silverstripe-block-page/blob/master/LICENSE | ||
* @author <[email protected]> | ||
**/ | ||
class CreateBlock_ItemRequest extends GridFieldDetailForm_ItemRequest | ||
{ | ||
/** | ||
* Allowe CMS block request actions | ||
* | ||
* @since version 1.0.0 | ||
* | ||
* @config array $allowed_actions | ||
**/ | ||
private static $allowed_actions = [ | ||
'ItemEditForm', | ||
'doCreate', | ||
'doPublish', | ||
'doUnpublish', | ||
'doArchive' | ||
'ItemEditForm' | ||
]; | ||
|
||
/** | ||
* CMS record form method | ||
* | ||
* @since version 1.0.0 | ||
* | ||
* @return object | ||
**/ | ||
public function ItemEditForm() | ||
{ | ||
$form = parent::ItemEditForm(); | ||
|
@@ -131,17 +176,6 @@ public function ItemEditForm() | |
} | ||
return $form; | ||
} | ||
|
||
/** | ||
* Handles the block create request and redirects to the new record | ||
* | ||
* @since version 1.0.0 | ||
* | ||
* @param array $data | ||
* @param object $form | ||
* | ||
* @return void | ||
**/ | ||
public function doCreate($data, Form $form) | ||
{ | ||
$request = Controller::curr()->getRequest(); | ||
|
@@ -156,16 +190,6 @@ public function doCreate($data, Form $form) | |
return Controller::curr()->redirect(Controller::join_links($this->gridField->Link('item'), $block->ID, 'edit')); | ||
} | ||
/** | ||
* Handles the publish action | ||
* | ||
* @since version 4.0.0 | ||
* | ||
* @param array $data | ||
* @param object $form | ||
* | ||
* @return void | ||
**/ | ||
public function doPublish($data, Form $form) | ||
{ | ||
$record = $this->getRecord(); | ||
|
@@ -182,16 +206,6 @@ public function doPublish($data, Form $form) | |
return $this->redirectAfterSave(false); | ||
} | ||
/** | ||
* Handles the unpublish action | ||
* | ||
* @since version 4.0.0 | ||
* | ||
* @param array $data | ||
* @param object $form | ||
* | ||
* @return void | ||
**/ | ||
public function doUnpublish($data, $form) | ||
{ | ||
$record = $this->getRecord(); | ||
|
@@ -207,16 +221,6 @@ public function doUnpublish($data, $form) | |
return $this->redirectAfterSave(false); | ||
} | ||
/** | ||
* Set form action message | ||
* | ||
* @since version 4.0.0 | ||
* | ||
* @param object $form | ||
* @param string $message | ||
* | ||
* @return void | ||
**/ | ||
protected function setFormMessage($form, $message) | ||
{ | ||
$form->sessionMessage($message, 'good', ValidationResult::CAST_HTML); | ||
|
@@ -227,32 +231,12 @@ protected function setFormMessage($form, $message) | |
} | ||
} | ||
/** | ||
* Redirects to block selection screen | ||
* | ||
* @since version 1.0.0 | ||
* | ||
* @param array $data | ||
* @param object $form | ||
* | ||
* @return void | ||
**/ | ||
public function doAddBlock($data, Form $form) | ||
{ | ||
return Controller::curr()->redirect(Controller::join_links($this->gridField->Link('item'), 'new')); | ||
} | ||
/** | ||
* Get the current record action | ||
* | ||
* @since version 1.0.0 | ||
* | ||
* @return string | ||
**/ | ||
private function getAction() | ||
{ | ||
$path = explode('/', Controller::curr()->getRequest()->getURL()); | ||
return array_pop($path); | ||
} | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* GridFieldVersionedDeleteAction | ||
* | ||
* Overrides GridFieldDeleteAction to unlink a versioned relation (ContentBlock) | ||
* from a versioned DataObject (Page) | ||
* | ||
* @package silverstripe-block-page | ||
* @license MIT License https://github.com/cyber-duck/silverstripe-block-page/blob/master/LICENSE | ||
* @author <[email protected]> | ||
**/ | ||
namespace CyberDuck\BlockPage\Action; | ||
|
||
use SilverStripe\Forms\GridField\GridField; | ||
use SilverStripe\Forms\GridField\GridFieldDeleteAction; | ||
use SilverStripe\Versioned\Versioned; | ||
|
||
class GridFieldVersionedDeleteAction extends GridFieldDeleteAction | ||
{ | ||
public function handleAction(GridField $gridField, $actionName, $arguments, $data) | ||
{ | ||
// remove from live | ||
if ($actionName == 'deleterecord' || $actionName == 'unlinkrelation') { | ||
$item = $gridField->getList()->byID($arguments['RecordID']); | ||
if (!$item) { | ||
return; | ||
} | ||
if ($actionName == 'unlinkrelation') { | ||
if (!$item->canEdit()) { | ||
throw new ValidationException( | ||
_t(__CLASS__.'.EditPermissionsFailure', "No permission to unlink record") | ||
); | ||
} | ||
$item->PageContentBlock->deleteFromStage(Versioned::LIVE); | ||
} | ||
} | ||
// remove from stage | ||
parent::handleAction($gridField, $actionName, $arguments, $data); | ||
} | ||
} |
Empty file.
Oops, something went wrong.