/**
  * Override the initialize method to load all available country
  * zones for a given parent country before rendering
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     if ($this->hasArgument('parent') && $this->arguments['parent'] != '' && \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
         $this->arguments['options'] = $this->countryZonesRepository->findAllByIso2($this->arguments['parent']);
     }
 }
 /**
  * Override the initialize method to load all available
  * countries before rendering
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
         if ($this->hasArgument('allowedCountries') && count($this->arguments['allowedCountries'])) {
             $result = $this->countryRepository->findByIsoCodeA2($this->arguments['allowedCountries']);
         } else {
             $result = $this->countryRepository->findAll();
         }
         if (!empty($this->arguments['allowedCountries'])) {
             $orderedResults = array();
             foreach ($this->arguments['allowedCountries'] as $countryKey) {
                 foreach ($result as $country) {
                     if ($country->getIsoCodeA2() == $countryKey) {
                         $orderedResults[] = $country;
                     }
                 }
             }
             $result = $orderedResults;
         }
         $this->arguments['options'] = array();
         foreach ($result as $country) {
             $this->arguments['options'][] = $country;
         }
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Override the initialize method to load all
  * available languages before rendering
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables')) {
         if ($this->hasArgument('allowedLanguages') && count($this->arguments['allowedLanguages'])) {
             $this->arguments['options'] = $this->languageRepository->findByLgCollateLocale($this->arguments['allowedLanguages']);
         } else {
             $this->arguments['options'] = $this->languageRepository->findAll();
         }
     }
 }
 /**
  * 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 #8
0
 /**
  * Retrieves the selected value(s)
  *
  * @return mixed value string or an array of strings
  */
 protected function getSelectedValue()
 {
     $selectedValue = parent::getSelectedValue();
     // set preselection from TypoScript
     if (empty($selectedValue)) {
         $controllerName = strtolower($this->controllerContext->getRequest()->getControllerName());
         $cObj = $this->configurationManager->getContentObject();
         $typoScript = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
         $prefillTypoScript = $typoScript['plugin.']['tx_femanager.']['settings.'][$controllerName . '.']['prefill.'];
         $selectedValue = $cObj->cObjGetSingle($prefillTypoScript[$this->getFieldName()], $prefillTypoScript[$this->getFieldName() . '.']);
     }
     return $selectedValue;
 }
 /**
  * @test
  */
 public function optionsContainPrependedItemWithCorrectValueIfPrependOptionLabelAndPrependOptionValueAreSet()
 {
     $this->tagBuilder->expects($this->once())->method('addAttribute')->with('name', 'myName');
     $this->viewHelper->expects($this->once())->method('registerFieldNameForFormTokenGeneration')->with('myName');
     $this->tagBuilder->expects($this->once())->method('setContent')->with('<option value="-1">please choose</option>' . chr(10) . '<option value="value1">label1</option>' . chr(10) . '<option value="value2">label2</option>' . chr(10) . '<option value="value3">label3</option>' . chr(10));
     $this->tagBuilder->expects($this->once())->method('render');
     $this->arguments['options'] = array('value1' => 'label1', 'value2' => 'label2', 'value3' => 'label3');
     $this->arguments['name'] = 'myName';
     $this->arguments['prependOptionLabel'] = 'please choose';
     $this->arguments['prependOptionValue'] = '-1';
     $this->injectDependenciesIntoViewHelper($this->viewHelper);
     $this->viewHelper->initialize();
     $this->viewHelper->render();
 }
Beispiel #10
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();
 }
Beispiel #11
0
 /**
  * @return string
  */
 public function render()
 {
     $this->arguments['options'] = $this->buildOptions($this->buildCategoryData());
     return parent::render();
 }
 /**
  * Get value conditional to TYPO3 version
  *
  * @param bool $convertObjects should also be removed - see todo below
  * @return mixed
  * @todo remove condition for TYPO3 6.2 in upcoming major version
  */
 public function getValue($convertObjects = true)
 {
     if (method_exists($this, 'getValueAttribute')) {
         return parent::getValueAttribute();
     } else {
         return parent::getValue($convertObjects);
     }
 }
 /**
  * @param Tx_PtExtlist_Domain_Model_List_Header_ListHeader $headers
  */
 public function render()
 {
     $columns = $this->arguments['columns'];
     $options = array();
     $selectedOptions = array();
     foreach ($columns as $columnIdentifier => $column) {
         /** @var $column Tx_PtExtlist_Domain_Model_List_Header_HeaderColumn */
         if (!($this->columnSelectorConfig->getHideDefaultVisibleInSelector() && $column->getColumnConfig()->getIsVisible())) {
             $options[$columnIdentifier] = $this->captionRenderer->renderColumnLabel($column);
         }
         if ($column->getIsVisible()) {
             $selectedOptions[] = $columnIdentifier;
         }
     }
     // This hack is needed to be backwards compatible to Fluid 1.3.0 where arguments was an object
     if (is_a($this->arguments, 'Tx_Fluid_Core_ViewHelper_Arguments')) {
         $arg = (array) $this->arguments;
         $arg['multiple'] = 1;
         $arg['name'] = $this->arguments['name'];
         $arg['options'] = $options;
         $arg['value'] = $selectedOptions;
         $this->arguments = new \TYPO3\CMS\Fluid\Core\ViewHelper\Arguments($arg);
     } else {
         $this->arguments['options'] = $options;
         $this->arguments['value'] = $selectedOptions;
     }
     return parent::render();
 }
 /**
  * Arguments initialization
  *
  * @return void
  */
 public function initializeArguments()
 {
     parent::initializeArguments();
     $this->registerArgument('optionIcon', 'string', 'If specified, will show the given icon in front of each option label.');
 }
 /**
  * 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;
 }
 /**
  * Initialize arguments.
  *
  * @return void
  * @api
  */
 public function initializeArguments()
 {
     parent::initializeArguments();
     $this->registerArgument('optionDataAttributes', 'array', 'Additional data-attributes for options: data-{key}="property:{value}"', false);
 }
Beispiel #17
0
 /**
  * Initialize arguments.
  *
  * @return void
  * @api
  */
 public function initializeArguments()
 {
     parent::initializeArguments();
     $this->registerTagAttribute('onchange', 'string', 'Event when selection is changed');
 }
Beispiel #18
0
 /**
  * Render one option tag
  *
  * @param string $value value attribute of the option tag (will be escaped)
  * @param string $label content of the option tag (will be escaped)
  * @return string the rendered option tag
  */
 protected function renderOptionTag($value, $label)
 {
     return parent::renderOptionTag($value, $label, $this->isSelectedAlternative($this->getOptionFromOriginalOptionsByValue($value)));
 }
Beispiel #19
0
 /**
  * Render the tag.
  *
  * @return string rendered tag.
  * @api
  */
 public function render()
 {
     $content = parent::render();
     return $content;
 }
 /**
  * Get value conditional to TYPO3 version
  *
  * @return mixed
  * @todo remove condition for TYPO3 6.2 in upcoming major version
  */
 public function getValue()
 {
     if (method_exists($this, 'getValueAttribute')) {
         return parent::getValueAttribute();
     } else {
         return parent::getValue();
     }
 }
 /**
  * Options
  *
  * @return array
  */
 protected function getOptions()
 {
     return array('' => $this->arguments['defaultOption']) + parent::getOptions();
 }
 /**
  * Rendering of selectbox
  *
  * @param integer $start
  * @param integer $end
  * @param integer $step
  * @param integer $digits
  *
  * @return string
  */
 public function render($start, $end, $step = 1, $digits = 2)
 {
     $this->start = $start;
     $this->end = $end;
     $this->step = $step;
     $this->digits = (int) $digits;
     return parent::render();
 }