Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Upgrade compact view to use video elements #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions Classes/Backend/InlineControlContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class InlineControlContainer
Expand All @@ -33,7 +34,7 @@ protected function renderPossibleRecordsSelectorTypeGroupDB(array $inlineConfigu
// Inject button before help-block
if (strpos($selector, '</div><div class="help-block">') > 0) {
$selector = str_replace('</div><div class="help-block">', $button . '</div><div class="help-block">', $selector);
// Try to inject it into the form-control container
// Try to inject it into the form-control container
} elseif (preg_match('/<\/div><\/div>$/i', $selector)) {
$selector = preg_replace('/<\/div><\/div>$/i', $button . '</div></div>', $selector);
} else {
Expand Down Expand Up @@ -67,7 +68,10 @@ protected function renderBynderButton(array $inlineConfiguration): string
$objectPrefix = $currentStructureDomObjectIdPrefix . '-' . $foreign_table;
$nameObject = $currentStructureDomObjectIdPrefix;

$compactViewUrl = BackendUtility::getModuleUrl('bynder_compact_view', ['element' => 'bynder' . $this->inlineData['config'][$nameObject]['md5']]);
$compactViewUrl = BackendUtility::getModuleUrl('bynder_compact_view', [
'element' => 'bynder' . $this->inlineData['config'][$nameObject]['md5'],
'assetTypes' => $this->getAssetTypesByAllowedElements($groupFieldConfiguration['appearance']['elementBrowserAllowed'])
]);

$this->requireJsModules[] = 'TYPO3/CMS/Bynder/CompactView';
$buttonText = htmlspecialchars($languageService->sL('LLL:EXT:bynder/Resources/Private/Language/locallang_be.xlf:compact_view.button'));
Expand Down Expand Up @@ -105,4 +109,30 @@ protected function bynderStorageAvailable(): bool
}
return false;
}
}

/**
* @param string $allowedElements
* @return string
*/
protected function getAssetTypesByAllowedElements($allowedElements): string
{
$assetTypes = [];
if (empty($allowedElements)) {
$assetTypes = [BynderDriver::ASSET_TYPE_IMAGE, BynderDriver::ASSET_TYPE_VIDEO];
} else {
$allowedElements = GeneralUtility::trimExplode(',', strtolower($allowedElements), true);
foreach (['jpg', 'png', 'gif'] as $element) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move ['jpg', 'png', 'gif'] to the extension configuration

if (in_array($element, $allowedElements)) {
$assetTypes[] = BynderDriver::ASSET_TYPE_VIDEO;
break;
}
}

if (in_array('mp4', $allowedElements)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, mp4 is the only allowed/available format?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

$assetTypes[] = BynderDriver::ASSET_TYPE_VIDEO;
}
}

return implode(',', $assetTypes);
}
}
20 changes: 18 additions & 2 deletions Classes/Controller/CompactViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* All code (c) Beech.it all rights reserved
*/

use BeechIt\Bynder\Service\BynderService;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use BeechIt\Bynder\Service\BynderService;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Resource\Index\Indexer;
use TYPO3\CMS\Core\Resource\ResourceStorage;
Expand Down Expand Up @@ -55,6 +55,9 @@ class CompactViewController
*/
protected $bynderService;

/**
* CompactViewController constructor.
*/
public function __construct()
{
$this->bynderService = GeneralUtility::makeInstance(BynderService::class);
Expand All @@ -66,6 +69,8 @@ public function __construct()
}

/**
* Action: Display compact view
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
Expand All @@ -78,13 +83,21 @@ public function indexAction(ServerRequestInterface $request, ResponseInterface $
'language' => $this->getBackendUserAuthentication()->uc['lang'] ?: ($this->getBackendUserAuthentication()->user['lang'] ?: 'en_EN'),
'apiBaseUrl' => $this->bynderService->getApiBaseUrl(),
'element' => $request->getQueryParams()['element'],
'assetTypes' => $request->getQueryParams()['assetTypes']
]);

$response->getBody()->write($this->view->render());

return $response;
}

/**
* Action: Retrieve file from storage
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @return ResponseInterface
*/
public function getFilesAction(ServerRequestInterface $request, ResponseInterface $response)
{
$files = [];
Expand All @@ -107,6 +120,9 @@ public function getFilesAction(ServerRequestInterface $request, ResponseInterfac
return $response;
}

/**
* @return ResourceStorage
*/
protected function getBynderStorage(): ResourceStorage
{
/** @var ResourceStorage $fileStorage */
Expand Down Expand Up @@ -137,4 +153,4 @@ protected function getIndexer(ResourceStorage $storage)
{
return GeneralUtility::makeInstance(Indexer::class, $storage);
}
}
}
2 changes: 1 addition & 1 deletion Classes/Resource/AssetProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,4 @@ public function __destruct()
sleep(ceil(3 - $difference));
}
}
}
}
47 changes: 36 additions & 11 deletions Classes/Resource/BynderDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* Date: 19-2-18
* All code (c) Beech.it all rights reserved
*/
use BeechIt\Bynder\Exception\NotImplementedException;
use BeechIt\Bynder\Service\BynderService;
use Bynder\Api\Impl\AssetBankManager;
use TYPO3\CMS\Core\Resource\Driver\DriverInterface;
use TYPO3\CMS\Core\Resource\Exception;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use BeechIt\Bynder\Exception\NotImplementedException;

/**
* Class BynderDriver
Expand All @@ -23,6 +23,9 @@ class BynderDriver implements DriverInterface
{
const KEY = 'bynder';

const ASSET_TYPE_VIDEO = 'video';
const ASSET_TYPE_IMAGE = 'image';

/**
* @var array
*/
Expand Down Expand Up @@ -213,16 +216,29 @@ public function getPublicUrl($identifier)
$format = $matches[2];
}

if (!in_array($format, ['mini', 'thul', 'webimage'])) {
$format = 'webimage';
}

try {
$fileInfo = $this->getBynderService()->getMediaInfo($identifier);
return $fileInfo['thumbnails'][$format];
switch ($fileInfo['type']) {
case BynderDriver::ASSET_TYPE_IMAGE:
if (!in_array($format, ['mini', 'thul', 'webimage'])) {
$format = 'webimage';
}
return $fileInfo['thumbnails'][$format];
case BynderDriver::ASSET_TYPE_VIDEO:
$urls = array_filter($fileInfo['videoPreviewURLs'], function ($url) {
return preg_match('/mp4$/i', $url);
});
if (empty($urls)) {
throw new Exception\FileDoesNotExistException(
'mp4 not found in video URL\'s',
1530626116454
);
}
return reset($urls);
}
} catch (\Exception $exception) {
throw new Exception\FileDoesNotExistException(
sprintf('Requested file "%s" coudn\'t be found', $identifier),
sprintf('Requested file "%s" couldn\'t be found', $identifier),
1519115242,
$exception
);
Expand Down Expand Up @@ -689,8 +705,17 @@ protected function extractFileInformation(array $mediaInfo, array $propertiesToE
{
if (empty($propertiesToExtract)) {
$propertiesToExtract = [
'size', 'atime', 'mtime', 'ctime', 'mimetype', 'name', 'extension',
'identifier', 'identifier_hash', 'storage', 'folder_hash'
'size',
'atime',
'mtime',
'ctime',
'mimetype',
'name',
'extension',
'identifier',
'identifier_hash',
'storage',
'folder_hash'
];
}
$fileInformation = [];
Expand Down Expand Up @@ -736,7 +761,7 @@ protected function getSpecificFileInformation($mediaInfo, $property)
case 'folder_hash':
return $this->hashIdentifier('');

// Metadata
// Metadata
case 'title':
return $mediaInfo['name'];
case 'description':
Expand Down Expand Up @@ -799,4 +824,4 @@ public function __destruct()
GeneralUtility::unlink_tempfile($tempFile);
}
}
}
}
26 changes: 12 additions & 14 deletions Resources/Private/Templates/CompactView/Index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<link rel="stylesheet" type="text/css"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CSS isn't needed anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is handled by the JS now. I followed documentation of https://developer-docs.bynder.com/UI%20components/#compact-view where it only mentioned the <script> to setup.

href="https://d8ejoa1fys2rk.cloudfront.net/modules/compactview/includes/css/compactview_global-1.0.1.css">

<div id="bynder-compactview"
data-language="{language}"
data-button="Pick a file from Bynder"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you drop the button text?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me an example, where this is shown? The inline button uses this label. I cannot see where this is used in this compact view :-)

data-folder="bynder-compactview"
data-zindex="300"
data-collections="false"
data-header="false"
data-assetTypes="{assetTypes}"
data-autoload="true"
data-fullScreen="true"
data-collections="false"
data-defaultEnvironment="{apiBaseUrl}"
data-button-id="1"
></div>
<script src="https://d8ejoa1fys2rk.cloudfront.net/modules/compactview/includes/js/client-1.0.1.min.js"></script>
data-folder="bynder-compactview"
data-fullScreen="true"
data-header="false"
data-language="{language}"
data-mode="multi"
data-zindex="300"
>
</div>
<script src="https://d8ejoa1fys2rk.cloudfront.net/modules/compactview/includes/js/client-1.1.0.min.js"></script>

<div id="importedAssets"></div>
<script>
Expand All @@ -34,4 +32,4 @@

parentDocument.dispatchEvent(new CustomEvent("BynderAddMedia", {"detail": details}));
});
</script>
</script>