-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
68 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Resource Validation | ||
In some cases, you need to validate your resource, before it should get dispatched in a specific operation like `insert`, `update` or `delete`. | ||
Just use the `DynamicSearchEvents::RESOURCE_CANDIDATE_VALIDATION` event to manipulate the resource candidate: | ||
|
||
```yaml | ||
App\DynamicSearch\EventListener\ResourceCandidateListener: | ||
tags: | ||
- { name: kernel.event_subscriber } | ||
``` | ||
```php | ||
<?php | ||
|
||
namespace App\DynamicSearch\EventListener; | ||
|
||
use DynamicSearchBundle\DynamicSearchEvents; | ||
use DynamicSearchBundle\Event\ResourceCandidateEvent; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class ResourceCandidateListener implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
DynamicSearchEvents::RESOURCE_CANDIDATE_VALIDATION => ['validateResourceCandidate', 0] | ||
]; | ||
} | ||
|
||
public function validateResourceCandidate(ResourceCandidateEvent $e): void | ||
{ | ||
$resourceCandidate = $e->getResourceCandidate(); | ||
$resource = $resourceCandidate->getResource(); | ||
|
||
// always allow dispatching delete operation as they are | ||
if ($resourceCandidate->getDispatchType() === 'delete') { | ||
return; | ||
} | ||
|
||
// example I: change dispatch type to force delete | ||
if ($yourConditionMet && $resourceCandidate->getDispatchType() === 'update' && $resourceCandidate->isAllowedToModifyDispatchType() === true) { | ||
$resourceCandidate->setDispatchType('delete'); | ||
} | ||
|
||
// example II: set resource to null if it should not get indexed at all | ||
if ($yourConditionMet && $resourceCandidate->isAllowedToModifyResource() === true) { | ||
$resourceCandidate->setResource(null); | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 0 additions & 110 deletions
110
src/DynamicSearchBundle/Resource/Proxy/ProxyResource.php
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
src/DynamicSearchBundle/Resource/Proxy/ProxyResourceInterface.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.