Skip to content

Commit

Permalink
Merge branch 'release/4.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Apr 23, 2024
2 parents 5a7510a + 2be3238 commit df32742
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 10 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 4.1.0 - 2024-04-23
### Added
- Added an option to specify the filename as which the export will be generated ([#6](https://github.com/studioespresso/craft-exporter/issues/6))
- Added support for Formie's Name field ([#13](https://github.com/studioespresso/craft-exporter/issues/13))
- Exports can now be created for empty sections ([#12](https://github.com/studioespresso/craft-exporter/issues/12))

### Fixed
- Fixed an error that would occur when editing exports for element that had new fields ([#11](https://github.com/studioespresso/craft-exporter/issues/11))


## 4.0.0 - 2024-03-12
- Inital release 🚀

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Export all things",
"type": "craft-plugin",
"license": "proprietary",
"version": "4.0.0",
"version": "4.1.0",
"authors": [
{
"name": "Studio Espresso",
Expand Down
5 changes: 5 additions & 0 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use studioespresso\exporter\events\RegisterExportableElementTypes;
use studioespresso\exporter\events\RegisterExportableFieldTypes;
use studioespresso\exporter\fields\DateTimeParser;
use studioespresso\exporter\fields\FormieNameParser;
use studioespresso\exporter\fields\MultiOptionsFieldParser;
use studioespresso\exporter\fields\OptionsFieldParser;
use studioespresso\exporter\fields\PlainTextParser;
Expand Down Expand Up @@ -309,6 +310,10 @@ function(RegisterExportableFieldTypes $event) {
\verbb\formie\fields\formfields\Entries::class, // @phpstan-ignore-line
\verbb\formie\fields\formfields\Categories::class, // @phpstan-ignore-line
]);

$event->fieldTypes = array_merge($event->fieldTypes, [FormieNameParser::class => [
\verbb\formie\fields\formfields\Name::class, // @phpstan-ignore-line
]]);
});
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/elements/ExportElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,17 @@ public static function isLocalized(): bool
public function canView(User $user): bool
{
$element = $this->getElementQuery()->one();
if ($element->canView(Craft::$app->getUser()->getIdentity())) {
if ($element && $element->canView(Craft::$app->getUser()->getIdentity())) {
return true;
}

if (!$element) {
$element = $this->mockElement();
if ($element && $element->canView(Craft::$app->getUser()->getIdentity())) {
return true;
}
}

return false;
}

Expand Down Expand Up @@ -270,6 +278,11 @@ public function getElementQuery(): ElementQuery
return Exporter::$plugin->query->buildQuery($this);
}

public function mockElement(): Element|null
{
return Exporter::$plugin->query->mockElement($this);
}

public function getExportableAttributes(): array
{
$helper = new ElementTypeHelper();
Expand Down
2 changes: 1 addition & 1 deletion src/fields/BaseFieldParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

abstract class BaseFieldParser extends Component
{
abstract protected function getValue(Element $element, array $handle);
abstract protected function getValue(Element $element, array $field);

abstract protected function getOptionType(): string|bool;

Expand Down
52 changes: 52 additions & 0 deletions src/fields/FormieNameParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace studioespresso\exporter\fields;

class FormieNameParser extends BaseFieldParser
{
/**
* @param $element
* @param \verbb\formie\fields\formfields\Name $field
* @return mixed
* @throws \craft\errors\InvalidFieldException
*/
public function getValue($element, $field)
{
$value = $element->getFieldValue($field['handle']);
/** @phpstan-ignore-next-line */
if (is_object($value) && get_class($value) === verbb\formie\models\Name::class) {
$string = '';
if ($value->prefix) {
$string = $string . $value->prefix . " ";
}
if ($value->firstName) {
$string = $string . $value->firstName . " ";
}
if ($value->lastName) {
$string = $string . $value->lastName;
}
return $string;
}
return $value;
}

public function getOptions(): array
{
return [];
}

public function getOptionType(): string|bool
{
return false;
}

protected function getOptionLabel(): string|bool
{
return false;
}

protected function getOptionDescription(): string|bool
{
return false;
}
}
1 change: 0 additions & 1 deletion src/helpers/FieldTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public function getAvailableFieldTypes(): array
$event->fieldTypes,
self::SUPPORTED_FIELD_TYPES,
);

return self::$_supportedFieldTypes;
}

Expand Down
18 changes: 18 additions & 0 deletions src/services/ExportQueryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ public function buildQuery(ExportElement $export): ElementQuery
return $query;
}

public function mockElement(ExportElement $export): Element|null
{
try {
$elementType = $export->elementType;
$settings = $export->getSettings();
$elementOptions = Exporter::getInstance()->elements->getElementTypeSettings($elementType);

$element = Craft::createObject($elementType);
if (isset($elementOptions['group'])) {
$group = $elementOptions['group']['parameter'];
$element->$group = $settings['group'];
}
return $element;
} catch (\Throwable $e) {
return null;
}
}

public function getFields(ExportElement $export, Element $element): array
{
$data = [];
Expand Down
3 changes: 2 additions & 1 deletion src/services/MailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public function send(ExportElement $export, $path): bool

$message = new Message();

$fileName = "Export.{$exportSettings['fileType']}";
$name = $exportSettings['fileName'] ?? "Export";
$fileName = "{$name}.{$exportSettings['fileType']}";
$message->attach($path, ['fileName' => $fileName, 'contentType' => "application/{$exportSettings['fileType']}"]);
$message->setSubject("Your export");
$message->setTo($exportSettings['email']);
Expand Down
4 changes: 2 additions & 2 deletions src/templates/sprig/element/step_2.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% set attributes = export.getAttributes() %}
{% set fields = export.getFields() ?? [] %}

{% set element = export.getElementQuery().one() %}
{% set element = export.mockElement() %}

{% if not element %}
{{ "No elements can be found for your selection. Please create an element first or check your settings in step 1."|t('exporter') }}
Expand Down Expand Up @@ -69,7 +69,7 @@
{% else %}
{# We have a parser, so the field is supported #}
{% set fieldSettings = false %}
{% if fields|length and attribute(fields, field.handle) %}
{% if fields|length and attribute(fields, field.handle) is defined %}
{% set fieldSettings = attribute(fields, field.handle) %}
{% endif %}
<div id="{{ field.handle }}-input-field" class="field checkboxfield"
Expand Down
13 changes: 13 additions & 0 deletions src/templates/sprig/run.twig
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@
</div>
<hr>
<h2>{{ "Export delivery"|t('exporter') }}</h2>

{{ forms.textField({
first: true,
label: "Filename"|t('exporter'),
instructions: "The filename that should be used for the export."|t('exporter'),
id: 'email',
name: 'settings[fileName]',
value: settings.fileName ?? export.name|lower|replace(' ', '-'),
errors: (errors is defined and errors.email ) ? errors.email : null,
required: true
}) }}


{{ hiddenInput('settings[deliveryType]', 'email') }}
{{ forms.textField({
first: true,
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,9 @@ tabbable@^6.2.0:
integrity sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==

vite@^4.5.0:
version "4.5.2"
resolved "https://registry.yarnpkg.com/vite/-/vite-4.5.2.tgz#d6ea8610e099851dad8c7371599969e0f8b97e82"
integrity sha512-tBCZBNSBbHQkaGyhGCDUGqeo2ph8Fstyp6FMSvTtsXeZSPpSMGlviAOav2hxVTqFcx8Hj/twtWKsMJXNY0xI8w==
version "4.5.3"
resolved "https://registry.yarnpkg.com/vite/-/vite-4.5.3.tgz#d88a4529ea58bae97294c7e2e6f0eab39a50fb1a"
integrity sha512-kQL23kMeX92v3ph7IauVkXkikdDRsYMGTVl5KY2E9OY4ONLvkHf04MDTbnfo6NKxZiDLWzVpP5oTa8hQD8U3dg==
dependencies:
esbuild "^0.18.10"
postcss "^8.4.27"
Expand Down

0 comments on commit df32742

Please sign in to comment.