本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityInterface::set方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityInterface::set方法的具体用法?PHP ContentEntityInterface::set怎么用?PHP ContentEntityInterface::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\ContentEntityInterface
的用法示例。
在下文中一共展示了ContentEntityInterface::set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transferFieldValues
/**
* Transfer field values from update to entity to be updated.
*
* Because different fields may be on different bundles
* not all fields will be transferred to all entities.
*
* @param $update
* @param $entity_to_update
*/
protected function transferFieldValues(ScheduledUpdateInterface $update, ContentEntityInterface $entity_to_update) {
$field_map = $this->scheduled_update_type->getFieldMap();
foreach ($field_map as $from_field => $to_field) {
if ($to_field) {
if ($entity_to_update->hasField($to_field) && $update->hasField($from_field)) {
$new_value = $update->get($from_field)->getValue();
// @todo if $new_value is empty. Check to see if the field is required on the target?
// If it is require don't update value because this cause a fatal at least on base fields.
if (isset($new_value)) {
$entity_to_update->set($to_field, $new_value);
}
}
}
}
}