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

[TASK] Cleanups in FalViewHelper #962

Merged
merged 2 commits into from
Dec 14, 2015
Merged
Changes from 1 commit
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
45 changes: 21 additions & 24 deletions Classes/ViewHelpers/Resource/Record/FalViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

use FluidTYPO3\Vhs\Utility\ResourceUtility;
use TYPO3\CMS\Core\Resource\FileReference;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\DatabaseConnection;
Expand Down Expand Up @@ -62,8 +63,8 @@ public function __construct() {
}

/**
* @param mixed $identity
* @return mixed
* @param FileReference $fileReference
* @return array
*/
public function getResource($fileReference) {
$file = $fileReference->getOriginalFile();
Expand All @@ -74,11 +75,11 @@ public function getResource($fileReference) {
}

/**
* Fetch a fileRefernce from the file repository
* Fetch a fileReference from the file repository
*
* @param $table name of the table to get the file reference for
* @param $field name of the field referencing a file
* @param $uid uid of the related record
* @param string $table name of the table to get the file reference for
* @param string $field name of the field referencing a file
* @param int $uid uid of the related record
Copy link
Member

Choose a reason for hiding this comment

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

Please use integer here - everything else looks good!

* @return array
*/
protected function getFileReferences($table, $field, $uid) {
Expand All @@ -91,19 +92,15 @@ protected function getFileReferences($table, $field, $uid) {
* @return array
*/
public function getResources($record) {
/** @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer $contentObj */
$contentObjectRenderer = $this->configurationManager->getContentObject();

/** @var \TYPO3\CMS\Core\Database\DatabaseConnection $databaseConnection */
$databaseConnection = $this->getDatabaseConntection();

if (isset($record['t3ver_oid']) && (integer) $record['t3ver_oid'] !== 0) {
$sqlRecordUid = $record['t3ver_oid'];
} else {
$sqlRecordUid = $record[$this->idField];
}

if (FALSE === empty($GLOBALS['TSFE']->sys_page)) {
$images = array();
if (empty($GLOBALS['TSFE']->sys_page) === FALSE) {
$images = $this->getFileReferences($this->getTable(), $this->getField(), $sqlRecordUid);
} else {
if ($GLOBALS['BE_USER']->workspaceRec['uid']) {
Expand All @@ -123,19 +120,19 @@ public function getResources($record) {
'',
'uid'
);
if (FALSE === empty($references)) {
if (empty($references) === FALSE) {
$referenceUids = array_keys($references);
}
$images = array();
if (FALSE === empty($referenceUids)) {
foreach ($referenceUids as $referenceUid) {
try {
// Just passing the reference uid, the factory is doing workspace
// overlays automatically depending on the current environment
$images[] = $this->resourceFactory->getFileReferenceObject($referenceUid);
} catch (ResourceDoesNotExistException $exception) {
// No handling, just omit the invalid reference uid
continue;
$images = array();
Copy link
Member

Choose a reason for hiding this comment

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

Moving declaration of $images in here may cause the variable to be undefined (or at least not an array) which would cause the final loop to break with a fatal PHP error. It should be okay to move the declaration outside of the condition so it always gets initialised but only filled if referenceUids is not empty. Sorry, missed the declaration above. Code should execute just fine, despite the slightly confusing reuse of $images variable which was there before you got here :)

if (empty($referenceUids) === FALSE) {
foreach ($referenceUids as $referenceUid) {
try {
// Just passing the reference uid, the factory is doing workspace
// overlays automatically depending on the current environment
$images[] = $this->resourceFactory->getFileReferenceObject($referenceUid);
} catch (ResourceDoesNotExistException $exception) {
// No handling, just omit the invalid reference uid
continue;
}
}
}
}
Expand Down