Skip to content

Instantly share code, notes, and snippets.

@wilr
Created April 5, 2012 10:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wilr/2309951 to your computer and use it in GitHub Desktop.
Save wilr/2309951 to your computer and use it in GitHub Desktop.
Cancel form action for SilverStripe
<?php
/**
* Action that takes the user back to a given link rather than submitting
* the form.
*
* @package cancelformaction
*/
class CancelFormAction extends FormAction {
/**
* @var string
*/
private $link;
function __construct($link = "", $title = "", $form = null, $extraData = null, $extraClass = '') {
if(!$title) $title = _t('CancelFormAction.CANCEL', 'Cancel');
$this->setLink($link);
parent::__construct('CancelFormAction', $title, $form, $extraData, $extraClass);
}
function setLink($link) {
$this->link = $link;
}
function getLink() {
return $this->link;
}
function Field() {
$attributes = array(
'class' => 'action cancel ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $this->action,
'tabindex' => $this->getTabIndex(),
'href' => $this->getLink()
);
if($this->isReadonly()) {
$attributes['disabled'] = 'disabled';
$attributes['class'] = $attributes['class'] . ' disabled';
}
return $this->createTag(
'a',
$attributes,
$this->buttonContent ? $this->buttonContent : $this->Title()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment