/** * @inheritdoc */ public function render(array &$output) { $innerIdPrefix = sprintf('%s-%s', $this->getField()->getName(), $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ID_PREFIX)); // Add the outer container element open tag. $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ATTRIBUTES))); // Add a hidden field (note: using the raw field name always without [] appended) to reset the value each post. $output[] = sprintf('<input type="hidden" name="%s" value="" />', $this->getField()->getName()); // Add the input elements and value labels, one for each available value. $value = $this->getFieldValue(); foreach ($this->getField()->getValues() as $option) { // Add the input element itself. $optionId = sprintf('%s-%s', $innerIdPrefix, NameUtilities::convertToDashedLower($option['value'])); $optionAttributes = array_merge($this->getRenderOption(self::RENDER_OPTION_KEY_ATTRIBUTES), array('id' => $optionId, 'value' => $option['value'], 'type' => $this->getField()->getType(), 'class' => $this->getField()->getType())); if (is_array($value) && in_array($option['value'], $value)) { $optionAttributes['checked'] = 'checked'; } $input = sprintf('<input%s />', HtmlUtilities::attributes($optionAttributes)); // Add the input label element. $inputLabelAttributes = array('for' => $optionId, 'class' => sprintf('multiple-input-label %s-label', $this->getField()->getType())); $inputLabel = sprintf('<label%s>%s</label>', HtmlUtilities::attributes($inputLabelAttributes), $option['label']); // Add the inner wrapper. $optionWrapperAttributes = $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ATTRIBUTES); $optionWrapperAttributes['id'] = sprintf('%s-container', $innerIdPrefix); $output[] = sprintf('<%s%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME), HtmlUtilities::attributes($optionWrapperAttributes)); if ($this->getRenderOption(self::RENDER_OPTION_KEY_LABELS_FIRST)) { $output[] = $inputLabel; $output[] = $input; } else { $output[] = $input; $output[] = $inputLabel; } $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_INNER_WRAPPER_ELEMENT_NAME)); } // Add the outer container element end tag. $output[] = sprintf('</%s>', $this->getRenderOption(self::RENDER_OPTION_KEY_OUTER_WRAPPER_ELEMENT_NAME)); }
public function testConvertToDashedLower() { $this->assertEquals('from-camel-case', NameUtilities::convertToDashedLower('fromCamelCase')); $this->assertEquals('from-studly-caps', NameUtilities::convertToDashedLower('FromStudlyCaps')); $this->assertEquals('from-dashed-lower', NameUtilities::convertToDashedLower('from-dashed-lower')); $this->assertEquals('from-underscore-lower', NameUtilities::convertToDashedLower('from-underscore-lower')); $this->assertEquals('from-underscore-caps', NameUtilities::convertToDashedLower('From_Underscore_Caps')); $this->assertEquals('from-lower-case', NameUtilities::convertToDashedLower('from lower case')); $this->assertEquals('from-title-case', NameUtilities::convertToDashedLower('From Title Case')); $this->assertEquals('this-one-isnt-easy-a-test-case-sitegear-org', NameUtilities::convertToDashedLower('This One Isn\'t Easy - A Test Case @ sitegear.org')); }
/** * Initialise the routing for this Engine. */ protected function compileRouteCollection(Request $request) { // Setup the request context. $context = new RequestContext(); $context->fromRequest($request); // Compile the collection. $this->compiledRouteCollection = new RouteCollection(); foreach ($this->getRawRouteMap() as $urlMapEntry) { $module = $this->getModule($urlMapEntry['module']); /** @var \Sitegear\Module\MountableModuleInterface $module */ $module->mount('/' . trim($urlMapEntry['root'], '/'), $context); $routes = $module->getRoutes(); if (!empty($routes)) { $routeNamespace = NameUtilities::convertToDashedLower($urlMapEntry['module']); foreach ($routes as $routeName => $routeObject) { $this->compiledRouteCollection->add(sprintf('%s:%s', $routeNamespace, $routeName), $routeObject); } } } }
/** * @inheritdoc * * This implementation allows the use of a simple syntax in view scripts to render nested view scripts. * * $view->section()->[sectionName]() * $view->component()->[componentName]() * $view->[moduleName]()->[componentName]() * * These all follow the same pattern; the first call specifies the source of the content, and the second call * specifies the exact target. The special strings 'section', 'component' and 'template' can be used in the first * position. The 'section' special string maps to the controller module; the 'component' and 'template' special * strings map to the Content module. * * For every occurrence encountered of the above syntax patterns in a view script, a new View object is * created dynamically. If the syntax is incorrect, e.g. if there are more or less than 2 chained method calls, * then an error message is output. */ public function __call($name, $arguments) { if (!$this->rendering) { // We are not rendering yet, so push a target onto the stack. $this->pushTarget(NameUtilities::convertToDashedLower($name), $arguments); } else { // We are already rendering this view, and the view script is requesting a child view; create it and call // the requested method on it (which will set the new view's first target, because the child view is not // rendering). $childView = $this->getEngine()->getViewFactory()->buildView($this->getRequest(), $this); return call_user_func_array(array($childView, $name), $arguments); } return $this; }
/** * @inheritdoc */ public function applyViewDefaults(ViewInterface $view, $viewType, $viewName) { LoggerRegistry::debug('{class}::applyViewDefaults([view], {viewType}, {viewName})', array('class' => (new \ReflectionClass($this))->getShortName(), 'viewType' => TypeUtilities::describe($viewType), 'viewName' => TypeUtilities::describe($viewName))); $this->applyConfigToView('common', $view); $this->applyConfigToView(sprintf('%s.%s', NameUtilities::convertToDashedLower($viewType), NameUtilities::convertToDashedLower($viewName)), $view); }
/** * @inheritdoc */ protected function normaliseRenderOptions() { return ArrayUtilities::combine(parent::normaliseRenderOptions(), array(self::RENDER_OPTION_KEY_ELEMENT_NAME => 'fieldset', self::RENDER_OPTION_KEY_ATTRIBUTES => array('id' => sprintf('sitegear-fieldset-%s', NameUtilities::convertToDashedLower($this->getFieldset()->getHeading()))))); }
/** * @inheritdoc */ public function getSitePath($location, $resource, ModuleInterface $module = null) { // Ensure the passed-in resource has no leading slashes and no surrounding whitespace $resource = ltrim(trim($resource), '/'); switch ($location) { case ResourceLocations::RESOURCE_LOCATION_SITE: // For the site level, the module name must be inserted $root = $this->getSiteRoot(); $resource = sprintf('%s/%s', NameUtilities::convertToDashedLower($this->engine->getModuleName($module)), $resource); break; case ResourceLocations::RESOURCE_LOCATION_VENDOR: throw new \InvalidArgumentException('The "vendor" location identifier cannot be used for site paths'); case ResourceLocations::RESOURCE_LOCATION_MODULE: $root = sprintf('%s/%s', $module->getModuleRoot(), ResourceLocations::RESOURCES_DIRECTORY); break; case ResourceLocations::RESOURCE_LOCATION_ENGINE: $root = sprintf('%s/%s', $this->engine->getEngineRoot(), ResourceLocations::RESOURCES_DIRECTORY); break; default: throw new \InvalidArgumentException(sprintf('Cannot find site resource in unknown location "%s"', $location)); } return sprintf('%s/site/%s', $root, $resource); }
/** * @inheritdoc */ protected function createModule($name) { LoggerRegistry::debug('AbstractConfigurableEngine::createModule({name})', array('name' => TypeUtilities::describe($name))); $module = parent::createModule($name); if ($module instanceof ConfigurableInterface) { $moduleConfigKey = sprintf('%s.%s', $this->getRootModuleOverrideConfigKey(), NameUtilities::convertToDashedLower($name)); $moduleConfig = $this->config($moduleConfigKey, array()); $module->configure($moduleConfig); } return $module; }
/** * @inheritdoc * * This implementation allows resources to be rendered by calling a method named for the resource type. For example * "$view->resources()->css()" renders the resources of type 'css'. The method name will be converted to * dashed-lower form, so a call like "$view->resources()->someType()" will refer to the type "some-type". */ public function __call($name, $arguments) { return $this->render(NameUtilities::convertToDashedLower($name)); }
/** * @inheritdoc */ public function getErrorRoute() { $module = NameUtilities::convertToDashedLower($this->config('engine.module-resolution.error-content')); return sprintf('%s:error', $module); }