Skip to content

Commit aa8cd97

Browse files
nuryagdymAkenRoberts
authored andcommitted
added soft deletable filter configuration and updated codes and paths to fit Symfony 4
1 parent 1d01c14 commit aa8cd97

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

doc/symfony4.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Content:
1313

1414
- [Symfony 4](#sf4-app) application
1515
- Extensions metadata [mapping](#ext-mapping)
16+
- Extensions filters [filtering](#ext-filtering)
1617
- Extension [listeners](#ext-listeners)
1718
- Usage [example](#ext-example)
1819
- Some [tips](#more-tips)
@@ -40,7 +41,7 @@ To add it to your project:
4041

4142
Let's start from the mapping. In case you use the **translatable**, **tree** or **loggable**
4243
extension you will need to map those abstract mapped superclasses for your ORM to be aware of.
43-
To do so, add some mapping info to your **doctrine.orm** configuration, edit **app/config/config.yml**:
44+
To do so, add some mapping info to your **doctrine.orm** configuration, edit **config/doctrine.yaml**:
4445

4546
```yaml
4647
doctrine:
@@ -121,18 +122,34 @@ orm:
121122
prefix: Gedmo\Tree\Entity
122123
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity"
123124
```
125+
<a name="ext-filtering"></a>
126+
## Filters
124127
128+
The **softdeleteable** ORM filter also needs to be configured, so that soft deleted records are filtered when querying.
129+
To do so, add this filter info to your **doctrine.orm** configuration, edit **config/doctrine.yaml**:
130+
```yaml
131+
doctrine:
132+
dbal:
133+
# your dbal config here
134+
orm:
135+
auto_generate_proxy_classes: %kernel.debug%
136+
auto_mapping: true
137+
# only these lines are added additionally
138+
filters:
139+
softdeleteable:
140+
class: Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter
141+
```
125142
<a name="ext-listeners"></a>
126143
127144
## Doctrine extension listener services
128145
129146
Next, the heart of extensions are behavioral listeners which pours all the sugar. We will
130-
create a **yml** service file in our config directory. The setup can be different, your config could be located
131-
in the bundle, it depends on your preferences. Edit **app/config/packages/doctrine_extensions.yml**
147+
create a **yaml** service file in our config directory. The setup can be different, your config could be located
148+
in the bundle, it depends on your preferences. Edit **config/packages/doctrine_extensions.yaml**
132149
133150
```yaml
134151
# services to handle doctrine extensions
135-
# import it in config.yml
152+
# import it in config/packages/doctrine_extensions.yaml
136153
services:
137154
# Doctrine Extension listeners to handle behaviors
138155
gedmo.listener.tree:
@@ -274,7 +291,7 @@ class DoctrineExtensionSubscriber implements EventSubscriberInterface
274291
## Example
275292

276293
After that, you have your extensions set up and ready to be used! Too easy right? Well,
277-
if you do not believe me, let's create a simple entity in our **Acme** project:
294+
if you do not believe me, let's create a simple entity in our project:
278295

279296
```php
280297

@@ -369,37 +386,34 @@ Everything will work just fine, you can modify the **App\Controller\DemoControll
369386
and add an action to test how it works:
370387

371388
```php
372-
// file: src/Acme/DemoBundle/Controller/DemoController.php
389+
// file: src/Controller/DemoController.php
373390
// include this code portion
374391

375392
/**
376393
* @Route("/posts", name="_demo_posts")
377394
*/
378395
public function postsAction()
379396
{
380-
$em = $this->getDoctrine()->getEntityManager();
381-
$repository = $em->getRepository('AcmeDemoBundle:BlogPost');
397+
$em = $this->getDoctrine()->getManager();
398+
$repository = $em->getRepository(App\Entity\BlogPost::class);
382399
// create some posts in case if there aren't any
383-
if (!$repository->findOneById('hello_world')) {
384-
$post = new \Acme\DemoBundle\Entity\BlogPost();
400+
if (!$repository->find('hello_world')) {
401+
$post = new App\Entity\BlogPost();
385402
$post->setTitle('Hello world');
386403

387-
$next = new \Acme\DemoBundle\Entity\BlogPost();
404+
$next = new App\Entity\BlogPost();
388405
$next->setTitle('Doctrine extensions');
389406

390407
$em->persist($post);
391408
$em->persist($next);
392409
$em->flush();
393410
}
394-
$posts = $em
395-
->createQuery('SELECT p FROM AcmeDemoBundle:BlogPost p')
396-
->getArrayResult()
397-
;
398-
die(var_dump($posts));
411+
$posts = $repository->findAll();
412+
dd($posts);
399413
}
400414
```
401415

402-
Now if you follow the url: **http://your_virtual_host/app_dev.php/demo/posts** you
416+
Now if you follow the url: **http://your_virtual_host/demo/posts** you
403417
should see a print of posts, this is only an extension demo, we will not create a template.
404418

405419
<a name="more-tips"></a>

0 commit comments

Comments
 (0)