diff --git a/composer.json b/composer.json index 425057f..03921b8 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "email": "info@studioespresso.co", "issues": "https://github.com/studioespresso/craft-exporter/issues?state=open", "source": "https://github.com/studioespresso/craft-exporter", - "docs": "https://studioespresso.github.io/craft-exporter/", + "docs": "https://github.com/studioespresso/craft-exporter", "rss": "https://github.com/studioespresso/craft-exporter/releases.atom" }, "require": { @@ -38,7 +38,7 @@ "handle": "exporter", "name": "Element Exporter", "developer": "Studio Espresso", - "documentationUrl": "https://studioespresso.github.io/craft-exporter/", + "documentationUrl": "https://github.com/studioespresso/craft-exporter", "class": "studioespresso\\exporter\\Exporter" }, "scripts": { diff --git a/src/Exporter.php b/src/Exporter.php index 2f91ac7..65f0835 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -20,11 +20,17 @@ use putyourlightson\sprig\Sprig; use studioespresso\exporter\elements\ExportElement; use studioespresso\exporter\events\RegisterExportableElementTypes; +use studioespresso\exporter\events\RegisterExportableFieldTypes; +use studioespresso\exporter\fields\DateTimeParser; +use studioespresso\exporter\fields\MultiOptionsFieldParser; +use studioespresso\exporter\fields\OptionsFieldParser; +use studioespresso\exporter\fields\PlainTextParser; +use studioespresso\exporter\fields\RelationFieldParser; use studioespresso\exporter\helpers\ElementTypeHelper; use studioespresso\exporter\helpers\FieldTypeHelper; -use studioespresso\exporter\helpers\PluginHelper; use studioespresso\exporter\models\ExportableCategoryModel; use studioespresso\exporter\models\ExportableEntryModel; +use studioespresso\exporter\models\ExportableFormieSubmissionModel; use studioespresso\exporter\models\Settings; use studioespresso\exporter\records\ExportRecord; use studioespresso\exporter\services\ElementService; @@ -46,7 +52,6 @@ * @property-read ExportQueryService $query * @property-read ElementTypeHelper $elements * @property-read FieldTypeHelper $fields - * @property-read PluginHelper $plugins * @property-read MailService $mail * @property-read ElementService $element **/ @@ -93,7 +98,6 @@ public static function config(): array 'components' => [ 'elements' => ['class' => ElementTypeHelper::class], 'fields' => ['class' => FieldTypeHelper::class], - 'plugins' => ['class', PluginHelper::class], 'query' => ['class' => ExportQueryService::class], 'mail' => ['class' => MailService::class], 'element' => ['class' => ElementService::class], @@ -232,14 +236,28 @@ private function registerUserPermissions() private function registerRedactor() { if (Craft::$app->getPlugins()->isPluginEnabled('redactor')) { - $this->plugins->registerRedactor(); + Event::on( + FieldTypeHelper::class, + FieldTypeHelper::EVENT_REGISTER_EXPORTABLE_FIELD_TYPES, + function(RegisterExportableFieldTypes $event) { + $parsers = $event->fieldTypes; + $parsers[PlainTextParser::class][] = \craft\redactor\Field::class; // @phpstan-ignore-line + $event->fieldTypes = $parsers; + }); } } private function registerCkEditor() { if (Craft::$app->getPlugins()->isPluginEnabled('ckeditor')) { - $this->plugins->registerCKEditor(); + Event::on( + FieldTypeHelper::class, + FieldTypeHelper::EVENT_REGISTER_EXPORTABLE_FIELD_TYPES, + function(RegisterExportableFieldTypes $event) { + $parsers = $event->fieldTypes; + $parsers[PlainTextParser::class][] = \craft\ckeditor\Field::class; // @phpstan-ignore-line + $event->fieldTypes = $parsers; + }); } } @@ -248,7 +266,50 @@ private function registerFormie() { // Register support for Formie if the plugin is installed and Enabled if (Craft::$app->getPlugins()->isPluginEnabled('formie')) { - $this->plugins->registerFormie(); + Event::on( + ElementTypeHelper::class, + ElementTypeHelper::EVENT_REGISTER_EXPORTABLE_ELEMENT_TYPES, + function(RegisterExportableElementTypes $event) { + $model = new ExportableFormieSubmissionModel(); + $event->elementTypes = array_merge($event->elementTypes, [ + /** @phpstan-ignore-next-line */ + \verbb\formie\elements\Submission::class => $model, + ]); + }); + + Event::on( + FieldTypeHelper::class, + FieldTypeHelper::EVENT_REGISTER_EXPORTABLE_FIELD_TYPES, + function(RegisterExportableFieldTypes $event) { + $parsers = $event->fieldTypes; + + $event->fieldTypes[PlainTextParser::class] = array_merge($parsers[PlainTextParser::class], [ + \verbb\formie\fields\formfields\Email::class, // @phpstan-ignore-line + \verbb\formie\fields\formfields\SingleLineText::class, // @phpstan-ignore-line + \verbb\formie\fields\formfields\MultiLineText::class, // @phpstan-ignore-line + \verbb\formie\fields\formfields\Phone::class, // @phpstan-ignore-line + \verbb\formie\fields\formfields\Agree::class, // @phpstan-ignore-line + \verbb\formie\fields\formfields\Number::class, // @phpstan-ignore-line + ]); + + $event->fieldTypes[DateTimeParser::class] = array_merge($parsers[DateTimeParser::class], [ + \verbb\formie\fields\formfields\Date::class, // @phpstan-ignore-line + ]); + + $event->fieldTypes[OptionsFieldParser::class] = array_merge($parsers[OptionsFieldParser::class], [ + \verbb\formie\fields\formfields\Radio::class, // @phpstan-ignore-line + \verbb\formie\fields\formfields\Dropdown::class, // @phpstan-ignore-line + ]); + + $event->fieldTypes[MultiOptionsFieldParser::class] = array_merge($parsers[MultiOptionsFieldParser::class], [ + \verbb\formie\fields\formfields\Checkboxes::class, // @phpstan-ignore-line + ]); + + $event->fieldTypes[RelationFieldParser::class] = array_merge($parsers[RelationFieldParser::class], [ + \verbb\formie\fields\formfields\Entries::class, // @phpstan-ignore-line + \verbb\formie\fields\formfields\Categories::class, // @phpstan-ignore-line + ]); + }); } } } diff --git a/src/helpers/PluginHelper.php b/src/helpers/PluginHelper.php deleted file mode 100644 index 4935d3c..0000000 --- a/src/helpers/PluginHelper.php +++ /dev/null @@ -1,89 +0,0 @@ -fieldTypes; - $parsers[PlainTextParser::class][] = \craft\redactor\Field::class; // @phpstan-ignore-line - $event->fieldTypes = $parsers; - }); - } - - - public function registerCKEditor() - { - Event::on( - FieldTypeHelper::class, - FieldTypeHelper::EVENT_REGISTER_EXPORTABLE_FIELD_TYPES, - function(RegisterExportableFieldTypes $event) { - $parsers = $event->fieldTypes; - $parsers[PlainTextParser::class][] = \craft\ckeditor\Field::class; // @phpstan-ignore-line - $event->fieldTypes = $parsers; - }); - } - - public function registerFormie() - { - Event::on( - ElementTypeHelper::class, - ElementTypeHelper::EVENT_REGISTER_EXPORTABLE_ELEMENT_TYPES, - function(RegisterExportableElementTypes $event) { - $model = new ExportableFormieSubmissionModel(); - $event->elementTypes = array_merge($event->elementTypes, [ - /** @phpstan-ignore-next-line */ - \verbb\formie\elements\Submission::class => $model, - ]); - }); - - Event::on( - FieldTypeHelper::class, - FieldTypeHelper::EVENT_REGISTER_EXPORTABLE_FIELD_TYPES, - function(RegisterExportableFieldTypes $event) { - $parsers = $event->fieldTypes; - - $event->fieldTypes[PlainTextParser::class] = array_merge($parsers[PlainTextParser::class], [ - \verbb\formie\fields\formfields\Email::class, // @phpstan-ignore-line - \verbb\formie\fields\formfields\SingleLineText::class, // @phpstan-ignore-line - \verbb\formie\fields\formfields\MultiLineText::class, // @phpstan-ignore-line - \verbb\formie\fields\formfields\Phone::class, // @phpstan-ignore-line - \verbb\formie\fields\formfields\Agree::class, // @phpstan-ignore-line - \verbb\formie\fields\formfields\Number::class, // @phpstan-ignore-line - ]); - - $event->fieldTypes[DateTimeParser::class] = array_merge($parsers[DateTimeParser::class], [ - \verbb\formie\fields\formfields\Date::class, // @phpstan-ignore-line - ]); - - $event->fieldTypes[OptionsFieldParser::class] = array_merge($parsers[OptionsFieldParser::class], [ - \verbb\formie\fields\formfields\Radio::class, // @phpstan-ignore-line - \verbb\formie\fields\formfields\Dropdown::class, // @phpstan-ignore-line - ]); - - $event->fieldTypes[MultiOptionsFieldParser::class] = array_merge($parsers[MultiOptionsFieldParser::class], [ - \verbb\formie\fields\formfields\Checkboxes::class, // @phpstan-ignore-line - ]); - - $event->fieldTypes[RelationFieldParser::class] = array_merge($parsers[RelationFieldParser::class], [ - \verbb\formie\fields\formfields\Entries::class, // @phpstan-ignore-line - \verbb\formie\fields\formfields\Categories::class, // @phpstan-ignore-line - ]); - }); - } -}