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


PHP ConfigEntityBase::preSave方法代碼示例

本文整理匯總了PHP中Drupal\Core\Config\Entity\ConfigEntityBase::preSave方法的典型用法代碼示例。如果您正苦於以下問題:PHP ConfigEntityBase::preSave方法的具體用法?PHP ConfigEntityBase::preSave怎麽用?PHP ConfigEntityBase::preSave使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Config\Entity\ConfigEntityBase的用法示例。


在下文中一共展示了ConfigEntityBase::preSave方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $errors = $this->validate();
     if (!empty($errors)) {
         throw new EncryptException(implode(';', $errors));
     }
 }
開發者ID:svendecabooter,項目名稱:encrypt,代碼行數:11,代碼來源:EncryptionProfile.php

示例2: preSave

 /**
  * Acts on an entity before the presave hook is invoked.
  *
  * Used before the entity is saved and before invoking the presave hook.
  *
  * Ensure that config entities which are bundles of other entities cannot have
  * their ID changed.
  *
  * @param \Drupal\Core\Entity\EntityStorageInterface $storage
  *   The entity storage object.
  *
  * @throws \Drupal\Core\Config\ConfigNameException
  *   Thrown when attempting to rename a bundle entity.
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Only handle renames, not creations.
     if (!$this->isNew() && $this->getOriginalId() !== $this->id()) {
         $bundle_type = $this->getEntityType();
         $bundle_of = $bundle_type->getBundleOf();
         if (!empty($bundle_of)) {
             throw new ConfigNameException("The machine name of the '{$bundle_type->getLabel()}' bundle cannot be changed.");
         }
     }
 }
開發者ID:isramv,項目名稱:camp-gdl,代碼行數:26,代碼來源:ConfigEntityBundleBase.php

示例3: testPreSaveDuringSync

 /**
  * @covers ::preSave
  */
 public function testPreSaveDuringSync()
 {
     $query = $this->getMock('\\Drupal\\Core\\Entity\\Query\\QueryInterface');
     $storage = $this->getMock('\\Drupal\\Core\\Config\\Entity\\ConfigEntityStorageInterface');
     $query->expects($this->any())->method('execute')->will($this->returnValue(array()));
     $query->expects($this->any())->method('condition')->will($this->returnValue($query));
     $storage->expects($this->any())->method('getQuery')->will($this->returnValue($query));
     $storage->expects($this->any())->method('loadUnchanged')->will($this->returnValue($this->entity));
     // Saving an entity will not reset the dependencies array during config
     // synchronization.
     $this->entity->set('dependencies', array('module' => array('node')));
     $this->entity->preSave($storage);
     $this->assertEmpty($this->entity->getDependencies());
     $this->entity->setSyncing(TRUE);
     $this->entity->set('dependencies', array('module' => array('node')));
     $this->entity->preSave($storage);
     $dependencies = $this->entity->getDependencies();
     $this->assertContains('node', $dependencies['module']);
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:22,代碼來源:ConfigEntityBaseUnitTest.php

示例4: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage, $update = TRUE)
 {
     ksort($this->content);
     ksort($this->hidden);
     parent::preSave($storage, $update);
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:9,代碼來源:EntityDisplayBase.php

示例5: preSave

 /**
  * {@inheritdoc}
  *
  * Not using core's default logic around ConditionPluginCollection since it
  * incorrectly assumes no condition will ever be applied twice.
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $criteria = [];
     foreach ($this->getSelectionConditions() as $id => $condition) {
         $criteria[$id] = $condition->getConfiguration();
     }
     $this->selection_criteria = $criteria;
     /** @var \Drupal\Core\Plugin\Context\ContextInterface[] $contexts */
     $contexts = $this->getContexts();
     foreach ($this->getAliasType()->getContexts() as $plugin_context_id => $plugin_context) {
         unset($contexts[$plugin_context_id]);
     }
     $this->context_definitions = [];
     foreach ($contexts as $context_id => $context) {
         $this->context_definitions[] = ['id' => $context_id, 'label' => $context->getContextDefinition()->getLabel()];
     }
     // Invalidate the static caches.
     \Drupal::service('pathauto.generator')->resetCaches();
 }
開發者ID:Wylbur,項目名稱:gj,代碼行數:26,代碼來源:PathautoPattern.php

示例6: preSave

 /**
  * Overrides \Drupal\Core\Entity\Entity::preSave().
  *
  * @throws \Drupal\Core\Field\FieldException
  *   If the field definition is invalid.
  * @throws \Drupal\Core\Entity\EntityStorageException
  *   In case of failures at the configuration storage level.
  */
 public function preSave(EntityStorageInterface $storage)
 {
     // Clear the derived data about the field.
     unset($this->schema);
     // Filter out unknown settings and make sure all settings are present, so
     // that a complete field definition is passed to the various hooks and
     // written to config.
     $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
     $default_settings = $field_type_manager->getDefaultStorageSettings($this->type);
     $this->settings = array_intersect_key($this->settings, $default_settings) + $default_settings;
     if ($this->isNew()) {
         $this->preSaveNew($storage);
     } else {
         $this->preSaveUpdated($storage);
     }
     parent::preSave($storage);
 }
開發者ID:nsp15,項目名稱:Drupal8,代碼行數:25,代碼來源:FieldStorageConfig.php

示例7: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     // Ensure the filters have been sorted before saving.
     $this->filters()->sort();
     parent::preSave($storage);
     $this->name = trim($this->label());
 }
開發者ID:anyforsoft,項目名稱:csua_d8,代碼行數:10,代碼來源:FilterFormat.php

示例8: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     \Drupal::entityManager()->clearCachedFieldDefinitions();
 }
開發者ID:nstielau,項目名稱:drops-8,代碼行數:8,代碼來源:EntityDisplayModeBase.php

示例9: preSave

 /**
  * {@inheritdoc}
  *
  * Not using core's default logic around ConditionPluginCollection since it
  * incorrectly assumes no condition will ever be applied twice.
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $criteria = [];
     foreach ($this->getSelectionConditions() as $id => $condition) {
         $criteria[$id] = $condition->getConfiguration();
     }
     $this->selection_criteria = $criteria;
     // Invalidate the static caches.
     \Drupal::service('pathauto.generator')->resetCaches();
 }
開發者ID:CIGIHub,項目名稱:bsia-drupal8,代碼行數:17,代碼來源:PathautoPattern.php

示例10: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     if (!isset($this->weight) && ($roles = $storage->loadMultiple())) {
         // Set a role weight to make this new role last.
         $max = array_reduce($roles, function ($max, $role) {
             return $max > $role->weight ? $max : $role->weight;
         });
         $this->weight = $max + 1;
     }
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:14,代碼來源:Role.php

示例11: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // The rest of the code only applies to updates.
     if (!isset($this->original)) {
         return;
     }
     $this->getBackend()->preUpdate();
     // If the server is being disabled, also disable all its indexes.
     if (!$this->status() && $this->original->status()) {
         foreach ($this->getIndexes(array('status' => TRUE)) as $index) {
             /** @var \Drupal\search_api\IndexInterface $index */
             $index->setStatus(FALSE)->save();
         }
     }
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:19,代碼來源:Server.php

示例12: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Convert route parameters that are entity IDs to UUIDs.
     $entity_manager = $this->entityManager();
     $this->processEntityRouteParameters($this, function ($entity_type_id, $value) use($entity_manager) {
         $entity = $entity_manager->getStorage($entity_type_id)->load($value);
         // Entity validation should have ensured that this entity in fact exists
         // but we try to avoid incomprehensible fatals at all costs.
         if ($entity instanceof EntityInterface) {
             return $entity->uuid();
         }
     });
 }
開發者ID:robertfoleyjr,項目名稱:robertfoleyjr-d8,代碼行數:17,代碼來源:MenuLinkConfig.php

示例13: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // Entity browser ID was added when creating. No need to save that as it can
     // always be calculated.
     foreach ($this->widgets as &$widget) {
         unset($widget['settings']['entity_browser_id']);
     }
     unset($this->selection_display_configuration['entity_browser_id']);
     unset($this->display_configuration['entity_browser_id']);
     unset($this->widget_selector_configuration['widget_ids']);
 }
開發者ID:DrupalTV,項目名稱:DrupalTV,代碼行數:15,代碼來源:EntityBrowser.php

示例14: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     $this->filterParameters();
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:8,代碼來源:Page.php

示例15: preSave

 /**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage, $update = TRUE)
 {
     // Sort elements by weight before saving.
     uasort($this->content, 'Drupal\\Component\\Utility\\SortArray::sortByWeightElement');
     parent::preSave($storage, $update);
 }
開發者ID:anatalsceo,項目名稱:en-classe,代碼行數:9,代碼來源:EntityDisplayBase.php


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