-
Notifications
You must be signed in to change notification settings - Fork 9
/
AboutSeeder.php
94 lines (82 loc) · 2.4 KB
/
AboutSeeder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
use Illuminate\Database\Seeder;
use Pixney\WysiwygBlockExtension\Block\BlockModel;
use Anomaly\PagesModule\Page\Contract\PageRepositoryInterface;
use Anomaly\PagesModule\Type\Contract\TypeRepositoryInterface;
use Anomaly\BlocksModule\Block\Contract\BlockRepositoryInterface;
use Anomaly\Streams\Platform\Model\Pages\PagesDefaultPagesEntryModel;
class AboutSeeder extends Seeder
{
/**
* The page repository.
*
* @var PageRepositoryInterface
*/
protected $pages;
/**
* The types repository.
*
* @var TypeRepositoryInterface
*/
protected $types;
/**
* The types repository.
*
* @var BlockRepositoryInterface
*/
protected $blocks;
/**
* Create a new PageSeeder instance.
*
* @param BlockRepositoryInterface $blocks
* @param PageRepositoryInterface $pages
* @param TypeRepositoryInterface $types
*/
public function __construct(
BlockRepositoryInterface $blocks,
PageRepositoryInterface $pages,
TypeRepositoryInterface $types
) {
$this->pages = $pages;
$this->types = $types;
$this->blocks = $blocks;
}
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$pageType = $this->types->findBySlug('default');
$content = 'My content';
$block = (new BlockModel())->create([
'content' => $content,
]);
$entry = (new PagesDefaultPagesEntryModel())->create();
$page = $this->pages->create(
[
'en' => [
'title' => 'About page'
],
'slug' => str_slug('About page'),
'entry' => $entry,
'type' => $pageType,
'enabled' => true,
'home' => false,
'theme_layout' => 'theme::layouts/default.twig',
]
);
$page->allowedRoles()->sync([]);
$this->blocks->create(
[
'area' => $entry,
'entry' => $block,
'field' => $pageType->getEntryStream()->getField('content_blocks'),
'extension' => 'pixney.extension.wysiwyg_block',
'sort_order' => 1,
]
);
$this->command->info('Page and blocks for it seeded.');
}
}