From 03712364937c108fc037002f65830fdecbac7f99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 12 Jun 2018 17:58:45 +0200 Subject: [PATCH] allow to render choice in different columns --- CustomFields/CustomFieldChoice.php | 63 ++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/CustomFields/CustomFieldChoice.php b/CustomFields/CustomFieldChoice.php index 927bd3ead..26d6394ed 100644 --- a/CustomFields/CustomFieldChoice.php +++ b/CustomFields/CustomFieldChoice.php @@ -330,4 +330,67 @@ class CustomFieldChoice extends AbstractCustomField { 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']; + } }