本文整理汇总了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));
}
}
示例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.");
}
}
}
示例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']);
}
示例4: preSave
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage, $update = TRUE)
{
ksort($this->content);
ksort($this->hidden);
parent::preSave($storage, $update);
}
示例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();
}
示例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);
}
示例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());
}
示例8: preSave
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage)
{
parent::preSave($storage);
\Drupal::entityManager()->clearCachedFieldDefinitions();
}
示例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();
}
示例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;
}
}
示例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();
}
}
}
示例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();
}
});
}
示例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']);
}
示例14: preSave
/**
* {@inheritdoc}
*/
public function preSave(EntityStorageInterface $storage)
{
parent::preSave($storage);
$this->filterParameters();
}
示例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);
}