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] Use the latest Bynder SDK #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions Classes/Backend/ImageManipulationElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
* Date: 21-2-18
* All code (c) Beech.it all rights reserved
*/

use BeechIt\Bynder\Resource\BynderDriver;

/**
* Class ImageManipulationElement
*
* Override of ImageManipulationElement to hide cropper for Bynder files
*/
class ImageManipulationElement extends \TYPO3\CMS\Backend\Form\Element\ImageManipulationElement
{
public function render()
public function render(): array
{
$resultArray = $this->initializeResultArray();

Expand All @@ -25,6 +24,7 @@ public function render()
// Early return in case of Bynder file (or no file)
return $resultArray;
}

return parent::render();
}
}
10 changes: 3 additions & 7 deletions Classes/Backend/InlineControlContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
use BeechIt\Bynder\Resource\BynderDriver;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Class InlineControlContainer
*
* Override core InlineControlContainer to inject Bynder button
*/
class InlineControlContainer extends \TYPO3\CMS\Backend\Form\Container\InlineControlContainer
{

/**
* @param array $inlineConfiguration
* @return string
*/
protected function renderPossibleRecordsSelectorTypeGroupDB(array $inlineConfiguration)
protected function renderPossibleRecordsSelectorTypeGroupDB(array $inlineConfiguration): string
{
$selector = parent::renderPossibleRecordsSelectorTypeGroupDB($inlineConfiguration);

Expand All @@ -35,7 +31,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 @@ -101,7 +97,7 @@ protected function renderBynderButton(array $inlineConfiguration): string
*/
protected function bynderStorageAvailable(): bool
{
/** @var ResourceStorage $fileStorage */
/** @var \TYPO3\CMS\Core\Resource\ResourceStorage $fileStorage */
foreach ($this->getBackendUserAuthentication()->getFileStorages() as $fileStorage) {
if ($fileStorage->getDriverType() === BynderDriver::KEY) {
return true;
Expand Down
13 changes: 10 additions & 3 deletions Classes/Controller/CompactViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,25 @@
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Index\Indexer;
use TYPO3\CMS\Core\Resource\ResourceStorageInterface;
use TYPO3Fluid\Fluid\View\ViewInterface;

class CompactViewController
{
/** @var \TYPO3Fluid\Fluid\View\ViewInterface */
protected $view;
/** @var \TYPO3\CMS\Core\Resource\ResourceStorageInterface */
private $bynderStorage;

/** @var \BeechIt\Bynder\Service\BynderService */
protected $bynderService;

/** @var \TYPO3\CMS\Core\Resource\Index\Indexer */
private $indexer;

/** @var \TYPO3Fluid\Fluid\View\ViewInterface */
protected $view;

public function __construct(
ResourceStorageInterface $bynderStorage,
BynderService $bynderService,
Expand Down Expand Up @@ -57,7 +64,7 @@ public function getFilesAction(ServerRequestInterface $request): ResponseInterfa
$error = '';
foreach ($request->getParsedBody()['files'] ?? [] as $fileIdentifier) {
$file = $this->bynderStorage->getFile($fileIdentifier);
if ($file) {
if ($file instanceof File) {
// (Re)Fetch metadata
$this->indexer->extractMetaData($file);
$files[] = $file->getUid();
Expand Down
84 changes: 84 additions & 0 deletions Classes/EventListener/PersistBynderFileStorage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace BeechIt\Bynder\EventListener;

use BeechIt\Bynder\Resource\BynderDriver;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Package\Event\AfterPackageActivationEvent;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class PersistBynderFileStorage
{
/** @var int */
private $executionTime;

/** @var \TYPO3\CMS\Core\Resource\StorageRepository */
private $storageRepository;

public function __construct(StorageRepository $storageRepository)
{
$this->executionTime = $GLOBALS['EXEC_TIME'] ?? time();
$this->storageRepository = $storageRepository;
}

/**
* @param \TYPO3\CMS\Core\Package\Event\AfterPackageActivationEvent $event
* @return void
*/
public function __invoke(AfterPackageActivationEvent $event): void
{
if ($event->getPackageKey() !== 'bynder') {
return;
}

if ($this->storageRepository->findByStorageType(BynderDriver::KEY) !== []) {
return;
}

$this->createBynderStorage();
}

/**
* @return void
*/
private function createBynderStorage(): void
{
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);

// Create Bynder storage
$field_values = [
'pid' => 0,
'tstamp' => $this->executionTime,
'crdate' => $this->executionTime,
'name' => 'Bynder',
'description' => 'Automatically created during the installation of EXT:bynder',
'driver' => BynderDriver::KEY,
'configuration' => '',
'is_online' => 1,
'is_browsable' => 1,
'is_public' => 1,
'is_writable' => 0,
'is_default' => 0,
// We use the processed file folder of the default storage as fallback
'processingfolder' => '1:/_processed_/',
];
Comment on lines +50 to +65
Copy link

Choose a reason for hiding this comment

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

You can pass this directory to the insert without instantiating a variable.


$dbConnection = $connectionPool->getConnectionForTable('sys_file_storage');
$dbConnection->insert('sys_file_storage', $field_values);
$storageUid = (int)$dbConnection->lastInsertId('sys_file_storage');

// Create file mount (for the editors)
$field_values = [
'pid' => 0,
'tstamp' => $this->executionTime,
'title' => 'Bynder',
'description' => 'Automatically created during the installation of EXT:bynder',
'path' => '',
'base' => $storageUid,
];
Comment on lines +72 to +79
Copy link

Choose a reason for hiding this comment

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

Same here


$dbConnection = $connectionPool->getConnectionForTable('sys_filemounts');
$dbConnection->insert('sys_filemounts', $field_values);
}
}
Loading