本文整理汇总了PHP中Drupal\Core\Entity\EntityStorageInterface::save方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityStorageInterface::save方法的具体用法?PHP EntityStorageInterface::save怎么用?PHP EntityStorageInterface::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityStorageInterface
的用法示例。
在下文中一共展示了EntityStorageInterface::save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@inheritdoc}
*/
public function process(FeedInterface $feed, ItemInterface $item, StateInterface $state)
{
$existing_entity_id = $this->existingEntityId($feed, $item);
$skip_existing = $this->configuration['update_existing'] == static::SKIP_EXISTING;
// Bulk load existing entities to save on db queries.
if ($skip_existing && $existing_entity_id) {
return;
}
// Delay building a new entity until necessary.
if ($existing_entity_id) {
$entity = $this->storageController->load($existing_entity_id);
}
$hash = $this->hash($item);
$changed = $existing_entity_id && $hash !== $entity->get('feeds_item')->hash;
// Do not proceed if the item exists, has not changed, and we're not
// forcing the update.
if ($existing_entity_id && !$changed && !$this->configuration['skip_hash_check']) {
return;
}
// Build a new entity.
if (!$existing_entity_id) {
$entity = $this->newEntity($feed);
}
try {
// Set field values.
$this->map($feed, $entity, $item);
$this->entityValidate($entity);
// This will throw an exception on failure.
$this->entitySaveAccess($entity);
// Set the values that we absolutely need.
$entity->get('feeds_item')->target_id = $feed->id();
$entity->get('feeds_item')->hash = $hash;
$entity->get('feeds_item')->imported = REQUEST_TIME;
// And... Save! We made it.
$this->storageController->save($entity);
// Track progress.
$existing_entity_id ? $state->updated++ : $state->created++;
} catch (\Exception $e) {
$state->failed++;
$state->setMessage($e->getMessage(), 'warning');
}
}