2013-04-24 18:57:33 +02:00
|
|
|
<?php
|
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Model\EditableFormField;
|
|
|
|
|
2017-08-13 23:26:53 +02:00
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
2017-08-14 00:06:17 +02:00
|
|
|
use SilverStripe\Forms\DropdownField;
|
|
|
|
use SilverStripe\i18n\i18n;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableCustomRule;
|
2017-08-11 02:36:28 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2013-04-24 18:57:33 +02:00
|
|
|
/**
|
|
|
|
* A dropdown field which allows the user to select a country
|
|
|
|
*
|
|
|
|
* @package userforms
|
|
|
|
*/
|
2016-07-21 07:53:59 +02:00
|
|
|
class EditableCountryDropdownField extends EditableFormField
|
|
|
|
{
|
|
|
|
private static $singular_name = 'Country Dropdown';
|
|
|
|
|
|
|
|
private static $plural_name = 'Country Dropdowns';
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $table_name = 'EditableCountryDropdownField';
|
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
/**
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
|
|
|
$fields->removeByName('Default');
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFormField()
|
|
|
|
{
|
2017-08-14 00:06:17 +02:00
|
|
|
$field = DropdownField::create($this->Name, $this->EscapedTitle)
|
|
|
|
->setSource(i18n::getData()->getCountries())
|
2017-09-04 23:45:16 +02:00
|
|
|
->setFieldHolderTemplate(EditableFormField::class . '_holder')
|
|
|
|
->setTemplate(EditableDropdown::class);
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
$this->doUpdateFormField($field);
|
|
|
|
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getValueFromData($data)
|
|
|
|
{
|
|
|
|
if (isset($data[$this->Name])) {
|
|
|
|
$source = $this->getFormField()->getSource();
|
|
|
|
return $source[$data[$this->Name]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIcon()
|
|
|
|
{
|
2017-11-02 22:44:45 +01:00
|
|
|
$resource = ModuleLoader::getModule('silverstripe/userforms')->getResource('images/editabledropdown.png');
|
|
|
|
|
|
|
|
if (!$resource->exists()) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $resource->getURL();
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSelectorField(EditableCustomRule $rule, $forOnLoad = false)
|
|
|
|
{
|
|
|
|
return "$(\"select[name='{$this->Name}']\")";
|
|
|
|
}
|
|
|
|
}
|