Skip to content

Commit

Permalink
refactor plugin finalization
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinSecondred committed Dec 20, 2023
1 parent 02f6ea1 commit b9e5dae
Show file tree
Hide file tree
Showing 58 changed files with 1,112 additions and 731 deletions.
28 changes: 0 additions & 28 deletions .editorconfig.json

This file was deleted.

16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Craft Seeder Changelog

## 4.0.0-R4 - 2023-06-29

## 4.0.0-RC1 - 2023-06-29

Expand Down
147 changes: 60 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# Seeder plugin for Craft CMS 3.x

![Seeder](/resources/banner.png?raw=true)
# Seeder plugin for Craft CMS

## Usage

Seeder allows you to quickly create dummy entries through the command line. And you can just as easily remove the dummy data when you're done building the site.
With the plugin installed, running `./craft help seeder/generate` will show you which commands are available

Since the plugin is only usefull during the development and not on a live site, charging money for it would be stupid (you could just free trial it every time). Instead you can download it for free and if you want to support future development, you can support it on [beerpay.io](https://beerpay.io/studioespresso/craft3-seeder). Thanks!

[![Beerpay](https://beerpay.io/studioespresso/craft3-seeder/badge.svg)](https://beerpay.io/studioespresso/craft3-seeder)
With the plugin installed, running `php craft element-seeder/generate/entries` create entries

## Installation

Expand All @@ -21,98 +15,77 @@ To install the plugin, follow these instructions.

2. Then tell Composer to load the plugin:

composer require studioespresso/craft-seeder
composer require anubarak/craft-seeder

3. In the Control Panel, go to Settings → Plugins and click the “Install” button for "Seeder".

#### Entries (Section ID/handle, count)
### Entries (Section ID/handle, count)

Use the command below, followed by the ``--section`` option and the ``--number`` of entries you want to create (defaults to 20 if ommited). This command works with both section ID and handle.

```Shell
./craft seeder/generate/entries --section=news --count=15
```

#### Categories (Category group ID/handle, count)
```Shell
./craft seeder/generate/categories --group=labels --count=10
```

#### Users (Usergroup ID/handle, count)
```Shell
./craft seeder/generate/users --group=editors --count=5
php craft element-seeder/generate/entries --section=news --count=15
```

## Clean up
Once you're done building out the site, the plugin gives you an easy way to remove the dummy data (entries, assets, categories and users). This can be done through the CP (click the Seeder section the sidebar) or through the command line with the following command:

```Shell
./craft seeder/clean-up/all
php craft element-seeder/clean-up
```

## Configuration options
### ``eachMatrixBlock`` - Seed all blocktypes in a matrix field
For a matrix, the plugin will get a random set of block types within the minimum & maximum amounts of blocks the field allows.

With this setting set to `true`, we'll generate a each blocktype once in a random order. This is a good way to test pagebuilder/contentbuilder like fields

### `useLocalAssets` - Use assets already in your site to seed asset fields
````php
'useLocalAssets' => [
'volumeId' => 1,
'path' => 'test/'
]
````

Add the array above to ``config/seeder.php`` to seed using assets from volume `1` and folder `test/`.

## Troubleshooting
The most common problem with the plugins is getting the following error:
````Shell
Unknown command: seeder/generate/entries
````
If you have the plugin installed in the CP and are seeing this message, craft can not connect to your database through the command line. Your site probably works correctly but CLI commands won't.

If you're running MAMP/XAMP, you should use `127.0.0.1` as hostname instead of `localhost`.


## Roadmap

#### Core elements
- [x] Entries
- [x] Categories
- [x] Users
- [x] Entry fields
- [ ] User fields
- [ ] Category fields
- [ ] Asset fields


#### Core fields
- [x] Title
- [x] Plain text
- [x] Email
- [x] Url
- [x] Color
- [x] Date
- [ ] Entries
- [x] Categories
- [x] Dropdown
- [x] Checkboxes
- [x] Radio buttons
- [x] Multi select
- [x] Assets
- [x] Matrix
- [x] Lightswitch
- [x] Table
- [x] Tags
- [x] Users

#### Plugin elements
- [ ] Commerce products & variants

#### Plugin fields
- [x] [Redactor](https://github.com/craftcms/redactor)
- [x] [CKEditor](https://github.com/craftcms/ckeditor)
- [x] [Super Table](https://github.com/verbb/super-table)
- [x] [Position field](https://github.com/Rias500/craft-position-fieldtype)

you can include custom configurations for each layout

```php
<?php

use anubarak\seeder\models\EntryConfig;
use anubarak\seeder\models\FieldCallback;
use anubarak\seeder\models\Settings;
use craft\base\ElementInterface;
use craft\base\FieldInterface;

$config = (new Settings())
->fieldsConfig([
new EntryConfig(
'news',
null,
[
(new FieldCallback('date'))
->setCallable(
static function(
\Faker\Generator $faker,
FieldInterface $field,
ElementInterface $element
) {
return new DateTime();
}
),
(new FieldCallback('date2'))
->setCallable(
static function(
\Faker\Generator $faker,
FieldInterface $field,
ElementInterface $element
) {
$date = (clone $element->getFieldValue('date'));
$date->modify('+1 day');

return $date;
}
),
(new FieldCallback('headline'))
->setFakerMethod('text'),
]
)
]);

// required for Craft 4 since they'll do an array_merge
return $config->toArray([], ['fieldsConfig'], false);
```
Would create a custom callback while seeding fields for entries in the section `news` for fields
`date`, `date2` and `text`.
Text would call the `Faker` function `$faker->text` and `date` and `date2` would call the callback function in order to
populate fields with custom conditions
10 changes: 0 additions & 10 deletions codeception.yml

This file was deleted.

49 changes: 25 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
{
"name": "anubarak/craft-seeder",
"description": "Easy entries seeder for Craft CMS",
"type": "craft-plugin",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"seeder"
],
"license": "MIT",
"require": {
"craftcms/cms": "^4.0.0",
"fakerphp/faker": "^1.23.0"
},
"autoload": {
"psr-4": {
"anubarak\\seeder\\": "src/"
}
},
"extra": {
"name": "Element Seeder",
"handle": "element-seeder",
"class": "anubarak\\seeder\\Seeder"
"name": "anubarak/craft-seeder",
"description": "Easy entries seeder for Craft CMS",
"version": "4.0.0-R4",
"type": "craft-plugin",
"keywords": [
"craft",
"cms",
"craftcms",
"craft-plugin",
"seeder"
],
"license": "MIT",
"require": {
"craftcms/cms": "^4.0.0",
"fakerphp/faker": "^1.23.0"
},
"autoload": {
"psr-4": {
"anubarak\\seeder\\": "src/"
}
},
"extra": {
"name": "Element Seeder",
"handle": "element-seeder",
"class": "anubarak\\seeder\\Seeder"
}
}
Binary file removed resources/banner.png
Binary file not shown.
Loading

0 comments on commit b9e5dae

Please sign in to comment.