Skip to content

Commit

Permalink
Freeform submission support
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Dec 1, 2023
1 parent 5549578 commit 980112d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 36 deletions.
56 changes: 36 additions & 20 deletions src/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use craft\events\RegisterUserPermissionsEvent;
use craft\services\Elements;
use craft\services\Gc;
use craft\services\Sections;
use craft\services\UserPermissions;
use craft\web\twig\variables\CraftVariable;
use craft\web\UrlManager;
Expand All @@ -26,23 +25,21 @@
use studioespresso\exporter\helpers\ElementTypeHelper;
use studioespresso\exporter\helpers\FieldTypeHelper;
use studioespresso\exporter\models\ExportableCategoryModel;
use studioespresso\exporter\models\ExportableElementTypeModel;
use studioespresso\exporter\models\ExportableEntryModel;
use studioespresso\exporter\models\ExportableFormieSubmissionModel;
use studioespresso\exporter\models\ExportableFreeformSubmissionModel;
use studioespresso\exporter\models\Settings;
use studioespresso\exporter\records\ExportRecord;
use studioespresso\exporter\services\ExportQueryService;
use studioespresso\exporter\services\MailService;
use studioespresso\exporter\variables\CraftVariableBehavior;
use studioespresso\exporter\variables\ExporterVariable;
use verbb\formie\elements\Submission;
use verbb\formie\fields\formfields\Agree;
use verbb\formie\fields\formfields\Email;
use verbb\formie\fields\formfields\MultiLineText;
use verbb\formie\fields\formfields\Number;
use verbb\formie\fields\formfields\Phone;
use verbb\formie\fields\formfields\SingleLineText;
use verbb\formie\Formie;
use verbb\formie\integrations\feedme\fields\Name;
use yii\base\Event;
use yii\console\Application as ConsoleApplication;
Expand Down Expand Up @@ -91,7 +88,9 @@ public function init(): void
$this->registerUserPermissions();
$this->registerSupportedElementTypes();
$this->registerFieldParsers();
// Register plugin support
$this->registerFormie();
$this->registerFreeform();
});
}

Expand Down Expand Up @@ -205,22 +204,6 @@ function (RegisterExportableFieldTypes $event) {
});
}

private function registerFormie()
{
// Register support for Formie if the plugin is installed and Enabled
if (Craft::$app->getPlugins()->isPluginEnabled('formie')) {
Event::on(
ElementTypeHelper::class,
ElementTypeHelper::EVENT_REGISTER_EXPORTABLE_ELEMENT_TYPES,
function (RegisterExportableElementTypes $event) {
$model = new ExportableFormieSubmissionModel();
$event->elementTypes = array_merge($event->elementTypes, [
Submission::class => $model
]);
});
}
}

private function attachEventHandlers(): void
{
Event::on(
Expand Down Expand Up @@ -276,4 +259,37 @@ private function registerUserPermissions()
];
});
}

private function registerFormie()
{
// Register support for Formie if the plugin is installed and Enabled
if (Craft::$app->getPlugins()->isPluginEnabled('formie')) {
Event::on(
ElementTypeHelper::class,
ElementTypeHelper::EVENT_REGISTER_EXPORTABLE_ELEMENT_TYPES,
function (RegisterExportableElementTypes $event) {
$model = new ExportableFormieSubmissionModel();
$event->elementTypes = array_merge($event->elementTypes, [
\verbb\formie\elements\Submission::class => $model
]);
});
}
}

private function registerFreeform()
{
// Register support for Formie if the plugin is installed and Enabled
if (Craft::$app->getPlugins()->isPluginEnabled('freeform')) {
Event::on(
ElementTypeHelper::class,
ElementTypeHelper::EVENT_REGISTER_EXPORTABLE_ELEMENT_TYPES,
function (RegisterExportableElementTypes $event) {
$model = new ExportableFreeformSubmissionModel();
$event->elementTypes = array_merge($event->elementTypes, [
\Solspace\Freeform\Elements\Submission::class => $model
]);
});
}
}

}
5 changes: 0 additions & 5 deletions src/models/ExportableCategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

namespace studioespresso\exporter\models;

use craft\base\Element;
use craft\base\ElementInterface;
use craft\base\Model;
use craft\elements\Category;
use craft\elements\Entry;
use craft\services\Sections;

class ExportableCategoryModel extends ExportableElementTypeModel
{
Expand Down
2 changes: 0 additions & 2 deletions src/models/ExportableElementTypeModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace studioespresso\exporter\models;

use craft\base\Element;
use craft\base\ElementInterface;
use craft\base\Model;

abstract class ExportableElementTypeModel extends Model
Expand Down
3 changes: 0 additions & 3 deletions src/models/ExportableEntryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace studioespresso\exporter\models;

use craft\base\Element;
use craft\base\ElementInterface;
use craft\base\Model;
use craft\elements\Entry;
use craft\services\Sections;

Expand Down
6 changes: 0 additions & 6 deletions src/models/ExportableFormieSubmissionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@

namespace studioespresso\exporter\models;

use craft\base\Element;
use craft\base\ElementInterface;
use craft\base\Model;
use craft\elements\Category;
use craft\elements\Entry;
use craft\services\Sections;
use verbb\formie\elements\Submission;
use verbb\formie\Formie;

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

namespace studioespresso\exporter\models;

use Solspace\Freeform\Elements\Submission;
use Solspace\Freeform\Freeform;
use verbb\formie\Formie;

class ExportableFreeformSubmissionModel extends ExportableElementTypeModel
{
public $elementType = Submission::class;

public string $elementLabel = "Freeform Submissions";

public function getGroup(): array
{
return [
"label" => "Form",
"parameter" => "formId",
"items" => Freeform::getInstance()->forms->getAllForms(), // @phpstan-ignore-line
"nameProperty" => "name",
];
}

public function getSubGroup(): bool|array
{
return false;
}

}
1 change: 1 addition & 0 deletions src/templates/sprig/element/step_1.twig
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
{% set subGroup = elementOptions.getSubGroup() %}
{% if elementOptions.group is defined %}
{% set groupOptions = elementOptions.getGroup() %}
{{ d(groupOptions) }}
<div class="flex-fields">
<div class="field width-50" id="elementType-entry-subfields">
<div class="heading">
Expand Down

0 comments on commit 980112d

Please sign in to comment.