Skip to content

Instantly share code, notes, and snippets.

@muskie9
Created April 16, 2019 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muskie9/d78f8f07faa03ba39ac02b49036596a7 to your computer and use it in GitHub Desktop.
Save muskie9/d78f8f07faa03ba39ac02b49036596a7 to your computer and use it in GitHub Desktop.
<?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;
/**
* CancelFormAction constructor.
* @param string $link
* @param string $title
* @param null $form
* @param null $extraData
* @param string $extraClass
*/
public 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);
}
/**
* @param $link
*/
public function setLink($link)
{
$this->link = $link;
}
/**
* @return string
*/
public function getLink()
{
return $this->link;
}
/**
* @param array $properties
* @return string
*/
public function Field($properties = array())
{
$attributes = array(
'class' => 'cancel btn ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $this->action,
'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