本文整理汇总了PHP中Drupal\Core\Config\ConfigFactoryInterface::rename方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigFactoryInterface::rename方法的具体用法?PHP ConfigFactoryInterface::rename怎么用?PHP ConfigFactoryInterface::rename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Config\ConfigFactoryInterface
的用法示例。
在下文中一共展示了ConfigFactoryInterface::rename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, EntityInterface $entity)
{
$is_new = $entity->isNew();
$prefix = $this->getPrefix();
$config_name = $prefix . $entity->id();
if ($id !== $entity->id()) {
// Renaming a config object needs to cater for:
// - Storage needs to access the original object.
// - The object needs to be renamed/copied in ConfigFactory and reloaded.
// - All instances of the object need to be renamed.
$this->configFactory->rename($prefix . $id, $config_name);
}
$config = $this->configFactory->getEditable($config_name);
// Retrieve the desired properties and set them in config.
$config->setData($this->mapToStorageRecord($entity));
$config->save($entity->hasTrustedData());
// Update the entity with the values stored in configuration. It is possible
// that configuration schema has casted some of the values.
if (!$entity->hasTrustedData()) {
$data = $this->mapFromStorageRecords(array($config->get()));
$updated_entity = current($data);
foreach (array_keys($config->get()) as $property) {
$value = $updated_entity->get($property);
$entity->set($property, $value);
}
}
return $is_new ? SAVED_NEW : SAVED_UPDATED;
}
示例2: doSave
/**
* {@inheritdoc}
*/
protected function doSave($id, EntityInterface $entity)
{
$is_new = $entity->isNew();
$prefix = $this->getPrefix();
if ($id !== $entity->id()) {
// Renaming a config object needs to cater for:
// - Storage needs to access the original object.
// - The object needs to be renamed/copied in ConfigFactory and reloaded.
// - All instances of the object need to be renamed.
$config = $this->configFactory->rename($prefix . $id, $prefix . $entity->id());
} else {
$config = $this->configFactory->get($prefix . $id);
}
// Retrieve the desired properties and set them in config.
$config->setData($this->mapToStorageRecord($entity));
$config->save();
return $is_new ? SAVED_NEW : SAVED_UPDATED;
}