当前位置: 首页>>代码示例>>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;未经允许,请勿转载。