allow to render choice in different columns

This commit is contained in:
Julien Fastré 2018-06-12 17:58:45 +02:00
parent 2042e43613
commit 0371236493

View File

@ -330,4 +330,67 @@ class CustomFieldChoice extends AbstractCustomField
{ {
return $value; return $value;
} }
public function getChoices(CustomField $cf)
{
if ($cf->getOptions()[self::MULTIPLE]) {
$choices = array();
foreach ($cf->getOptions()[self::CHOICES] as $choice) {
if ($choices['active'] === false) {
continue;
}
$choices[$choice["slug"]] = $this->translatableStringHelper
->localize($choice["name"]);
}
if ($this->allowOtherChoice($cf)) {
$labels = $cf->getOptions()[self::OTHER_VALUE_LABEL];
if (!is_array($labels) or count($labels) === 0) {
$labels['back'] = 'other value';
}
$choices['_other'] = $this->translatableStringHelper
->localize($labels);
}
return $choices;
} else {
return [
$cf->getSlug() => $this->translatableStringHelper->localize($cf->getName())
];
}
}
public function isChecked(CustomField $cf, $choiceSlug, $data)
{
$deserialized = $this->deserialize($data, $cf);
if ($deserialized === null) {
return false;
}
dump($deserialized);
if ($cf->getOptions()[self::MULTIPLE]) {
return \in_array($choiceSlug, $deserialized);
} else {
return $data === $choiceSlug;
}
}
public function isMultiple(CustomField $cf)
{
return $cf->getOptions()[self::MULTIPLE];
}
public function allowOtherChoice(CustomField $cf)
{
return $cf->getOptions()[self::ALLOW_OTHER];
}
public function extractOtherValue(CustomField $cf, array $data = null)
{
dump('extracting');
dump($data);
return $data['_other'];
}
} }