Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
updateEntityProperty example
throw
new
\
LogicException
(
'The "property" property is required'
)
;
}
if
(
!
$row
->
hasDestinationProperty
(
'translation'
)
)
{
throw
new
\
LogicException
(
'The "translation" property is required'
)
;
}
$config_override
=
$this
->languageManager->
getLanguageConfigOverride
(
$row
->
getDestinationProperty
(
'langcode'
)
,
$config
)
;
$config_override
->
set
(
str_replace
(
Row::PROPERTY_SEPARATOR, '.',
$row
->
getDestinationProperty
(
'property'
)
)
,
$row
->
getDestinationProperty
(
'translation'
)
)
;
$config_override
->
save
(
)
;
}
else
{
foreach
(
$row
->
getRawDestination
(
)
as
$property
=>
$value
)
{
$this
->
updateEntityProperty
(
$entity
,
explode
(
Row::PROPERTY_SEPARATOR,
$property
)
,
$value
)
;
}
$this
->
setRollbackAction
(
$row
->
getIdMap
(
)
)
;
}
}
/** * Updates a (possible nested) entity property with a value. * * @param \Drupal\Core\Entity\EntityInterface $entity * The config entity. * @param array $parents * The array of parents. * @param string|object $value * The value to update to. */
class
EntityDateFormat
extends
EntityConfigBase
{
/** * {@inheritdoc} */
protected
function
updateEntityProperty
(
EntityInterface
$entity
, array
$parents
,
$value
)
{
assert
(
$entity
instanceof DateFormatInterface
)
;
if
(
$parents
[
0
]
== 'pattern'
)
{
$entity
->
setPattern
(
$value
)
;
}
else
{
parent::
updateEntityProperty
(
$entity
,
$parents
,
$value
)
;
}
}
}