Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function getAdditionalTemplateVariables()
 {
     $map = $this->_acceptableValues->getAcceptableValues($this->getOptionName());
     if (!$this->_langUtils->isAssociativeArray($map)) {
         throw new InvalidArgumentException(sprintf('"%s" has a non-associative array set for its value map', $this->getId()));
     }
     return array('ungroupedChoices' => $map);
 }
 public function onOption(tubepress_api_event_EventInterface $event)
 {
     $errors = $event->getSubject();
     $optionName = $event->getArgument('optionName');
     $optionValue = $event->getArgument('optionValue');
     if (!$this->_optionsReference->optionExists($optionName)) {
         $error = $this->_translator->trans('No option with name "%s".');
         //>(translatable)<
         $error = sprintf($error, $optionName);
         $errors[] = $error;
         $event->setSubject($errors);
         return;
     }
     if ($this->_optionsReference->isBoolean($optionName) && !is_bool($optionValue)) {
         $error = $this->_translator->trans('"%s" can only be "true" or "false". You supplied "%s".');
         //>(translatable)<
         $error = sprintf($error, $this->_getLabel($optionName), $optionValue);
         $errors[] = $error;
         $event->setSubject($errors);
         return;
     }
     $acceptableValues = $this->_acceptableValues->getAcceptableValues($optionName);
     if ($acceptableValues !== null) {
         if ($this->_langUtils->isAssociativeArray($acceptableValues)) {
             $values = array_keys($acceptableValues);
         } else {
             $values = array_values($acceptableValues);
         }
         if (!in_array($optionValue, $values)) {
             $error = $this->_translator->trans('"%s" must be one of "%s". You supplied "%s".');
             //>(translatable)<
             $error = sprintf($error, $this->_getLabel($optionName), implode(', ', $values), $optionValue);
             $errors[] = $error;
             $event->setSubject($errors);
         }
     }
 }