Skip to content

Commit

Permalink
Changed: README.md and CHANGELOG.md, Preparation for 1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ericges committed Dec 13, 2023
1 parent 9af2ebf commit 824b104
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

## [1.3.3] - 2023-12-13
- Feature: delete ml products with frontend requests

## [1.3.2] - 2023-11-06
- Fixed: support for heimrichhannot/contao-form-type-bundle v0.1.3

Expand Down
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,47 @@ huh_media_library:
# If true, the filenames of the generated product downloads will be sanitized.
sanitize_download_filenames: false
```
### Delete ML Products
Submit a `DELETE`-Request to the product's details URL. If the HTTP `DELETE` method is unavailable, use a hidden form field with a name of `_method` and the value `DELETE` instead.

Example for use within a Bootstrap 5 modal:
```html
<form method="post">
<input type="hidden" name="REQUEST_TOKEN" value="{{ request_token }}">
<input type="hidden" name="_method" value="DELETE">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
<button type="submit" class="btn btn-primary">Löschen</button>
</form>
```

#### More on creating a Delete Form

Further, if you need to inject a request token into the respective `HeimrichHannot\ReaderBundle` reader template, you may want to implement an EventListener:

```php
use Contao\CoreBundle\Csrf\ContaoCsrfTokenManager;
use HeimrichHannot\ReaderBundle\Event\ReaderBeforeRenderEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MLDeleteFormEventListener implements EventSubscriberInterface
{
public function __construct(private readonly ContaoCsrfTokenManager $csrfTokenManager) {}
public static function getSubscribedEvents()
{
return [ReaderBeforeRenderEvent::NAME => 'onReaderBeforeRenderEvents'];
}
public function onReaderBeforeRenderEvents(ReaderBeforeRenderEvent $event): void
{
if ($item['dataContainer'] === 'tl_ml_product')
{
$item = $event->getTemplateData();
$item['request_token'] = $this->csrfTokenManager->getDefaultTokenValue();
$event->setTemplateData($item);
}
}
}
```

0 comments on commit 824b104

Please sign in to comment.