Skip to content
Permalink
Browse files

No need to assign something that we already have

  • Loading branch information...
carakas committed Oct 7, 2019
1 parent b6fc947 commit d2c80a34e7ad768353b93826f33506ad4b16336e
@@ -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`
@@ -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`
@@ -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();
@@ -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());
@@ -38,7 +38,7 @@
</div>
</div>

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

{{ form_row(form.text) }}
</div>
@@ -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>
@@ -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,
];
};
}
@@ -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 %}

0 comments on commit d2c80a3

Please sign in to comment.
You can’t perform that action at this time.