Skip to content

Commit cbaa994

Browse files
committed
Initial commit
1 parent edd106a commit cbaa994

File tree

325 files changed

+29413
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

325 files changed

+29413
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "page/themes/hugo-theme-learn"]
2+
path = page/themes/hugo-theme-learn
3+
url = https://github.com/matcornic/hugo-theme-learn

LICENSE.md

Lines changed: 173 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.PHONY: build
2+
build:
3+
cd page; hugo \
4+
--cleanDestinationDir \
5+
--contentDir ../docs \
6+
--destination ../build \
7+
--verbose
8+
9+
dev:
10+
cd page; hugo server \
11+
--cleanDestinationDir \
12+
--contentDir ../docs \
13+
--destination ../build \
14+
--verbose
15+
16+
clean:
17+
rm -r build

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
1-
# contao-docs
2-
Contao Documentation
1+
# Contao Documentation
2+
3+
The documentation for the Contao project will be maintained in this repository.
4+
5+
## Build
6+
7+
```
8+
make build
9+
```
10+
11+
Builds the entire documentation into the `build` directory using the [Hugo site generator](https://gohugo.io/commands/hugo/).
12+
13+
```
14+
make dev
15+
```
16+
17+
Spins up the development server which automatically tracks changes in the `docs` directory and rebuilds the frontend.
18+
You can access the frontend on [http://localhost:1313](http://localhost:1313).
19+
20+
```
21+
make clean
22+
```
23+
24+
Cleans the build directory.
25+
26+
## Licence
27+
28+
The Contao documentation is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
29+
License](https://creativecommons.org/licenses/by-nc-sa/4.0/) license (CC BY-NC-SA 4.0). If you want to redistribute a modified or unmodified version of the documentation, you can do so under the license terms.
30+
31+
If you contribute to the documentation, e.g. by creating pull requests, you grant us full usage rights of any content you create or upload. You also ensure that your
32+
content does not violate any third-party rights.
33+
34+
We are not claiming exclusive usage rights, therefore you are free to use your
35+
contributed content (e.g. texts or images) in any other project as well.

docs/_index.de.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Contao Dokumentation"
3+
---
4+
5+
# Contao Documentation

docs/_index.en.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Contao Documentation"
3+
---
4+
5+
# Contao Documentation

docs/about/_index.de.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "Contao Dokumentation"
3+
chapter: true
4+
lastmod: "2017-03-03"
5+
---
6+
7+
# Contao Documentation

docs/about/by-last-mod.en.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: "Contao Documentation"
3+
description: "Ich bin eine Beschreibung"
4+
lastmod: "2018-04-06"
5+
---
6+
7+
# Contao Documentation

docs/cookbook/_index.en.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Cookbook"
3+
weight: 3
4+
---
5+

docs/cookbook/backend-routes.en.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
---
2+
title: "Backend Routes"
3+
weight: 1
4+
---
5+
6+
## Adding custom backend routes
7+
8+
You can use the Contao backend to display content generated in your own custom Controllers.
9+
This way you can develop custom extensions without the need to use DCA configuration.
10+
The following example can be changed according to your own setup. For example you're
11+
not obliged to use the annotation configuration for your routes you could use
12+
XML or YAML interchangeably.
13+
14+
### Create your Controller and Template
15+
16+
The first step is to create your own Controller. A more detailed explanation
17+
on how Symfony Controller work can be found in the [Symfony documentation](https://symfony.com/doc/current/controller.html).
18+
The Controller class is placed inside the `Controller` directory in your `AppBundle`
19+
and is configured through annotations.
20+
21+
```php
22+
<?php
23+
24+
// src/AppBundle/Controller/BackendController.php
25+
26+
declare(strict_types=1);
27+
28+
namespace AppBundle\Controller;
29+
30+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
31+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
32+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
33+
use Symfony\Component\HttpFoundation\Response;
34+
35+
/**
36+
* @Route("/contao", defaults={
37+
* "_scope" = "backend",
38+
* "_token_check" = true,
39+
* "_backend_module" = "my-modules"
40+
* })
41+
*/
42+
class BackendController extends AbstractController
43+
{
44+
/**
45+
* @Route("/my-backend-route", name="app.backend-route")
46+
* @Template("AppBundle::my_backend_route.html.twig")
47+
*/
48+
public function backendRouteAction()
49+
{
50+
return [];
51+
}
52+
}
53+
```
54+
55+
We need three different route parameters.
56+
57+
* `_scope`: This forces the scope of this route to be `backend`. That way you're
58+
telling Contao, that this route belongs to the backend and should be handled accordingly.
59+
* `_token_check`: If you're using Contao forms with the RequestToken integration
60+
you need to set this to true, in order to get it to work.
61+
* `_backend_module`: This attribute is not mandatory but will be used to match
62+
the current route in order to highlight the currently active node in the backend menu.
63+
More on this later.
64+
65+
Be sure to have imported your bundles Controllers in your `routing.yml` *before*
66+
the `ContaoCoreBundle` routes.
67+
68+
```yaml
69+
# app/config/routing.yml
70+
71+
app:
72+
resource: '@AppBundle/Controller/'
73+
type: annotation
74+
```
75+
76+
Our route `backendRouteAction` will render the template `AppBundle::my_backend_route.html.twig`
77+
which must be placed into `src/AppBundle/Resources/views`.
78+
79+
```twig
80+
{% extends "@ContaoCore/Backend/be_page.html.twig" %}
81+
82+
{% block headline %}
83+
Not only the content of the `title`-tag but also the title of the content section.
84+
{% endblock %}
85+
86+
{% block error %}
87+
Will be placed within the error block.
88+
{% endblock %}
89+
90+
{% block main %}
91+
<div class="tl_listing_container">
92+
Main Content.
93+
</div>
94+
{% endblock %}
95+
```
96+
97+
As we extend from `@ContaoCore/Backend/be_page.html.twig` it is worth noting
98+
that there are three different blocks you can currently use:
99+
100+
* `headline`: This block renders the headline of the document.
101+
* `error`: In case of an error, place your message here, it will be placed prominently
102+
on the top of the page
103+
* `main`: This is the content area for output.
104+
105+
This exampe renders like this:
106+
107+
![](../images/custom-backend-routes-1.png)
108+
109+
### Extend the backend menu
110+
111+
Most of the time you probably want to add a menu entry for your backend module.
112+
Since the backend menu can be extended with an `EventListener` we can easily
113+
create one that listens for the menu event to be dispatched.
114+
115+
```php
116+
<?php
117+
// src/AppBundle/EventListener/BackendMenuListener.php
118+
119+
declare(strict_types=1);
120+
121+
namespace AppBundle\EventListener;
122+
123+
use Contao\CoreBundle\Event\MenuEvent;
124+
use Symfony\Component\HttpFoundation\RequestStack;
125+
use Symfony\Component\Routing\RouterInterface;
126+
127+
class BackendMenuListener
128+
{
129+
protected $router;
130+
protected $requestStack;
131+
132+
public function __construct(RouterInterface $router, RequestStack $requestStack)
133+
{
134+
$this->router = $router;
135+
$this->requestStack = $requestStack;
136+
}
137+
138+
public function onBuild(MenuEvent $event): void
139+
{
140+
$factory = $event->getFactory();
141+
$tree = $event->getTree();
142+
143+
$contentNode = $tree->getChild('content');
144+
145+
$node = $factory->createItem(
146+
'my-modules',
147+
[
148+
'label' => 'My Modules',
149+
'attributes' => [
150+
'title' => 'Title',
151+
'href' => $this->router->generate('app.backend-route'),
152+
'class' => 'my-modules'
153+
],
154+
]
155+
);
156+
157+
$node->setCurrent($this->requestStack->getCurrentRequest()->get('_backend_module') === 'my-modules');
158+
159+
$contentNode->addChild($node);
160+
}
161+
}
162+
163+
```
164+
165+
This EventListener creates a new menu node and handles its own `currentState` by
166+
reading and matching the previously mentioned request attribute `_backend_module`.
167+
168+
The only thing left to do is to register the EventListener in the service container.
169+
For this to work, we add the following lines to our service configuration in `app/config/services.yml`.
170+
171+
```yaml
172+
services:
173+
174+
contao.listener.user_backend_menu_listener:
175+
class: AppBundle\EventListener\BackendMenuListener
176+
arguments:
177+
- "@router"
178+
- "@request_stack"
179+
tags:
180+
- { name: kernel.event_listener, event: contao.backend_menu_build, method: onBuild, priority: -255 }
181+
```
182+
183+
We purposely assign it a low priority, so that we can be sure to be loaded after
184+
the Contao Core EventListeners. Otherwise the `content` node we assign ourself to
185+
will not be available yet.
186+
187+
And that's it. You controller should now be callable from the main backend menu in
188+
the sidebar.
48.5 KB
Loading

docs/cookbook/test/_index.en.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: "Test"
3+
weight: 3
4+
---
5+
6+
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
7+
ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
8+
dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
9+
tempor invidunt ut [labore et dolore magna aliquyam erat][1], sed diam voluptua. At vero eos et accusam et
10+
justo duo dolores et ea rebum.
11+
12+
13+
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
14+
ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
15+
dolores et ea rebum. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
16+
tempor invidunt ut [labore et dolore][2] magna aliquyam erat, sed diam voluptua. At vero eos et accusam et
17+
justo duo dolores et ea rebum.
18+
19+
[1]: https://www.test1.ch
20+
[2]: https://www.test2.ch

0 commit comments

Comments
 (0)