Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.

<xsl:template match="/">
<xsl:choose>
<xsl:when test='/data/params/url-export = "csv"'>
<xsl:apply-templates select='.' mode='csv'/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-imports/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

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.
29 changes: 29 additions & 0 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
</author>
</authors>
<releases>
<release version="1.7" date="2015-03-22" min="2.4">
- Add Export mode support multiple output types on a single page
</release>
<release version="1.6.1" date="2014-06-17" min="2.4">
- Code clean-up
</release>
Expand Down