diff --git a/README.md b/README.md index af592fd..5b71249 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,33 @@ Allows more control over frontend page content type mappings. Each mapping is st To force download of a page (by setting the `Content-Disposition` header), give it a page type that begins with a '.'. The page will be downloaded with a filename = `$page-handle.$type`. For instance, a page with handle `form-data` and a page type of `.csv` will be downloaded as `form-data.csv`. -Depending on the Content Type you map to a page type, it may not be necessary to add this Content-Disposition header in order to cause the page to download. \ No newline at end of file +Depending on the Content Type you map to a page type, it may not be necessary to add this Content-Disposition header in order to cause the page to download. + +## Export Mode + +Prior to version 1.7 for each export mode that you wanted for a page you were required to create an identical page in Symphony with an separate export mode. +This was quite an overhead if you were trying to create a number of reports which required both html and csv output, more so if you also had to export in xml or json format for other consumption. +With version 1.7 you can handle all of this through the same page, instead of adding a page type `.csv` however add `export.csv` as your page type in addition to any other export formats required. + +Through the configuration section there is now an additional parameter to fill, that is the export variable. +This is configurable so you can use a url parameter which fits your website, by default on install / update this is set to `export`. +It is important to note what you set this value as you will need it within your templates. + +### Adjusting your templates to work with export modes + +Assuming that you use a master template matching `/` you can add the following code within your page template which supports export modes. + + + + + + + + + + + + +If you had previously changed the export variable, update the when clause to reflect the correct url parameter. +For each export mode create a where clause reflecting the data which you want to return for that mode. +If no export modes are matched, the default template will be applied using apply imports, if you're not using a master template, call the main template instead. diff --git a/extension.driver.php b/extension.driver.php index bc26871..e26258b 100644 --- a/extension.driver.php +++ b/extension.driver.php @@ -75,6 +75,9 @@ public function addCustomPreferenceFieldsets($context) // Data if (is_array($mappings)) { foreach ($mappings as $type => $content_type) { + //if type is export this is not a type but an export url param so skip to next element + if ($type == 'export') continue; + $values = array('mime-type'=>$content_type,'page-type'=>$type); $wrapper->appendChild($this->generateRow($values['page-type'], 'instance expanded', $values)); } @@ -85,6 +88,12 @@ public function addCustomPreferenceFieldsets($context) // Wrapper into fieldset $fieldset->appendChild($out_wrapper); + + // Add fieldset + $input = Widget::Input('settings[content-type-mappings][export]',Symphony::Configuration()->get('export', self::SETTINGS_GROUP)); + $label = Widget::Label(__('Export URL parameter'), $input); + $fieldset->appendChild($label); + // Adds the field set to the wrapper $context['wrapper']->appendChild($fieldset); } @@ -163,6 +172,8 @@ public function save(&$context) } } + Symphony::Configuration()->set('export', $context['settings'][self::SETTINGS_GROUP]['export'], self::SETTINGS_GROUP); + // Save the changes Symphony::Configuration()->write(); @@ -188,9 +199,19 @@ public function install() Symphony::Configuration()->set($type, $content_type, self::SETTINGS_GROUP); } + Symphony::Configuration()->set('export', 'export', self::SETTINGS_GROUP); + Symphony::Configuration()->write(); } + public function update($previousVersion = null) + { + if(version_compare($previousVersion, '1.7', '<')) { + Symphony::Configuration()->set('export', 'export', self::SETTINGS_GROUP); + Symphony::Configuration()->write(); + } + } + public function uninstall() { Symphony::Configuration()->remove(self::SETTINGS_GROUP); @@ -214,12 +235,20 @@ public function resolveType($type) public function setContentType(array $context=NULL) { $page_data = Frontend::Page()->pageData(); + $params = Frontend::Page()->Params(); if (!isset($page_data['type']) || !is_array($page_data['type']) || empty($page_data['type'])) { return; } foreach ($page_data['type'] as $type) { + $exportParam = $params['url-' . Symphony::Configuration()->get('export', self::SETTINGS_GROUP)]; + + //if starts with and has url-param export and export matches page data type + if (strrpos($type, 'export', -strlen($type)) !== FALSE && isset($exportParam) && $exportParam == substr($type, -strlen($exportParam)) ) { + $type = str_replace('export', '', $type); + } + $content_type = $this->resolveType($type); if (!is_null($content_type)) { diff --git a/extension.meta.xml b/extension.meta.xml index f869fef..0eddb85 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -22,6 +22,9 @@ + + - Add Export mode support multiple output types on a single page + - Code clean-up