mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix change API to hasEmptyDefault() to be inline with SingleSelectField
This commit is contained in:
parent
3927e7e248
commit
287ad35f0d
@ -69,19 +69,14 @@ class TreeDropdownField extends FormField
|
|||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title to display when the value is empty
|
|
||||||
*
|
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $emptyTitle = null;
|
protected $emptyString = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the Empty title as the option for "root" when TreeDropdown is on the root,
|
|
||||||
* that way the root option is explicitly selectable.
|
|
||||||
*
|
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
protected $showRootOption = false;
|
protected $hasEmptyDefault = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class name for underlying object
|
* Class name for underlying object
|
||||||
@ -343,7 +338,7 @@ class TreeDropdownField extends FormField
|
|||||||
} elseif ($record) {
|
} elseif ($record) {
|
||||||
$title = Convert::raw2xml($record->{$this->labelField});
|
$title = Convert::raw2xml($record->{$this->labelField});
|
||||||
} else {
|
} else {
|
||||||
$title = $this->getEmptyTitle();
|
$title = $this->getEmptyString();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Implement for TreeMultiSelectField
|
// TODO Implement for TreeMultiSelectField
|
||||||
@ -356,7 +351,7 @@ class TreeDropdownField extends FormField
|
|||||||
$properties,
|
$properties,
|
||||||
array(
|
array(
|
||||||
'Title' => $title,
|
'Title' => $title,
|
||||||
'EmptyTitle' => $this->getEmptyTitle(),
|
'EmptyTitle' => $this->getEmptyString(),
|
||||||
'Metadata' => ($metadata) ? Convert::raw2json($metadata) : null,
|
'Metadata' => ($metadata) ? Convert::raw2json($metadata) : null,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -666,70 +661,60 @@ class TreeDropdownField extends FormField
|
|||||||
{
|
{
|
||||||
$data = parent::getSchemaDataDefaults();
|
$data = parent::getSchemaDataDefaults();
|
||||||
$data['data']['urlTree'] = $this->Link('tree');
|
$data['data']['urlTree'] = $this->Link('tree');
|
||||||
$data['data']['emptyTitle'] = $this->getEmptyTitle();
|
$data['data']['emptyString'] = $this->getEmptyString();
|
||||||
$data['data']['showRootOption'] = $this->getShowRootOption();
|
$data['data']['hasEmptyDefault'] = $this->getHasEmptyDefault();
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether to show the Empty title as the option for root
|
* @param boolean $bool
|
||||||
*
|
* @return self Self reference
|
||||||
* @param $emptyOption
|
|
||||||
* @return $this
|
|
||||||
*/
|
*/
|
||||||
public function setShowRootOption($showRoot)
|
public function setHasEmptyDefault($bool)
|
||||||
{
|
{
|
||||||
$this->showRootOption = $showRoot;
|
$this->hasEmptyDefault = $bool;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get whether to show the Empty title as the option for root
|
|
||||||
*
|
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function getShowRootOption()
|
public function getHasEmptyDefault()
|
||||||
{
|
{
|
||||||
// don't show empty option if no empty title is set
|
return $this->hasEmptyDefault;
|
||||||
if ($this->emptyTitle === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->showRootOption;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the empty title displayed
|
* Set the default selection label, e.g. "select...".
|
||||||
|
* Defaults to an empty string. Automatically sets
|
||||||
|
* {@link $hasEmptyDefault} to true.
|
||||||
*
|
*
|
||||||
* @param string $title
|
* @param string $string
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setEmptyTitle($title)
|
public function setEmptyString($string)
|
||||||
{
|
{
|
||||||
$this->emptyTitle = $title;
|
$this->setHasEmptyDefault(true);
|
||||||
|
$this->emptyString = $string;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the empty title displayed
|
|
||||||
*
|
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getEmptyTitle()
|
public function getEmptyString()
|
||||||
{
|
{
|
||||||
if ($this->emptyTitle !== null) {
|
if ($this->emptyString !== null) {
|
||||||
return $this->emptyTitle;
|
return $this->emptyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = DataObject::singleton($this->sourceObject);
|
$item = DataObject::singleton($this->sourceObject);
|
||||||
$emptyTitle = _t(
|
$emptyString = _t(
|
||||||
'SilverStripe\\Forms\\DropdownField.CHOOSE_MODEL',
|
'SilverStripe\\Forms\\DropdownField.CHOOSE_MODEL',
|
||||||
'(Choose {name})',
|
'(Choose {name})',
|
||||||
['name' => $item->i18n_singular_name()]
|
['name' => $item->i18n_singular_name()]
|
||||||
);
|
);
|
||||||
return $emptyTitle;
|
return $emptyString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user