protected function getAdditionalTemplateVariables() { $values = array(); $map = $this->getOptionDescriptor()->getAcceptableValues(); if (!tubepress_impl_util_LangUtils::isAssociativeArray($map)) { throw new InvalidArgumentException(sprintf('"%s" has a non-associative array set for its value map', $this->getOptionDescriptor()->getName())); } $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService(); foreach ($map as $key => $value) { $values[$key] = $messageService->_($value); } return array('choices' => $values); }
public function onSingleVideoTemplate(tubepress_api_event_EventInterface $event) { $template = $event->getSubject(); $context = tubepress_impl_patterns_sl_ServiceLocator::getExecutionContext(); $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService(); $optionDescriptorReference = tubepress_impl_patterns_sl_ServiceLocator::getOptionDescriptorReference(); $metaNames = tubepress_impl_util_LangUtils::getDefinedConstants('tubepress_api_const_options_names_Meta'); $shouldShow = array(); $labels = array(); foreach ($metaNames as $metaName) { $optionDescriptor = $optionDescriptorReference->findOneByName($metaName); $shouldShow[$metaName] = $context->get($metaName); $labels[$metaName] = $messageService->_($optionDescriptor->getLabel()); } $template->setVariable(tubepress_api_const_template_Variable::META_SHOULD_SHOW, $shouldShow); $template->setVariable(tubepress_api_const_template_Variable::META_LABELS, $labels); }
/** * Gets the failure message of a name/value pair that has failed validation. * * @param string $optionName The option name * @param mixed $candidate The candidate option value * * @return mixed Null if the option passes validation, otherwise a string failure message. */ public final function getProblemMessage($optionName, $candidate) { $optionDescriptorReferenceService = tubepress_impl_patterns_sl_ServiceLocator::getOptionDescriptorReference(); $messageService = tubepress_impl_patterns_sl_ServiceLocator::getMessageService(); $descriptor = $optionDescriptorReferenceService->findOneByName($optionName); if ($descriptor === null) { return sprintf('No option with name "%s".', $optionName); //>(translatable)< } if ($descriptor->hasValidValueRegex()) { if (preg_match_all($descriptor->getValidValueRegex(), (string) $candidate, $matches) >= 1 && $matches[0][0] === (string) $candidate) { return null; } return sprintf('Invalid value supplied for "%s".', $messageService->_($descriptor->getLabel())); //>(translatable)< } if ($descriptor->hasDiscreteAcceptableValues()) { $acceptableValues = $descriptor->getAcceptableValues(); if (tubepress_impl_util_LangUtils::isAssociativeArray($acceptableValues)) { $values = array_keys($descriptor->getAcceptableValues()); } else { $values = array_values($acceptableValues); } if (in_array($candidate, $values)) { return null; } return sprintf('"%s" must be one of "%s". You supplied "%s".', $messageService->_($descriptor->getLabel()), implode(', ', $values), $candidate); } if ($descriptor->isBoolean()) { if (is_bool($candidate)) { return null; } return sprintf('"%s" can only be "true" or "false". You supplied "%s".', $optionName, $candidate); //>(translatable)< } return null; }
public function setClassMap(array $map) { if (!empty($map) && !tubepress_impl_util_LangUtils::isAssociativeArray($map)) { throw new InvalidArgumentException('Class map must be an associative array'); } $this->_classMap = $map; }