Skip to content

Commit

Permalink
No need to assign something that we already have
Browse files Browse the repository at this point in the history
  • Loading branch information
carakas committed Oct 10, 2019
1 parent b6fc947 commit d2c80a3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 19 deletions.
15 changes: 1 addition & 14 deletions docs/07. media library/03. integrating in your module.md
Expand Up @@ -86,11 +86,6 @@ $this->mediaGroup = MediaGroup::create(MediaGroupType::fromString('image'));
### In your Create Command Handler class

Just pass the media group entity to your custom entity constructor.

### In your Add action

```php
$this->tpl->assign('mediaGroup', $form->getData()->mediaGroup);
```
[View example](https://github.com/forkcms/forkcms/blob/master/src/Backend/Modules/MediaGalleries/Actions/MediaGalleryAdd.php): `/src/Backend/Modules/MediaGalleries/Actions/MediaGalleryAdd.php`
Expand Down Expand Up @@ -123,21 +118,13 @@ if (!$this->mediaGroup instanceof MediaGroup) {
}
```

### In your Edit action

```php
$this->tpl->assign('mediaGroup', $form->getData()->mediaGroup);
```

Example: `src/Backend/Modules/MediaGalleries/Actions/Edit.php`

### In your Add and Edit template

This will result in:
![Screenshow of the Backend Meda Helper](./assets/integration-example-01.png)

```twig
{{ form_widget(form.mediaGroup, {'mediaGroup': mediaGroup}) }}
{{ form_widget(form.mediaGroup) }}
```

Example: `src/Backend/Modules/MediaGalleries/Layout/Templates/Add.html.twig` and `src/Backend/Modules/MediaGalleries/Layout/Templates/Edit.html.twig`
Expand Down
Expand Up @@ -104,7 +104,7 @@ private function parseForm(Form $form): void
{
$this->template->assign('form', $form->createView());
$this->template->assign('backLink', $this->getBackLink());
$this->template->assign('mediaGroup', $form->getData()->mediaGroup);
$this->template->assign('mediaGroup', $form->getData()->mediaGroup); // @deprecated not needed anymore from Fork 5.7

// Call parent
$this->parse();
Expand Down
Expand Up @@ -45,7 +45,7 @@ public function execute(): void
$this->template->assign('form', $form->createView());
$this->template->assign('backLink', $this->getBackLink());
$this->template->assign('mediaGallery', $mediaGallery);
$this->template->assign('mediaGroup', $form->getData()->mediaGroup);
$this->template->assign('mediaGroup', $form->getData()->mediaGroup); // @deprecated not needed anymore from Fork 5.7

$this->header->appendDetailToBreadcrumbs($mediaGallery->getTitle());

Expand Down
Expand Up @@ -38,7 +38,7 @@
</div>
</div>

{{ form_widget(form.mediaGroup, {'mediaGroup': mediaGroup}) }}
{{ form_widget(form.mediaGroup) }}

{{ form_row(form.text) }}
</div>
Expand Down
Expand Up @@ -41,7 +41,7 @@
{% endif %}

{# Including the MediaLibrary MediaGroup Helper #}
{{ form_widget(form.mediaGroup, {'mediaGroup': mediaGroup}) }}
{{ form_widget(form.mediaGroup) }}

{{ form_row(form.text) }}
</div>
Expand Down
Expand Up @@ -183,11 +183,12 @@ private function getMediaGroupFromMediaGroupData(array $mediaGroupData): MediaGr

private function getMediaGroupTransformFunction(): callable
{
return function (MediaGroup $mediaGroup) {
return static function (MediaGroup $mediaGroup) {
return [
'id' => $mediaGroup->getId(),
'type' => $mediaGroup->getType(),
'mediaIds' => implode(',', $mediaGroup->getIdsForConnectedItems()),
'mediaGroup' => $mediaGroup,
];
};
}
Expand Down
Expand Up @@ -4,6 +4,9 @@
#}

{% block media_group_widget %}
{% if not mediaGroup is defined %}
{% set mediaGroup = form.vars.data.mediaGroup %}
{% endif %}
{{ include_once("MediaLibrary/Resources/views/BackendMediaGroupsHelper.html.twig") }}
{% import "Layout/Templates/macros.html.twig" as macro %}
{% import _self as mediaMacro %}
Expand Down

0 comments on commit d2c80a3

Please sign in to comment.