Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
N
naderio_vhs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
4
Snippets
Groups
Projects
Show more breadcrumbs
Naderio-Official
typo3-ext
naderio_vhs
Commits
faf0555d
Commit
faf0555d
authored
4 years ago
by
Thomas Anders
Browse files
Options
Downloads
Patches
Plain Diff
Added get.fileReferences ViewHelper
parent
aece5f53
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/ViewHelpers/Get/FileReferencesViewHelper.php
+61
-0
61 additions, 0 deletions
Classes/ViewHelpers/Get/FileReferencesViewHelper.php
with
61 additions
and
0 deletions
Classes/ViewHelpers/Get/FileReferencesViewHelper.php
0 → 100644
+
61
−
0
View file @
faf0555d
<?php
namespace
Naderio\NaderioVhs\ViewHelpers\Get
;
use
TYPO3\CMS\Core\Resource\FileRepository
;
use
TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper
;
use
function
count
;
/**
* Get related Fal Objects
* Returns an [array] when [$multiple = true](default)
* or only the first reference is found directly as [FileReference] when [$multiple = false].
*/
class
FileReferencesViewHelper
extends
AbstractViewHelper
{
protected
FileRepository
$fileRepository
;
public
function
__construct
(
FileRepository
$fileRepository
)
{
$this
->
fileRepository
=
$fileRepository
;
}
public
function
initializeArguments
():
void
{
$this
->
registerArgument
(
'table'
,
'string'
,
'Tablename (e.g. tt_content)'
,
true
);
$this
->
registerArgument
(
'contentUid'
,
'int'
,
'Uid of the element with attached FileReferences'
,
true
);
$this
->
registerArgument
(
'field'
,
'string'
,
'Fieldname of the FileReference (e.g. images or file)'
,
true
);
$this
->
registerArgument
(
'multiple'
,
'string'
,
'Returns all FileReferences by default or only the first, if set to [false]'
,
false
,
true
);
}
/**
* @return array|false
*/
public
function
render
()
{
$relatedFileReferences
=
$this
->
fileRepository
->
findByRelation
(
$this
->
arguments
[
'table'
],
$this
->
arguments
[
'field'
],
$this
->
arguments
[
'contentUid'
]
);
if
(
!
count
(
$relatedFileReferences
))
{
return
false
;
}
if
(
count
(
$relatedFileReferences
)
>
0
)
{
if
(
$this
->
arguments
[
'multiple'
]
===
false
)
{
return
$relatedFileReferences
[
0
];
}
return
$relatedFileReferences
;
}
return
false
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment