Skip to content

Commit

Permalink
Use Eventy for import commands (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnPaes authored Jan 16, 2024
1 parent 524babb commit 8190872
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ php artisan rapidez:statamic:import:categories 5 8 9 category-url-key --site=def

By default the slug and title of the category are copied.

If you have a custom blueprint and would like to add more data from the category you can do so by hooking into the `rapidez-statamic:category-entry-data` event:
If you have a custom blueprint and would like to add more data from the category you can do so by hooking into the Eventy event: `rapidez-statamic:category-entry-data`

```php
Event::listen('rapidez-statamic:category-entry-data', fn($category) => [
Eventy::addFilter('rapidez.statamic.category.entry.data', fn($category) => [
'description' => $category->description,
]
);
Expand All @@ -142,10 +142,10 @@ php artisan rapidez:statamic:import:products --site=default

By default the slug and title of the product are copied.

If you have a custom blueprint and would like to add more data from the product you can do so by hooking into the `rapidez-statamic:product-entry-data` event:
If you have a custom blueprint and would like to add more data from the product you can do so by hooking into the Eventy event: `rapidez.statamic.product.entry.data`

```php
Event::listen('rapidez-statamic:product-entry-data', fn($product) => [
Eventy::addFilter('rapidez.statamic.product.entry.data', fn($product) => [
'description' => $product->description,
]
);
Expand All @@ -167,10 +167,10 @@ php artisan rapidez:statamic:import:brands --site=default

By default the slug and title of the brand are copied.

If you have a custom blueprint and would like to add more data from the brand you can do so by hooking into the `rapidez-statamic:brand-entry-data` event:
If you have a custom blueprint and would like to add more data from the brand you can do so by hooking into the Eventy event `rapidez.statamic.brand.entry.data`

```php
Event::listen('rapidez-statamic:brand-entry-data', fn($brand) => [
Eventy::addFilter('rapidez.statamic.brand.entry.data', fn($brand) => [
'description' => $brand->description,
]
);
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"doublethreedigital/runway": "^5.0",
"rapidez/blade-directives": "*",
"spatie/statamic-responsive-images": "^4.0",
"statamic/cms": "^4.0"
"statamic/cms": "^4.0",
"tormjens/eventy": "^0.8"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/ImportBrands.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Statamic\Facades\Site;
use Illuminate\Console\Command;
use Rapidez\Statamic\Models\Brand;
use TorMorten\Eventy\Facades\Eventy;
use Rapidez\Statamic\Actions\StatamicEntryAction;
use Illuminate\Support\Facades\Event;

class ImportBrands extends Command
{
Expand Down Expand Up @@ -40,7 +40,7 @@ public function handle(StatamicEntryAction $statamicEntryAction): int
array_merge([
'locale' => $site->handle(),
'site' => $site->handle(),
], ...Event::dispatch('rapidez-statamic:brand-entry-data', ['brand' => $brand]))
], ...[Eventy::filter('rapidez.statamic.brand.entry.data', $brand)])
);
}
$bar->advance();
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/ImportCategories.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Statamic\Facades\Site;
use Illuminate\Console\Command;
use Rapidez\Core\Facades\Rapidez;
use Illuminate\Support\Facades\Event;
use TorMorten\Eventy\Facades\Eventy;
use Rapidez\Statamic\Actions\StatamicEntryAction;

class ImportCategories extends Command
Expand Down Expand Up @@ -68,7 +68,7 @@ public function handle(): int
array_merge([
'locale' => $site->handle(),
'site' => $site->handle(),
], ...Event::dispatch('rapidez-statamic:category-entry-data', ['category' => $category]))
], ...[Eventy::filter('rapidez.statamic.category.entry.data', $category)])
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Commands/ImportProducts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Rapidez\Statamic\Commands;

use Statamic\Facades\Site;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Event;
use Rapidez\Core\Facades\Rapidez;
use TorMorten\Eventy\Facades\Eventy;
use Rapidez\Statamic\Actions\StatamicEntryAction;
use Statamic\Facades\Site;

class ImportProducts extends Command
{
Expand Down Expand Up @@ -53,7 +53,7 @@ public function handle()
array_merge([
'locale' => $site->handle(),
'site' => $site->handle(),
], ...Event::dispatch('rapidez-statamic:product-entry-data', ['product' => $product]))
], ...[Eventy::filter('rapidez.statamic.product.entry.data', $product)])
);
}

Expand Down
7 changes: 4 additions & 3 deletions src/RapidezStatamicServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Rapidez\Statamic\Http\Controllers\ImportsController;
use Rapidez\Statamic\Http\Controllers\StatamicRewriteController;
use Rapidez\Statamic\Http\ViewComposers\StatamicGlobalDataComposer;
use TorMorten\Eventy\Facades\Eventy;

class RapidezStatamicServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -94,17 +95,17 @@ public function bootListeners() : self
Cache::forget('statamic-globals-' . Site::current()->handle());
});

Event::listen('rapidez-statamic:category-entry-data', fn($category) => [
Eventy::addFilter('rapidez.statamic.category.entry.data', fn($category) => [
'title' => $category->name,
'slug' => trim($category->url_key),
]);

Event::listen('rapidez-statamic:product-entry-data', fn($product) => [
Eventy::addFilter('rapidez.statamic.product.entry.data', fn($product) => [
'title' => $product->name,
'slug' => trim($product->url_key),
]);

Event::listen('rapidez-statamic:brand-entry-data', fn($brand) => [
Eventy::addFilter('rapidez.statamic.brand.entry.data', fn($brand) => [
'title' => $brand->value_store,
'slug' => trim($brand->value_admin),
]);
Expand Down

0 comments on commit 8190872

Please sign in to comment.