當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ConfigFactoryInterface::rename方法代碼示例

本文整理匯總了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;
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:31,代碼來源:ConfigEntityStorage.php

示例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;
 }
開發者ID:anyforsoft,項目名稱:csua_d8,代碼行數:21,代碼來源:ConfigEntityStorage.php


注:本文中的Drupal\Core\Config\ConfigFactoryInterface::rename方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。