Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
backend helper
<?php
// Backend MediaGroups Helper
$this->media = $this->get('media_library.helper.backend')->create(
$this->frm,
$this->tpl,
$this->header,
array(
// create new with specified MediaGroup type
$this->get('media_library.factory.backend.group')->create(
$this->mediaGroupType
)
)
);
class BackendHelper
{
/** @var boolean */
protected $isSaved = false;
/** @var BackendMediaGroups */
protected $backendMediaGroups;
/** @var BackendMediaGroupHelper */
protected $backendMediaGroupHelper;
public function create(
$backendMediaGroups
) {
// Define backendMediaGroups
$this->backendMediaGroups = $this->backendMediaGroupsFactory->create(
$backendMediaGroups
);
}
public function loadForm()
{
}
public function parse()
{
}
public function save()
{
if ($this->isSaved) {
throw new \Exception('You can\'t use ->save() twice on the media helper.');
}
// We must redefine isSaved
$this->isSaved = true;
foreach ($this->backendMediaGroups as $key => $backendMediaGroup) {
$this->backendMediaGroupHelper->save(
$backendMediaGroup,
$this->form->getField('media_ids_' . $key)->getValue()
);
}
}
}
class BackendMediaGroupHelper
{
/** @var MediaGroupManager */
protected $mediaGroupManager;
/** @var MediaGroupMediaItemFactory */
protected $mediaGroupMediaItemFactory;
/** @var MediaGroupMediaItemManager */
protected $mediaGroupMediaItemManager;
/** @var MediaItemRepository */
protected $mediaItemRepository;
/**
* Construct
*
* @param MediaGroupManager $mediaGroupManager
* @param MediaGroupMediaItemManager $mediaGroupMediaItemManager
* @param MediaGroupMediaItemFactory $mediaGroupMediaItemFactory
* @param MediaItemRepository $mediaItemRepository
*/
public function __construct(
MediaGroupManager $mediaGroupManager,
MediaGroupMediaItemManager $mediaGroupMediaItemManager,
MediaGroupMediaItemFactory $mediaGroupMediaItemFactory,
MediaItemRepository $mediaItemRepository
) {
$this->mediaGroupManager = $mediaGroupManager;
$this->mediaGroupMediaItemManager = $mediaGroupMediaItemManager;
$this->mediaGroupMediaItemFactory = $mediaGroupMediaItemFactory;
$this->mediaItemRepository = $mediaItemRepository;
}
/**
* Save
*
* @param BackendMediaGroup $backendMediaGroup
* @param string formValue
*/
public function save(
BackendMediaGroup $backendMediaGroup,
$formValueNewMediaIds
) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.