Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getMediaListQuery example
public
function
getOne
(
$id
)
{
$this
->
checkPrivilege
(
'read'
)
;
if
(
empty
(
$id
)
)
{
throw
new
ParameterMissingException
(
'id'
)
;
}
$filters
=
[
[
'property' => 'media.id', 'expression' => '=', 'value' =>
$id
]
]
;
$query
=
$this
->
getRepository
(
)
->
getMediaListQuery
(
$filters
,
[
]
, 1
)
;
/** @var MediaModel|array $media */
$media
=
$query
->
getOneOrNullResult
(
$this
->
getResultMode
(
)
)
;
if
(
!
$media
)
{
throw
new
NotFoundException
(
sprintf
(
'Media by id %d not found',
$id
)
)
;
}
$mediaService
=
Shopware
(
)
->
Container
(
)
->
get
(
MediaServiceInterface::
class
)
;
if
(
\
is_array
(
$media
)
)
{
$media
[
'path'
]
=
$mediaService
->
getUrl
(
$media
[
'path'
]
)
;
}