Skip to content

Commit

Permalink
[TASK] Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Jul 28, 2017
0 parents commit 28587cc
Show file tree
Hide file tree
Showing 12 changed files with 834 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Classes/Domain/Model/News.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace GeorgRinger\NewsGallery\Domain\Model;

class News extends \GeorgRinger\News\Domain\Model\News {

/**
* @var string
*/
protected $txGalleryCollections = '';

/**
* @var int
*/
protected $txGalleryStorage = 0;

/**
* @var string
*/
protected $txGalleryFolder = '';

/**
* @return string
*/
public function getTxGalleryCollections()
{
return $this->txGalleryCollections;
}

/**
* @param string $txGalleryCollections
*/
public function setTxGalleryCollections($txGalleryCollections)
{
$this->txGalleryCollections = $txGalleryCollections;
}

/**
* @return int
*/
public function getTxGalleryStorage()
{
return $this->txGalleryStorage;
}

/**
* @param int $txGalleryStorage
*/
public function setTxGalleryStorage($txGalleryStorage)
{
$this->txGalleryStorage = $txGalleryStorage;
}

/**
* @return string
*/
public function getTxGalleryFolder()
{
return $this->txGalleryFolder;
}

/**
* @param string $txGalleryFolder
*/
public function setTxGalleryFolder($txGalleryFolder)
{
$this->txGalleryFolder = $txGalleryFolder;
}


}
126 changes: 126 additions & 0 deletions Classes/Resources/Service/UserFileMountService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php

namespace GeorgRinger\NewsGallery\Resource\Service;

/**
* This file is part of the "news_gallery" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageService;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\StorageRepository;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Service class for implementing the user filemounts,
* used for BE_USER (\TYPO3\CMS\Core\Authentication\BackendUserAuthentication)
* and TCEforms hooks
*
* Note: This is now also used by sys_file_category table (fieldname "folder")!
*/
class UserFileMountService
{
/**
* User function for sys_filemounts (the userfilemounts)
* to render a dropdown for selecting a folder
* of a selected mount
*
* @param array $PA the array with additional configuration options.
* @return string The HTML code for the TCEform field
*/
public function renderTceformsSelectDropdown(&$PA)
{
// If working for sys_filemounts table
$storageUid = (int)$PA['row']['base'][0];
if (!$storageUid) {
// If working for sys_file_collection table
$storageUid = (int)$PA['row']['tx_gallery_storage'][0];
}

if ($storageUid > 0) {
/** @var $storageRepository StorageRepository */
$storageRepository = GeneralUtility::makeInstance(StorageRepository::class);
/** @var $storage \TYPO3\CMS\Core\Resource\ResourceStorage */
$storage = $storageRepository->findByUid($storageUid);
if ($storage === null) {
/** @var FlashMessageService $flashMessageService */
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$queue = $flashMessageService->getMessageQueueByIdentifier();
$queue->enqueue(new FlashMessage('Storage #' . $storageUid . ' does not exist. No folder is currently selectable.', '', FlashMessage::ERROR));
if (empty($PA['items'])) {
$PA['items'][] = [
$PA['row'][$PA['field']],
$PA['row'][$PA['field']]
];
}
} elseif ($storage->isBrowsable()) {
$rootLevelFolders = [];

$fileMounts = $storage->getFileMounts();
if (!empty($fileMounts)) {
foreach ($fileMounts as $fileMountInfo) {
$rootLevelFolders[] = $fileMountInfo['folder'];
}
} else {
$rootLevelFolders[] = $storage->getRootLevelFolder();
}

foreach ($rootLevelFolders as $rootLevelFolder) {
$folderItems = $this->getSubfoldersForOptionList($rootLevelFolder);
foreach ($folderItems as $item) {
$PA['items'][] = [
$item->getIdentifier(),
$item->getIdentifier()
];
}
}
} else {
/** @var FlashMessageService $flashMessageService */
$flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
$queue = $flashMessageService->getMessageQueueByIdentifier();
$queue->enqueue(new FlashMessage('Storage "' . $storage->getName() . '" is not browsable. No folder is currently selectable.', '', FlashMessage::WARNING));
if (empty($PA['items'])) {
$PA['items'][] = [
$PA['row'][$PA['field']],
$PA['row'][$PA['field']]
];
}
}
} else {
$PA['items'][] = ['', 'Please choose a FAL mount from above first.'];
}
}

/**
* Simple function to make a hierarchical subfolder request into
* a "flat" option list
*
* @param Folder $parentFolder
* @param int $level a limiter
* @return Folder[]
*/
protected function getSubfoldersForOptionList(Folder $parentFolder, $level = 0)
{
$level++;
// hard break on recursion
if ($level > 99) {
return [];
}
$allFolderItems = [$parentFolder];
$subFolders = $parentFolder->getSubfolders();
foreach ($subFolders as $subFolder) {
try {
$subFolderItems = $this->getSubfoldersForOptionList($subFolder, $level);
} catch (InsufficientFolderReadPermissionsException $e) {
$subFolderItems = [];
}
$allFolderItems = array_merge($allFolderItems, $subFolderItems);
}
return $allFolderItems;
}
}
83 changes: 83 additions & 0 deletions Classes/ViewHelpers/RenderViewHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace GeorgRinger\NewsGallery\ViewHelpers;

/**
* This file is part of the "news_gallery" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3\CMS\Fluid\Core\ViewHelper\Facets\CompilableInterface;
use TYPO3\CMS\Frontend\Resource\FileCollector;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;

/**
* Render galleries
*/
class RenderViewHelper extends AbstractViewHelper implements CompilableInterface
{

use CompileWithRenderStatic;

/** @var bool */
protected $escapeOutput = false;

/**
* Initialize required arguments
*/
public function initializeArguments()
{
$this->registerArgument('as', 'string', 'Output variable', true);
$this->registerArgument('folder', 'string', 'Folder');
$this->registerArgument('storage', 'string', 'Storage');
$this->registerArgument('collections', 'string', 'List of collections');
}

/**
* Output media items
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$fileCollector = GeneralUtility::makeInstance(FileCollector::class);

// collections
if (!empty($arguments['collections'])) {
$collections = GeneralUtility::intExplode(',', $arguments['collections'], TRUE);
if (!empty($collections)) {
$fileCollector->addFilesFromFileCollections($collections);
}
}

// folders
if (!empty($arguments['folder']) && !empty($arguments['storage'])) {
$identifier = $arguments['storage'] . ':' . $arguments['folder'];
$fileCollector->addFilesFromFolder($identifier);
}

$files = $fileCollector->getFiles();
$as = $arguments['as'];

if (VersionNumberUtility::convertVersionNumberToInteger(TYPO3_branch) >= VersionNumberUtility::convertVersionNumberToInteger('9.0')) {
$renderingContext->getVariableProvider()->add($as, $files);
$output = $renderChildrenClosure();
$renderingContext->getVariableProvider()->remove($as);
} else {
$renderingContext->getTemplateVariableContainer()->templateVariableContainer->add($as, $files);
$output = $renderChildrenClosure();
$renderingContext->getTemplateVariableContainer()->templateVariableContainer->remove($as);
}

return $output;
}
}
61 changes: 61 additions & 0 deletions Configuration/TCA/Overrides/tx_news_domain_model_news.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}

$columns = [
'tx_gallery_collections' => [
'exclude' => true,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_collection',
'config' => [
'type' => 'group',
'internal_type' => 'db',
'localizeReferencesAtParentLocalization' => true,
'allowed' => 'sys_file_collection',
'foreign_table' => 'sys_file_collection',
'maxitems' => 10,
'minitems' => 0,
'size' => 2,
'wizards' => [
'suggest' => [
'type' => 'suggest',
'default' => [
'searchWholePhrase' => true,
'addWhere' => ' AND tx_news_domain_model_news.uid != ###THIS_UID###'
]
],
],
]
],
'tx_gallery_storage' => [
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_collection.storage',
'onChange' => 'reload',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [
['', 0]
],
'foreign_table' => 'sys_file_storage',
'foreign_table_where' => 'ORDER BY sys_file_storage.name',
'size' => 1,
'minitems' => 0,
'maxitems' => 1
]
],
'tx_gallery_folder' => [
'exclude' => true,
'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_tca.xlf:sys_file_collection.folder',
'config' => [
'type' => 'select',
'renderType' => 'selectSingle',
'items' => [],
'itemsProcFunc' => \GeorgRinger\NewsGallery\Resource\Service\UserFileMountService::class . '->renderTceformsSelectDropdown',
'default' => '',
]
],
];

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tx_news_domain_model_news', $columns);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('tx_news_domain_model_news', 'tx_gallery_collections,tx_gallery_storage,tx_gallery_folder', '', 'after:fal_media');
Binary file added Documentation/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 28587cc

Please sign in to comment.