2013-04-24 09:57:33 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A dropdown field which allows the user to select a country
|
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
|
|
|
class EditableCountryDropdownField extends EditableFormField {
|
|
|
|
|
2013-06-02 14:05:16 +12:00
|
|
|
private static $singular_name = 'Country Dropdown';
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-06-02 14:05:16 +12:00
|
|
|
private static $plural_name = 'Country Dropdowns';
|
2015-07-24 14:37:48 +12:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields() {
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
|
|
|
$fields->removeByName('Default');
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-04-24 09:57:33 -07:00
|
|
|
public function getFormField() {
|
2015-08-21 15:21:33 +12:00
|
|
|
$field = CountryDropdownField::create($this->Name, $this->EscapedTitle)
|
|
|
|
->setFieldHolderTemplate('UserFormsField_holder')
|
|
|
|
->setTemplate('UserFormsDropdownField');
|
|
|
|
|
2015-08-10 17:03:36 +12:00
|
|
|
$this->doUpdateFormField($field);
|
2015-08-21 15:21:33 +12:00
|
|
|
|
2015-08-10 17:03:36 +12:00
|
|
|
return $field;
|
2013-04-24 09:57:33 -07:00
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-04-24 09:57:33 -07:00
|
|
|
public function getValueFromData($data) {
|
|
|
|
if(isset($data[$this->Name])) {
|
2013-08-29 14:03:09 +12:00
|
|
|
$source = $this->getFormField()->getSource();
|
|
|
|
return $source[$data[$this->Name]];
|
2013-04-24 09:57:33 -07:00
|
|
|
}
|
|
|
|
}
|
2015-09-11 10:20:06 +12:00
|
|
|
|
2013-04-24 09:57:33 -07:00
|
|
|
public function getIcon() {
|
2015-09-24 10:40:30 +12:00
|
|
|
return USERFORMS_DIR . '/images/editabledropdown.png';
|
2013-04-24 09:57:33 -07:00
|
|
|
}
|
2015-08-13 11:31:37 +12:00
|
|
|
|
|
|
|
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false) {
|
|
|
|
return "$(\"select[name='{$this->Name}']\")";
|
|
|
|
}
|
2013-04-24 09:57:33 -07:00
|
|
|
}
|