Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ss4 upgrade #181

Open
wants to merge 14 commits into
base: feature/ss4-upgrade
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ UncleCheese\BetterButtons\Extensions\BetterButtons:
delete: true
frontendLinks: true
versioned_edit:
save: true
publish: true
# publishAndClose: true
# saveAndAdd: true
# saveAndNext: true
# saveAndPrev: true
Expand All @@ -36,6 +39,8 @@ UncleCheese\BetterButtons\Extensions\BetterButtons:
label: Versioning...
buttons:
rollback: true
archive: true
unpublish: true
frontendLinks: true
---
Only:
Expand Down
4 changes: 4 additions & 0 deletions _config/injector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Name: betterbuttonsinjector
SilverStripe\Core\Injector\Injector:
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.delete:
class: UncleCheese\BetterButtons\Buttons\Delete
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.archive:
class: UncleCheese\BetterButtons\Buttons\Archive
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.create:
class: UncleCheese\BetterButtons\Buttons\Create
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.publishAndAdd:
Expand All @@ -14,6 +16,8 @@ SilverStripe\Core\Injector\Injector:
class: UncleCheese\BetterButtons\Buttons\Rollback
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.save:
class: UncleCheese\BetterButtons\Buttons\Save
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.publish:
class: UncleCheese\BetterButtons\Buttons\Publish
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.unpublish:
class: UncleCheese\BetterButtons\Buttons\Unpublish
UncleCheese\BetterButtons\Interfaces\BetterButtonInterface.saveAndAdd:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "unclecheese/betterbuttons",
"description": "Adds new form actions and buttons to GridField detail form for usability enhancements.",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": ["silverstripe", "gridfield", "buttons"],
"license": "GNU",
"authors": [
Expand Down
38 changes: 20 additions & 18 deletions css/gridfield_betterbuttons.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
.gridfield-better-buttons-next { margin-right:12px; border-radius: 0 20px 20px 0; }
.gridfield-better-buttons-prev { margin-right:12px; border-radius: 20px 0 0 20px; }

//.btn.action.gridfield-better-buttons-delete,
// .ui-widget.gridfield-better-buttons-delete:focus {
// float:right;
// color: #fff;
// text-shadow:none;
// border: solid 1px #980c10;
// background: #d81b21;
// background: -webkit-gradient(linear, left top, left bottom, from(#ed1c24), to(#aa1317));
// background: -moz-linear-gradient(top, #ed1c24, #aa1317);
// filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ed1c24', endColorstr='#aa1317');
// }
/*
.btn.action.gridfield-better-buttons-delete,
.ui-widget.gridfield-better-buttons-delete:focus {
float:right;
color: #fff;
text-shadow:none;
border: solid 1px #980c10;
background: #d81b21;
background: -webkit-gradient(linear, left top, left bottom, from(#ed1c24), to(#aa1317));
background: -moz-linear-gradient(top, #ed1c24, #aa1317);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ed1c24', endColorstr='#aa1317');
}

// .btn.action.gridfield-better-buttons-delete:hover,
// .gridfield-better-buttons-delete:active {
// background: #b61318;
// background: -webkit-gradient(linear, left top, left bottom, from(#c9151b), to(#a11115));
// background: -moz-linear-gradient(top, #c9151b, #a11115);
// filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#c9151b', endColorstr='#a11115');
// }
.btn.action.gridfield-better-buttons-delete:hover,
.gridfield-better-buttons-delete:active {
background: #b61318;
background: -webkit-gradient(linear, left top, left bottom, from(#c9151b), to(#a11115));
background: -moz-linear-gradient(top, #c9151b, #a11115);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#c9151b', endColorstr='#a11115');
}
*/

.gridfield-better-buttons-undodelete {
display:none;
Expand Down
9 changes: 9 additions & 0 deletions lang/da.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
da:
GridFieldBetterButtons:
NEWRECORD: 'Ny'
PUBLISHANDADD: 'Udgiv og tilføj ny'
PUBLISHANDQUITE: 'Udgiv og luk'
SAVEANDADDNEW: 'Gem og tilføj ny'
SAVEANDCLOSE: 'Gem og luk'
SAVEANDNEXT: 'Gem og gå til næste'
SAVEANDPREV: 'Gem og gå til forrige'
54 changes: 54 additions & 0 deletions src/Buttons/Archive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\Requirements;

/**
* Defines the button that archives a record, with confirmation
*
* @author Uncle Cheese <[email protected]>
* @package silverstripe-gridfield-betterbuttons
*/
class Archive extends Button
{
/**
* Builds the button
*/
public function __construct()
{
parent::__construct('doArchive', _t('SilverStripe\Versioned\VersionedGridFieldItemRequest.ARCHIVE', 'Archive'));
}

/**
* Adds the JS, sets up necessary HTML attributes
* @return Archive
*/
public function baseTransform()
{
parent::baseTransform();

return $this
->setUseButtonTag(true)
->addExtraClass('btn-outline-danger btn-hide-outline font-icon-trash-bin gridfield-better-buttons-archive');
}

/**
* Determines if the button should show
* @return boolean
*/
public function shouldDisplay()
{
/* @var DataObject|Versioned $record */
$record = $this->getGridFieldRequest()->getRecord();

if(!$record->hasExtension(Versioned::class)){
return $record->canDelete();
}

return !$record->isPublished() && $record->canDelete();
}
}
9 changes: 7 additions & 2 deletions src/Buttons/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\Requirements;
Expand All @@ -19,7 +20,7 @@ class Delete extends Button
*/
public function __construct()
{
parent::__construct('doDelete', _t('GridFieldDetailForm.Delete', 'Delete'));
parent::__construct('doDelete', _t(GridFieldDetailForm::class . '.Delete', 'Delete'));
}

/**
Expand All @@ -33,7 +34,7 @@ public function baseTransform()

return $this
->setUseButtonTag(true)
->addExtraClass('btn-danger-outline btn-hide-outline font-icon-trash-bin gridfield-better-buttons-delete')
->addExtraClass('btn-outline-danger btn-hide-outline font-icon-trash-bin gridfield-better-buttons-delete')
->setAttribute("data-toggletext", _t('GridFieldBetterButtons.AREYOUSURE', 'Yes. Delete this item.'))
->setAttribute("data-confirmtext", _t('GridFieldDetailForm.CANCELDELETE', 'No. Don\'t delete.'));
}
Expand All @@ -47,6 +48,10 @@ public function shouldDisplay()
/* @var DataObject|Versioned $record */
$record = $this->getGridFieldRequest()->getRecord();

if(!$record->hasExtension(Versioned::class)){
return $record->canDelete();
}

return !$record->isPublished() && $record->canDelete();
}
}
47 changes: 47 additions & 0 deletions src/Buttons/Publish.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\GridField\GridFieldDetailForm;

/**
* Defines the button that saves a record
*
* @author Uncle Cheese <[email protected]>
* @package silverstripe-gridfield-betterbuttons
*/
class Publish extends Button
{
/**
* Builds the button
*/
public function __construct()
{
parent::__construct('doPublish', _t('SilverStripe\Versioned\VersionedGridFieldItemRequest.BUTTONPUBLISH', 'Publish'));
}

/**
* Determines if the button should show
*
* @return boolean
*/
public function shouldDisplay()
{
$record = $this->getGridFieldRequest()->getRecord();

return $record->canEdit();
}

/**
* Adds the appropriate icon and style
*
* @return FormAction
*/
public function transformToButton()
{
return parent::transformToButton()
->addExtraClass('btn-primary font-icon-save')
->setAttribute('data-icon', 'accept');
}
}
3 changes: 2 additions & 1 deletion src/Buttons/PublishAndAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use UncleCheese\BetterButtons\Interfaces\BetterButtonVersioned;
use UncleCheese\BetterButtons\Traits\SaveAndAddTransforms;
Expand All @@ -25,7 +26,7 @@ class PublishAndAdd extends Button implements BetterButtonVersioned
*/
public function __construct(Form $form, GridFieldDetailForm_ItemRequest $request)
{
parent::__construct('doPublishAndAdd', _t('GridFieldDetailForm.PUBLISHANDADD', 'Publish and add new'));
parent::__construct('doPublishAndAdd', _t('GridFieldBetterButtons.PUBLISHANDADD', 'Publish and add new'));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Buttons/PublishAndClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\GridField\GridFieldDetailForm;
use UncleCheese\BetterButtons\Interfaces\BetterButtonVersioned;
use UncleCheese\BetterButtons\Traits\SaveAndCloseTransforms;

Expand All @@ -20,7 +21,7 @@ class PublishAndClose extends Button implements BetterButtonVersioned
*/
public function __construct()
{
return parent::__construct('doPublishAndQuit', _t('GridFieldDetailForm.PUBLISHANDQUITE', 'Publish and close'));
return parent::__construct('doPublishAndQuit', _t('GridFieldBetterButtons.PUBLISHANDQUITE', 'Publish and close'));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Buttons/Rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\FormAction;
use UncleCheese\BetterButtons\Interfaces\BetterButtonVersioned;
use SilverStripe\ORM\DataObject;
Expand All @@ -20,7 +21,7 @@ class Rollback extends Button implements BetterButtonVersioned
*/
public function __construct()
{
parent::__construct('rollback', _t('SiteTree.BUTTONCANCELDRAFT', 'Cancel draft changes'));
parent::__construct('rollback', _t(SiteTree::class . '.BUTTONCANCELDRAFT', 'Cancel draft changes'));
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Buttons/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\GridField\GridFieldDetailForm;

/**
* Defines the button that saves a record
*
* @author Uncle Cheese <[email protected]>
* @author Uncle Cheese <[email protected]>
* @package silverstripe-gridfield-betterbuttons
*/
class Save extends Button
Expand All @@ -17,11 +18,12 @@ class Save extends Button
*/
public function __construct()
{
parent::__construct('save', _t('GridFieldDetailForm.SAVE', 'Save'));
parent::__construct('doSave', _t(GridFieldDetailForm::class . '.Save', 'Save'));
}

/**
* Determines if the button should show
*
* @return boolean
*/
public function shouldDisplay()
Expand All @@ -33,6 +35,7 @@ public function shouldDisplay()

/**
* Adds the appropriate icon and style
*
* @return FormAction
*/
public function transformToButton()
Expand Down
3 changes: 2 additions & 1 deletion src/Buttons/SaveAndClose.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\GridField\GridFieldDetailForm;
use UncleCheese\BetterButtons\Traits\SaveAndCloseTransforms;

/**
Expand All @@ -19,7 +20,7 @@ class SaveAndClose extends Button
*/
public function __construct()
{
parent::__construct("doSaveAndQuit", _t('GridFieldDetailForm.SAVEANDCLOSE', 'Save and close'));
parent::__construct("doSaveAndQuit", _t('GridFieldBetterButtons.SAVEANDCLOSE', 'Save and close'));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Buttons/SaveAndNext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use UncleCheese\BetterButtons\Controllers\ItemRequest;

Expand All @@ -19,7 +20,7 @@ class SaveAndNext extends Button
*/
public function __construct()
{
parent::__construct("doSaveAndNext", _t('GridFieldDetailForm.SAVEANDNEXT', 'Save and go to next record'));
parent::__construct("doSaveAndNext", _t('GridFieldBetterButtons.SAVEANDNEXT', 'Save and go to next record'));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Buttons/SaveAndPrev.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace UncleCheese\BetterButtons\Buttons;

use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use UncleCheese\BetterButtons\Controllers\ItemRequest;

Expand All @@ -19,7 +20,7 @@ class SaveAndPrev extends Button
*/
public function __construct()
{
parent::__construct("doSaveAndPrev", _t('GridFieldDetailForm.SAVEANDPREV', 'Save and go to previous record'));
parent::__construct("doSaveAndPrev", _t('GridFieldBetterButtons.SAVEANDPREV', 'Save and go to previous record'));
}

/**
Expand Down
Loading