-
-
Save hailwood/b799b7ed8179b8a88e3c 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
<?php | |
/** | |
* @package shop | |
*/ | |
class BrandFilterForm extends Form { | |
protected $currentFilter = []; | |
public function __construct($controller, $name = "BrandFilterForm") { | |
$this->currentFilter = Session::get('BrandFilter'); | |
parent::__construct( | |
$controller, | |
$name, | |
$this->getFormFields(), | |
$this->getFormActions() | |
); | |
$this->addExtraClass("brand-filter-form"); | |
$this->extend('updateBrandFilterForm'); | |
$this->setLegend('Brands'); | |
$this->disableSecurityToken(); | |
} | |
public function filterbrands($data, $form) { | |
$filters = $data['Filters']; | |
$this->currentFilter = $filters; | |
if (empty($filters)) { | |
Session::clear('BrandFilter'); | |
} else { | |
Session::set('BrandFilter', $filters); | |
} | |
return $this->controller->redirectBack(); | |
} | |
public function reset($data, $form) { | |
Session::clear('BrandFilter'); | |
$this->currentFilter = []; | |
return $this->controller->redirectBack(); | |
} | |
/** | |
* @return FieldList Fields for this form. | |
*/ | |
protected function getFormFields() { | |
$fields = new FieldList(); | |
$fields->push( | |
(new CheckboxSetField('Filters', '', ProductBrand::get('ProductBrand', 'Displayed=1')->map()->toArray(), $this->currentFilter)) | |
->setFieldHolderTemplate('BrandFilterCheckboxSetHolder') | |
); | |
return $fields; | |
} | |
/** | |
* @return FieldList Actions for this form. | |
*/ | |
protected function getFormActions() { | |
$fieldList = new FieldList( | |
FormAction::create('filterbrands', 'Filter') | |
->setUseButtonTag(true) | |
->addExtraClass('btn btn-main') | |
->setButtonContent('Filter') | |
); | |
if (!empty($this->currentFilter)) { | |
$removeAction = new FormAction('removefilter', 'Clear'); | |
$removeAction->setUseButtonTag(true); | |
$removeAction->addExtraClass('btn btn-compare pull-right'); | |
$removeAction->setButtonContent('Clear'); | |
$fieldList->push($removeAction); | |
} | |
return $fieldList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment