Created
April 3, 2015 02:46
-
-
Save muskie9/964094a3e9c73830a6df to your computer and use it in GitHub Desktop.
This field accepts an associative array as a source and handles FoxyCart value encryption if it's needed.
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 | |
/** | |
* Created by PhpStorm. | |
* User: nhorstmeier | |
* Date: 4/1/15 | |
* Time: 9:40 PM | |
*/ | |
class FoxyStripeDropdownField extends DropdownField{ | |
public function Field($properties = array()) { | |
$source = $this->getSource(); | |
$controller = Controller::curr(); | |
$code = $controller->data()->Code; | |
$newSource = $source; | |
$updated = array(); | |
foreach($newSource as $key => $val){ | |
$updated[ProductPage::getGeneratedValue($code, $this->getName(), $key, 'value')] = $val; | |
} | |
$source = $updated; | |
$options = array(); | |
if($source) { | |
// SQLMap needs this to add an empty value to the options | |
if(is_object($source) && $this->emptyString) { | |
$options[] = new ArrayData(array( | |
'Value' => '', | |
'Title' => $this->emptyString, | |
)); | |
} | |
foreach($source as $value => $title) { | |
$selected = false; | |
if($value === '' && ($this->value === '' || $this->value === null)) { | |
$selected = true; | |
} else { | |
// check against value, fallback to a type check comparison when !value | |
if($value) { | |
$selected = ($value == $this->value); | |
} else { | |
$selected = ($value === $this->value) || (((string) $value) === ((string) $this->value)); | |
} | |
$this->isSelected = $selected; | |
} | |
$disabled = false; | |
if(in_array($value, $this->disabledItems) && $title != $this->emptyString ){ | |
$disabled = 'disabled'; | |
} | |
$options[] = new ArrayData(array( | |
'Title' => $title, | |
'Value' => $value, | |
'Selected' => $selected, | |
'Disabled' => $disabled, | |
)); | |
} | |
} | |
$properties = array_merge($properties, array('Options' => new ArrayList($options))); | |
return parent::Field($properties); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment