/**
  * Render the option tags.
  *
  * Extend the default handling by iterating over calculated options array and
  * try to translate the value
  *
  * @return array an associative array of options, key will be the value of the option tag
  */
 protected function getOptions()
 {
     $options = parent::getOptions();
     foreach ($options as $value => $label) {
         $options[$value] = $this->translateLabel($label);
     }
     return $options;
 }
Beispiel #2
0
 /**
  * Options
  *
  * @return array
  */
 protected function getOptions()
 {
     $options = parent::getOptions();
     if (!empty($this->arguments['defaultOption'])) {
         $options = ['' => $this->arguments['defaultOption']] + $options;
     }
     return $options;
 }
 /**
  * Render the option tags.
  *
  * @param $optionOverride added by nnaddress
  * @return array an associative array of options, key will be the value of the option tag
  */
 protected function getOptions($optionOverride = NULL)
 {
     if (!$this->arguments['renderSubGroups']) {
         return parent::getOptions();
     }
     if (!is_array($this->arguments['options']) && !$this->arguments['options'] instanceof \Traversable) {
         return array();
     }
     $options = array();
     $optionsArgument = $optionOverride ? $optionOverride : $this->arguments['options'];
     foreach ($optionsArgument as $key => $value) {
         if (is_object($value)) {
             // Added by NN Address
             $childOptions = $this->getOptions($value->getChildGroups());
             if ($this->hasArgument('optionValueField')) {
                 $key = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments['optionValueField']);
                 if (is_object($key)) {
                     if (method_exists($key, '__toString')) {
                         $key = (string) $key;
                     } else {
                         throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Identifying value for object of class "' . get_class($value) . '" was an object.', 1247827428);
                     }
                 }
                 // TODO: use $this->persistenceManager->isNewObject() once it is implemented
             } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) {
                 $key = $this->persistenceManager->getIdentifierByObject($value);
             } elseif (method_exists($value, '__toString')) {
                 $key = (string) $value;
             } else {
                 throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('No identifying value for object of class "' . get_class($value) . '" found.', 1247826696);
             }
             if ($this->hasArgument('optionLabelField')) {
                 $value = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::getPropertyPath($value, $this->arguments['optionLabelField']);
                 if (is_object($value)) {
                     if (method_exists($value, '__toString')) {
                         $value = (string) $value;
                     } else {
                         throw new \TYPO3\CMS\Fluid\Core\ViewHelper\Exception('Label value for object of class "' . get_class($value) . '" was an object without a __toString() method.', 1247827553);
                     }
                 }
             } elseif (method_exists($value, '__toString')) {
                 $value = (string) $value;
                 // TODO: use $this->persistenceManager->isNewObject() once it is implemented
             } elseif ($this->persistenceManager->getIdentifierByObject($value) !== NULL) {
                 $value = $this->persistenceManager->getIdentifierByObject($value);
             }
         }
         $options[$key] = $value;
         // Added by NN Address
         if (sizeof($childOptions) > 0) {
             $options = $options + $childOptions;
         }
     }
     if ($this->arguments['sortByOptionLabel']) {
         asort($options, SORT_LOCALE_STRING);
     }
     return $options;
 }
 /**
  * Render the options tag, but with modifications if our special arguments have been specified.
  * @return array an associative array of options, key will be the value of the option tag
  */
 protected function getOptions()
 {
     $options = parent::getOptions();
     if ($this->hasArgument('nullOption')) {
         $label = $this->arguments['nullOption'];
         $options = array('' => $label) + $options;
     }
     return $options;
 }
 /**
  * Render the option tags.
  *
  * @return array an associative array of options, key will be the value of the option tag
  * @author Michael Knoll <*****@*****.**>
  */
 protected function getOptions()
 {
     $options = parent::getOptions();
     if ($this->arguments['emptyOption']) {
         $newOptions = array();
         $newOptions[0] = $this->arguments['emptyOption'];
         foreach ($options as $key => $value) {
             $newOptions[$key] = $value;
         }
         $options = $newOptions;
     }
     return $options;
 }
Beispiel #6
0
 /**
  * @return array
  */
 protected function getOptions()
 {
     if (FALSE === empty($this->arguments['table'])) {
         $table = $this->arguments['table'];
         $labelField = $GLOBALS['TCA'][$this->arguments['table']]['ctrl']['label'];
         if (TRUE === $this->hasArgument('optionLabelField') && $this->arguments['optionLabelField'] !== $labelField) {
             $labelField = $this->arguments['optionLabelField'];
         } else {
             $this->arguments['optionLabelField'] = $labelField;
         }
         if (TRUE === empty($this->arguments['optionValueField'])) {
             $this->arguments['optionValueField'] = 'uid';
         }
         $clause = '1=1 ' . $this->configurationManager->getContentObject()->enableFields($table);
         $fields = trim($labelField . ',' . $this->arguments['optionValueField'], ',');
         $this->arguments['options'] = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($fields, $table, $clause);
     } elseif (FALSE === empty($this->arguments['csv'])) {
         $exploded = GeneralUtility::trimExplode(',', $this->arguments['csv']);
         $this->arguments['options'] = array_combine($exploded, $exploded);
     }
     $first = reset($this->arguments['options']);
     $options = array();
     if (TRUE === isset($first['item']) && 1 === count($first) && 2 === count($first['item'])) {
         foreach ($this->arguments['options'] as $item) {
             list($name, $value) = array_values($item['item']);
             $options[$value] = $name;
         }
         $this->arguments['options'] = $options;
     } elseif (2 === count($first)) {
         foreach ($this->arguments['options'] as $item) {
             list($name, $value) = array_values($item);
             $options[$value] = FALSE === empty($name) ? $name : '[' . $this->arguments['optionValueField'] . ':' . $value . ']';
         }
         $this->arguments['options'] = $options;
     }
     return parent::getOptions();
 }
 /**
  * Options
  *
  * @return array
  */
 protected function getOptions()
 {
     return array('' => $this->arguments['defaultOption']) + parent::getOptions();
 }
 /**
  * Render the Options.
  *
  * @throws Exception
  * @return string
  * @api
  */
 public function getOptions()
 {
     $this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, $this->extensionName);
     if (!$this->hasArgument('staticInfoTable') || $this->arguments['staticInfoTable'] == '') {
         throw new \Exception('Please configure the "staticInfoTable"-Argument for this ViewHelper.', 1378136534);
     }
     /** @var \SJBR\StaticInfoTables\Domain\Repository\AbstractEntityRepository $repository */
     $repository = $this->arguments['staticInfoTable'] . 'Repository';
     if (!in_array($repository, get_object_vars($this))) {
         throw new \Exception('Please configure the right table in the "staticInfoTable"-Argument for this ViewHelper.', 1378136533);
     }
     /** @var array $items */
     $items = $this->emitGetItems($repository);
     /** @var string $valueFunction */
     $valueFunction = $this->getMethodnameFromArgumentsAndUnset('optionValueField', 'uid');
     /** @var string $labelFunction */
     $labelFunction = $this->getMethodnameFromArgumentsAndUnset('optionLabelField', 'nameLocalized');
     if (!$this->settings['countriesAllowed'] && (!$this->hasArgument('sortByOptionLabel') || $this->arguments['sortByOptionLabel'] == '')) {
         $this->arguments['sortByOptionLabel'] = true;
     }
     /** @var bool $test Test only the first item if they have the needed functions */
     $test = true;
     $options = array();
     /** @var \SJBR\StaticInfoTables\Domain\Model\AbstractEntity $item */
     foreach ($items as $item) {
         if ($test && !method_exists($item, $valueFunction)) {
             throw new \Exception('Wrong optionValueField.', 1378136535);
         }
         if ($test && !method_exists($item, $labelFunction)) {
             throw new \Exception('Wrong optionLabelField.', 1378136536);
         }
         $test = false;
         $value = $item->{$valueFunction}();
         $label = $item->{$labelFunction}();
         if ($value != '' && $label != '') {
             $options[$value] = $label;
         }
     }
     $this->arguments['options'] = $options;
     $sortedOptions = parent::getOptions();
     // Put default option after sorting to get it to the top of the items
     if ($this->hasArgument('defaultOptionLabel')) {
         $defaultOptionLabel = $this->arguments['defaultOptionLabel'];
         $defaultOptionValue = $this->hasArgument('defaultOptionValue') ? $this->arguments['defaultOptionValue'] : 0;
         $sortedOptions = array($defaultOptionValue => $defaultOptionLabel) + $sortedOptions;
     }
     return $sortedOptions;
 }