protected function renderEmbeddedEntityTypeSelectorMap() { $embed_type_selector_map = new ActivityMap(); $selector_td = $this->getDefaultTranslationDomain(); foreach ($this->attribute->getEmbeddedEntityTypeMap()->getKeys() as $embedded_type_prefix) { $embed_type_selector_map->setItem($embedded_type_prefix, new Activity(['name' => $embedded_type_prefix, 'label' => $this->_($embedded_type_prefix, $selector_td), 'url' => Url::createUri('#' . $embedded_type_prefix), 'settings' => new Settings()])); } $view_scope = $this->getOption('view_scope'); $default_settings = ['view_scope' => $view_scope]; $renderer_config = $this->view_config_service->getRendererConfig($view_scope, $this->output_format, $embed_type_selector_map, $default_settings); return $this->renderer_service->renderSubject($embed_type_selector_map, $this->output_format, $renderer_config); }
/** * Generates a URL for the given route name and parameters. The options * MAY be used to provide hints for the URL generation. This includes * information about different parts of a URL, e.g. the scheme or port to * use or whether absolute or relative URLs should be generated. * * The usual URL has the following simplified structure: * * scheme://userinfo@host:port/path?query#fragment * * @see http://en.wikipedia.org/wiki/URI_scheme * @see http://tools.ietf.org/html/rfc3986 * @see http://tools.ietf.org/html/std66 * * Suggested option keys and their default values are: * * - 'relative': false * whether to generate absolute or relative URLs * - 'separator': '&' * query parameters separator, e.g. ';' – see ini_get('arg_separator.output') * - 'scheme': null * scheme name, e.g. 'ftp' – true/false to include/exclude; * use an empty string ('') to generate protocol relative URLs ('//host.tld') * - 'userinfo': null * user information string, e.g. 'user:pwd' – true/false to include/exclude * - 'host': null * host string, e.g 'www.example.org' – true/false to include/exclude * - 'port': null * port string, e.g. '8080' – true/false to include/exclude * - 'authority': null * authority string, e.g. 'user:info@host:port' – true/false to include/exclude * - 'path': null * path string, e.g. 'some/hierarchical/path' – true/false to include/exclude * - 'fragment': null * fragment identifier string, e.g. 'foo' – true/false to include/exclude * - 'use_trans_sid': false * whether or not to include a session id (SID) – see ini_get('session.use_trans_sid') * * Other options may be used as well. Adapters for frameworks SHOULD * use and convert those options to their respective implementations of * handling the generation of URLs. * * While this interface is for primarily for generating URLs, it SHOULD be * possible to create any URIs depending on the implementations and the * provided options. * * Please note, that ATM the 'path' option is not supported. The 'prefix' option * instead allows to set the path part that is fixed for your docroot. * * @param mixed $name route-name, lookup-key, or object to generate an URL for * @param array $parameters pairs of placeholder names and values * @param array $options array of options to influence URL generation * * @return string URL relative or absolute URL */ public function generateUrl($name, array $parameters = [], array $options = []) { $url = ''; if ($name instanceof ActivityInterface) { $url = $name->getUrl(); } elseif ($name instanceof Url) { $url = $name; } else { $url = Url::createRoute($name, $parameters); } if ($url->getType() === Url::TYPE_ROUTE) { $route_params = $parameters; $route_params = array_replace_recursive($url->getParameters(), $parameters); $link = $this->routing->gen($url->getValue(), $route_params, $options); } elseif ($url->getType() === Url::TYPE_URI_TEMPLATE) { $uri_template = new UriTemplate($url->getValue()); $template_params = array_replace_recursive($url->getParameters(), $parameters); $link = $uri_template->expand($template_params); } else { $link = $url->__toString(); // TODO apply params as query params? } return $link; }
protected function setSortActivities(AgaviRequestDataHolder $request_data) { $activity_service = $this->getServiceLocator()->getActivityService(); // get sort activities defined for current view config scope $sort_activities_container = $activity_service->getContainer($this->getViewScope() . '.sort_activities'); $sort_activities = $sort_activities_container->getActivityMap(); $current_sort_value = $request_data->getParameter('sort'); $output_format = $this->getOutputFormat(); $view_scope = $this->getViewScope(); // we generate an id instead of default to a random one, as we need to render the sort // activities twice in the html and need unique ids there (by replacing the necessary html snippet) $sort_trigger_id = 'sortTrigger' . rand(1, 10000); $default_data = ['view_scope' => $view_scope]; // get sort_activities renderer config $view_config_service = $this->getServiceLocator()->getViewConfigService(); $renderer_config = $view_config_service->getRendererConfig($view_scope, $output_format, 'sort_activities', $default_data); /** which activity is the current default one? * * fallbacks order: * - 'sort' url parameter * - eventual renderer config setting * - eventual custom activity name (from setting or validation) * - first activity of the map */ $default_activity_map = $sort_activities->filterByUrlParameter('sort', $current_sort_value); $default_activity_name = ''; if (!$default_activity_map->isEmpty()) { $default_activity_name = $default_activity_map->getItem($default_activity_map->getKeys()[0])->getName(); } else { // when a default_activity_name setting is present we ignore the custom 'sort' url parameter if ($renderer_config->has('default_activity_name')) { $default_activity_name = $renderer_config->get('default_activity_name'); } elseif (empty($current_sort_value)) { if (!$sort_activities->isEmpty()) { $default_activity_name = $sort_activities->getItem($sort_activities->getKeys()[0])->getName(); } } else { // set the custom parameter value (when validation allows it) $default_activity_name = $current_sort_value; } } // sort_activities renderer settings $render_settings = ['trigger_id' => $sort_trigger_id]; if (!$sort_activities->isEmpty() && !$sort_activities->hasKey($default_activity_name)) { // force a dropdown to display the custom value but only allow the choice of configured activities $render_settings['as_dropdown'] = 'true'; $custom_activity = new Activity(['name' => $default_activity_name, 'label' => $default_activity_name . '.label', 'url' => ActivityUrl::createUri('null'), 'settings' => new Settings()]); $sort_activities->setItem($default_activity_name, $custom_activity); } if (!empty($default_activity_name)) { $render_settings['default_activity_name'] = $default_activity_name; } $renderer_service = $this->getServiceLocator()->getRendererService(); $rendered_sort_activities = $renderer_service->renderSubject($sort_activities, $output_format, $renderer_config, [], new Settings($render_settings)); $this->setAttribute('sort_trigger_id', $sort_trigger_id); $this->setAttribute('rendered_sort_activities', $rendered_sort_activities); return $rendered_sort_activities; }
protected function parseActivity(AgaviXmlConfigDomElement $activity_node, AgaviXmlConfigDomDocument $document) { // description for this activity $description_node = $activity_node->getChild('description'); $description = $description_node ? $description_node->getValue() : ''; // short label for this activity $label_node = $activity_node->getChild('label'); $label = $label_node ? $label_node->getValue() : ''; // verb (request method equivalent) for this activity $verb_node = $activity_node->getChild('verb'); $verb = $verb_node ? $verb_node->getValue() : AgaviConfig::get('activities.default_verb', self::DEFAULT_VERB); // link relations for the target url of this activity $rels = []; $rels_node = $activity_node->getChild('rels'); if (!empty($rels_node) && $rels_node->hasChildren('rel')) { foreach ($rels_node->get('rel') as $rel_node) { $rels[] = $rel_node->getValue(); } } // mime types the target url supports as input $accepting = []; $acception_node = $activity_node->getChild('accepting'); if (!empty($accepting_node)) { foreach ($accepting_node->get('type') as $type_node) { $accepting[] = $type_node->getValue(); } } // mime types the target url supports as output $sending = []; $sending_node = $activity_node->getChild('sending'); if (!empty($sending_node)) { foreach ($sending_node->get('type') as $type_node) { $sending[] = $type_node->getValue(); } } // parse all settings from given settings node $settings_node = $activity_node->getChild('settings'); $settings = $settings_node ? $this->parseSettings($settings_node) : []; if (!array_key_exists('form_id', $settings)) { $settings['form_id'] = 'randomId' . rand(); } // URL, URI_TEMPLATE or ROUTE_NAME for target url of this activity $url = ['type' => self::DEFAULT_URL_TYPE, 'value' => '']; $url_node = $activity_node->getChild('url'); if (!empty($url_node)) { $url_value = trim($url_node->getValue()); $url_type = $url_node->getAttribute('type'); if (!empty($url_type)) { if (!in_array($url_type, $this->allowed_url_types)) { throw new ConfigError(sprintf('Configuration file "%s" must specify a valid "type" attribute' . 'on "url" elements. Valid are: ', $document->documentURI, implode(', ', $this->allowed_url_types))); } $url['type'] = $url_type; } if (empty($url_value)) { throw new ConfigError(sprintf('Configuration file "%s" must specify a valid value for "url" elements.', $document->documentURI)); } if ($url_value === 'null') { $url_value = null; // useful for $ro->gen(null, …) } else { $url_value = AgaviToolkit::literalize(AgaviToolkit::expandDirectives($url_value)); } $url['value'] = $url_value; } $url['parameters'] = $this->parseUrlParameters($activity_node); $url = new Url($url); return ['name' => trim($activity_node->getAttribute('name')), 'type' => $activity_node->getAttribute('type', 'general'), 'description' => $description, 'label' => $label, 'verb' => $verb, 'rels' => $rels, 'accepting' => $accepting, 'sending' => $sending, 'settings' => $settings, 'url' => $url->toArray()]; }