本文整理匯總了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;
}