|
1 |
| -.. index:: |
2 |
| - single: Installation |
3 |
| - single: Configuration |
4 |
| - |
5 | 1 | Installation
|
6 | 2 | ============
|
7 | 3 |
|
8 |
| -Prerequisites |
9 |
| -------------- |
10 |
| - |
11 |
| -There are some Sonata dependencies that need to be installed and configured beforehand. |
12 |
| - |
13 |
| -Required dependencies: |
14 |
| - |
15 |
| -* `SonataAdminBundle <https://docs.sonata-project.org/projects/SonataAdminBundle/en/4.x/>`_ |
16 |
| -* `SonataBlockBundle_ <https://docs.sonata-project.org/projects/SonataBlockBundle/en/4.x/>`_ |
17 |
| -* `SonataSeoBundle_ <https://docs.sonata-project.org/projects/SonataSeoBundle/en/3.x/>`_ |
18 |
| - |
19 |
| -And the persistence bundle (currently, not all the implementations of the Sonata persistence bundles are available): |
| 4 | +.. code-block:: bash |
20 | 5 |
|
21 |
| -* `SonataDoctrineOrmAdminBundle <https://docs.sonata-project.org/projects/SonataDoctrineORMAdminBundle/en/4.x/>`_ |
22 |
| - |
23 |
| -Follow also their configuration step; you will find everything you need in |
24 |
| -their own installation chapter. |
| 6 | + composer require sonata-project/page-bundle -W |
25 | 7 |
|
26 | 8 | .. note::
|
27 | 9 |
|
28 |
| - If a dependency is already installed somewhere in your project or in |
29 |
| - another dependency, you won't need to install it again. |
30 |
| - |
31 |
| -Enable the Bundle |
32 |
| ------------------ |
33 |
| - |
34 |
| -Add ``SonataPageBundle`` via composer:: |
35 |
| - |
36 |
| - composer require sonata-project/page-bundle |
37 |
| - |
38 |
| -.. note:: |
39 |
| - |
40 |
| - This will install the SymfonyCmfRoutingBundle_, too. |
41 |
| - |
42 |
| -Next, be sure to enable the bundles in your ``config/bundles.php`` file if they |
43 |
| -are not already enabled:: |
44 |
| - |
45 |
| - // config/bundles.php |
46 |
| - |
47 |
| - return [ |
48 |
| - // ... |
49 |
| - Sonata\PageBundle\SonataPageBundle::class => ['all' => true], |
50 |
| - ]; |
51 |
| - |
52 |
| -Configuration |
53 |
| -============= |
54 |
| - |
55 |
| -CMF Routing Configuration |
56 |
| -------------------------- |
57 |
| - |
58 |
| -``sonata.page.router`` service must be added to the index of ``cmf_routing.router`` chain router. |
59 |
| - |
60 |
| -Configure ``symfony-cmf/routing-bundle``: |
61 |
| - |
62 |
| -.. code-block:: yaml |
63 |
| -
|
64 |
| - # config/packages/cmf_routing_bundle.yaml |
65 |
| -
|
66 |
| - cmf_routing: |
67 |
| - chain: |
68 |
| - routers_by_id: |
69 |
| - # enable the DynamicRouter with high priority to allow overwriting configured routes with content |
70 |
| - #cmf_routing.dynamic_router: 200 |
71 |
| - # enable the symfony default router with a lower priority |
72 |
| - sonata.page.router: 150 |
73 |
| - router.default: 100 |
74 |
| -
|
75 |
| -Or register ``sonata.page.router`` automatically: |
76 |
| - |
77 |
| -.. code-block:: yaml |
78 |
| -
|
79 |
| - # config/packages/sonata_page.yaml |
80 |
| -
|
81 |
| - sonata_page: |
82 |
| - router_auto_register: |
83 |
| - enabled: true |
84 |
| - priority: 150 |
85 |
| -
|
86 |
| -SonataPageBundle Configuration |
87 |
| ------------------------------- |
88 |
| - |
89 |
| -.. code-block:: yaml |
90 |
| -
|
91 |
| - # config/packages/sonata_page.yaml |
92 |
| -
|
93 |
| - sonata_page: |
94 |
| - multisite: host |
95 |
| - use_streamed_response: true # set the value to false in debug mode or if the reverse proxy does not handle streamed response |
96 |
| - ignore_route_patterns: |
97 |
| - - ^(.*)admin(.*) # ignore admin route, ie route containing 'admin' |
98 |
| - - ^_(.*) # ignore symfony routes |
99 |
| -
|
100 |
| - class: |
101 |
| - page: App\Entity\SonataPagePage |
102 |
| - snapshot: App\Entity\SonataPageSnapshot |
103 |
| - block: App\Entity\SonataPageBlock |
104 |
| - site: App\Entity\SonataPageSite |
105 |
| -
|
106 |
| - ignore_uri_patterns: |
107 |
| - - ^/admin\/ # ignore admin route, ie route containing 'admin' |
108 |
| -
|
109 |
| - page_defaults: |
110 |
| - homepage: {decorate: false} # disable decoration for homepage, key - is a page route |
111 |
| -
|
112 |
| - default_template: default # template key from templates section, used as default for pages |
113 |
| - templates: |
114 |
| - default: { path: '@SonataPage/layout.html.twig', name: 'default' } |
115 |
| - 2columns: { path: '@SonataPage/2columns_layout.html.twig', name: '2 columns layout' } |
116 |
| -
|
117 |
| - direct_publication: false # or %kernel.debug% if you want to publish in dev mode (but not in prod) |
118 |
| -
|
119 |
| - # manage the http errors |
120 |
| - catch_exceptions: |
121 |
| - not_found: [404] # render 404 page with "not_found" key (name generated: _page_internal_error_{key}) |
122 |
| - fatal: [500] # so you can use the same page for different http errors or specify specific page for each error |
123 |
| -
|
124 |
| -SonataAdminBundle Configuration |
125 |
| -------------------------------- |
126 |
| - |
127 |
| -.. code-block:: yaml |
128 |
| -
|
129 |
| - # config/packages/sonata_admin.yaml |
130 |
| -
|
131 |
| - sonata_admin: |
132 |
| - assets: |
133 |
| - extra_javascripts: |
134 |
| - - bundles/sonatapage/app.js |
135 |
| - extra_stylesheets: |
136 |
| - - bundles/sonatapage/app.css |
137 |
| -
|
138 |
| -SonataBlockBundle Configuration |
139 |
| -------------------------------- |
140 |
| - |
141 |
| -.. code-block:: yaml |
142 |
| -
|
143 |
| - # config/packages/sonata_block.yaml |
144 |
| -
|
145 |
| - sonata_block: |
146 |
| - default_contexts: [sonata_page_bundle] |
147 |
| -
|
148 |
| -Security Configuration |
149 |
| ----------------------- |
150 |
| - |
151 |
| -.. code-block:: yaml |
152 |
| -
|
153 |
| - # config/packages/security.yaml |
154 |
| -
|
155 |
| - security: |
156 |
| - role_hierarchy: |
157 |
| - ROLE_ADMIN: ROLE_USER |
158 |
| - ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH, SONATA] |
159 |
| -
|
160 |
| - SONATA: |
161 |
| - - ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT # if you are not using acl then this line must be uncommented |
162 |
| - - ROLE_SONATA_PAGE_ADMIN_BLOCK_EDIT |
163 |
| -
|
164 |
| -If you have decided to customize your logout management (in particular |
165 |
| -if you have set ``invalidate_session`` to false), you might want to add |
166 |
| -this logout handler: |
167 |
| - |
168 |
| -.. code-block:: yaml |
169 |
| -
|
170 |
| - # config/packages/security.yaml |
171 |
| -
|
172 |
| - security: |
173 |
| - firewalls: |
174 |
| - main: # replace with your firewall name |
175 |
| - logout: |
176 |
| - handlers: ['sonata.page.cms_manager_selector'] |
177 |
| -
|
178 |
| -Routing Configuration |
179 |
| ---------------------- |
180 |
| - |
181 |
| -.. code-block:: yaml |
182 |
| -
|
183 |
| - # config/routes.yaml |
184 |
| -
|
185 |
| - sonata_page_exceptions: |
186 |
| - resource: '@SonataPageBundle/Resources/config/routing/exceptions.xml' |
187 |
| - prefix: / |
188 |
| -
|
189 |
| -Doctrine ORM Configuration |
190 |
| --------------------------- |
191 |
| - |
192 |
| -And these in the config mapping definition (or enable auto_mapping):: |
193 |
| - |
194 |
| - # config/packages/doctrine.yaml |
195 |
| - |
196 |
| - doctrine: |
197 |
| - orm: |
198 |
| - entity_managers: |
199 |
| - default: |
200 |
| - mappings: |
201 |
| - SonataPageBundle: ~ |
202 |
| - |
203 |
| -And then create the corresponding entities, ``src/Entity/SonataPageBlock``:: |
204 |
| - |
205 |
| - // src/Entity/SonataPageBlock.php |
206 |
| - |
207 |
| - use Doctrine\DBAL\Types\Types; |
208 |
| - use Doctrine\ORM\Mapping as ORM; |
209 |
| - use Sonata\PageBundle\Entity\BaseBlock; |
210 |
| - |
211 |
| - #[ORM\Entity] |
212 |
| - #[ORM\Table(name: 'page__block')] |
213 |
| - class SonataPageBlock extends BaseBlock |
214 |
| - { |
215 |
| - #[ORM\Id] |
216 |
| - #[ORM\Column(type: Types::INTEGER)] |
217 |
| - #[ORM\GeneratedValue] |
218 |
| - protected $id; |
219 |
| - } |
220 |
| - |
221 |
| -``src/Entity/SonataPagePage``:: |
222 |
| - |
223 |
| - // src/Entity/SonataPagePage.php |
224 |
| - |
225 |
| - use Doctrine\DBAL\Types\Types; |
226 |
| - use Doctrine\ORM\Mapping as ORM; |
227 |
| - use Sonata\PageBundle\Entity\BasePage; |
| 10 | + It will ask to execute few symfony recipes, type ``a`` to install all. |
228 | 11 |
|
229 |
| - #[ORM\Entity] |
230 |
| - #[ORM\Table(name: 'page__page')] |
231 |
| - class SonataPagePage extends BasePage |
232 |
| - { |
233 |
| - #[ORM\Id] |
234 |
| - #[ORM\Column(type: Types::INTEGER)] |
235 |
| - #[ORM\GeneratedValue] |
236 |
| - protected $id; |
237 |
| - } |
238 | 12 |
|
239 |
| -``src/Entity/SonataPageSite``:: |
| 13 | +Post install |
| 14 | +------------ |
| 15 | +Generate a migration |
240 | 16 |
|
241 |
| - // src/Entity/SonataPageSite.php |
| 17 | +.. code-block:: bash |
242 | 18 |
|
243 |
| - use Doctrine\DBAL\Types\Types; |
244 |
| - use Doctrine\ORM\Mapping as ORM; |
245 |
| - use Sonata\PageBundle\Entity\BaseSite; |
| 19 | + php bin/console doctrine:migrations:diff |
246 | 20 |
|
247 |
| - #[ORM\Entity] |
248 |
| - #[ORM\Table(name: 'page__site')] |
249 |
| - class SonataPageSite extends BaseSite |
250 |
| - { |
251 |
| - #[ORM\Id] |
252 |
| - #[ORM\Column(type: Types::INTEGER)] |
253 |
| - #[ORM\GeneratedValue] |
254 |
| - protected $id; |
255 |
| - } |
| 21 | +Execute migration |
256 | 22 |
|
257 |
| -and ``src/Entity/SonataPageSnapshot``:: |
| 23 | +.. code-block:: bash |
258 | 24 |
|
259 |
| - // src/Entity/SonataPageSnapshot.php |
| 25 | + php bin/console doctrine:migrations:migrate --no-interaction |
260 | 26 |
|
261 |
| - use Doctrine\ORM\Mapping as ORM; |
262 |
| - use Sonata\PageBundle\Entity\BaseSnapshot; |
| 27 | +Create your first site |
263 | 28 |
|
264 |
| - #[ORM\Entity] |
265 |
| - #[ORM\Table(name: 'page__snapshot')] |
266 |
| - class SonataPageSnapshot extends BaseSnapshot |
267 |
| - { |
268 |
| - #[ORM\Id] |
269 |
| - #[ORM\Column(type: Types::INTEGER)] |
270 |
| - #[ORM\GeneratedValue] |
271 |
| - protected $id; |
272 |
| - } |
| 29 | +.. code-block:: bash |
273 | 30 |
|
274 |
| -The only thing left is to update your schema:: |
| 31 | + bin/console sonata:page:create-site --enabled --name=localhost --locale=- --host=localhost --relativePath=- --enabledFrom=now --enabledTo=- --default |
275 | 32 |
|
276 |
| - bin/console doctrine:schema:update --force |
| 33 | +Create your first page at ``/admin/app/sonatapagepage/create`` |
277 | 34 |
|
278 | 35 | Next Steps
|
279 | 36 | ----------
|
|
0 commit comments