Skip to content

Commit

Permalink
Merge pull request #17 from Wanere/patch-2
Browse files Browse the repository at this point in the history
Fix Multi Panel issue and troubleshooting blocks deletion
  • Loading branch information
DjLeChuck authored Oct 29, 2019
2 parents acf28a1 + 0c3e444 commit ddd8a15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ $builder->add('content', PanelType::class, [
]);
```

#### Troubleshooting block deletion
For some unknown reason, blocks are not properly deleted on saving the form, probably because no update is detected. To solve this, you need to create an event on `preUpdate` (in your Sonata Admin for example), to be triggered when you save the form.
```php
public function preUpdate($object)
{
!$object->getContent() ?: $object->getContent()->updatedTimestamps();
}
```

### Create a Block entity and its Block Manager

Start by creating your Block entity like the following example:
Expand Down
5 changes: 3 additions & 2 deletions Resources/public/js/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ $(document).ready(function () {
$('[data-behavior="add-block"]').each(function () {
$(this).on('change', $(this), function (e) {
$addBlockSelect = $(this);
$collectionHolder = $('#' + $addBlockSelect.data('panel-id'));
let parentId = $addBlockSelect.data('panel-id');
$collectionHolder = $('#' + parentId);
$collectionHolder.data('index', $collectionHolder.find('.ublock').length);

e.preventDefault();
Expand All @@ -16,7 +17,7 @@ $(document).ready(function () {
var index = $collectionHolder.data('index');

// Get the prototype data
var proto = $("div[data-type='" + selectedblockType + "']").data('prototype');
var proto = $("#" + parentId + ">div[data-type='" + selectedblockType + "']").data('prototype');

if (typeof proto === 'undefined') {
return;
Expand Down

0 comments on commit ddd8a15

Please sign in to comment.