Created
April 11, 2014 15:01
-
-
Save lozcalver/10475897 to your computer and use it in GitHub Desktop.
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
GridFieldDetailForm_ItemRequest: | |
extensions: | |
- GridFieldDetailFormExtension |
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
<?php | |
class GridFieldDetailFormExtension extends Extension { | |
/** | |
* @var array | |
*/ | |
private static $allowed_actions = array( | |
'doLock' | |
); | |
public function updateItemEditForm(&$form) { | |
if ($this->owner->getGridField()->getModelClass() == "Something") { | |
$record = $form->getRecord(); | |
if ($record->status == 'AVAILABLE') { | |
$action = new FormAction('doLock', 'Lock vehicle'); | |
$action->setUseButtonTag(true)->setAttribute('data-icon', 'chain--pencil'); | |
} | |
$form->Actions()->push($action); | |
} | |
} | |
/** | |
* Mark a used car as 'AVAILABLE_NON_UPDATABLE' | |
* @see UsedCar->lockVehicle() | |
* @param Array $data | |
* @param Form $form | |
* @return mixed | |
*/ | |
public function doLock($data, $form) { | |
$this->owner->record = $this->owner->record->lockVehicle(); | |
$form->sessionMessage('Vehicle locked successfully', 'good'); | |
return $this->owner->edit(Controller::curr()->getRequest()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment