Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
MediaAttribute example
public
function
create
(
array
$params
)
{
$this
->
checkPrivilege
(
'create'
)
;
$params
=
$this
->
prepareMediaData
(
$params
)
;
$media
=
new
MediaModel
(
)
;
$media
->
fromArray
(
$params
)
;
$attribute
=
new
MediaAttribute
(
)
;
if
(
isset
(
$params
[
'attribute'
]
)
&& \
is_array
(
$params
[
'attribute'
]
)
)
{
$attribute
->
fromArray
(
$params
[
'attribute'
]
)
;
}
$media
->
setAttribute
(
$attribute
)
;
$path
=
$this
->
prepareFilePath
(
$media
->
getPath
(
)
,
$media
->
getFileName
(
)
)
;
$media
->
setPath
(
$path
)
;
$violations
=
$this
->
getManager
(
)
->
validate
(
$media
)
;
if
(
$violations
->
count
(
)
> 0
)
{