Skip to content

Instantly share code, notes, and snippets.

@jrast
Created September 14, 2012 13:13
Show Gist options
  • Save jrast/3721833 to your computer and use it in GitHub Desktop.
Save jrast/3721833 to your computer and use it in GitHub Desktop.
Tutorial: FormActions selbst gebaut
<?php
class CancelFormAction extends FormAction {
private $link;
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);
}
/**
* @return string Link
*/
public function getLink()
{
return $this->Link;
}
/**
* @param string $Link
* @return CancleFormAction $this
*/
public function setLink($newLink)
{
$this->Link = $newLink;
return $this;
}
function Field() {
$attributes = array(
'class' => 'action cancel ' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'name' => $this->action,
'tabindex' => $this->getAttribute('tabindex'),
'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()
);
}
}
<?php
class CancelFormAction extends FormAction {
}
<?php
// Einfache Verwendung im Formular:
CancelFormAction::create($this->Link(), 'Abbrechen')
// Mit verketteten Funktionsaufrufen:
CancelFormAction::create($this->Link())->setTitle('Abbrechen')->addExtraClass('btn')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment