/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); $errors = $this->validate(); if (!empty($errors)) { throw new EncryptException(implode(';', $errors)); } }
/** * 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."); } } }
/** * @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']); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage, $update = TRUE) { ksort($this->content); ksort($this->hidden); parent::preSave($storage, $update); }
/** * {@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(); }
/** * 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); }
/** * {@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()); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); \Drupal::entityManager()->clearCachedFieldDefinitions(); }
/** * {@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(); }
/** * {@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; } }
/** * {@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(); } } }
/** * {@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(); } }); }
/** * {@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']); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); $this->filterParameters(); }
/** * {@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); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // @todo: Remove after implementing EntityWithPluginCollectionInterface. $this->set('configuration', $this->getPlugin()->getConfiguration()); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // If the server is being disabled, also disable all its indexes. if (!$this->status() && isset($this->original) && $this->original->status()) { foreach ($this->getIndexes(array('status' => TRUE)) as $index) { /** @var \Drupal\search_api\IndexInterface $index */ $index->setStatus(FALSE)->save(); } } }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // Stop enabling of indexes when the server is disabled. if ($this->status() && !$this->isServerEnabled()) { $this->disable(); } $this->applyLockedConfiguration(); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { $this->id = $this->id(); parent::preSave($storage); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // Sort the displays. $display = $this->get('display'); ksort($display); $this->set('display', array('default' => $display['default']) + $display); // @todo Check whether isSyncing is needed. if (!$this->isSyncing()) { $this->addCacheMetadata(); } }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // Store whether or not the site is already multilingual so that we can // rebuild services if necessary during // \Drupal\language\Entity\Language::postSave(). $this->preSaveMultilingual = \Drupal::languageManager()->isMultilingual(); // Languages are picked from a predefined list which is given in English. // For the uncommon case of custom languages the label should be given in // English. $this->langcode = 'en'; }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if ($this->isNew()) { $this->courierContextCC($this->entity_type, 'create'); } }
/** * {@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()); // @todo Do not save disabled filters whose properties are identical to // all default properties. }
/** * {@inheritdoc} */ public function preSave(EntityStorageControllerInterface $storage_controller) { parent::preSave($storage_controller); foreach ($this->getPlugins() as $type => $plugin) { // If this plugin has any configuration, ensure that it is set. if ($plugin instanceof ConfigurablePluginInterface) { $this->plugins[$type]['configuration'] = $plugin->getConfiguration(); } else { unset($this->plugins[$type]['configuration']); } } foreach ($this->targetPlugins as $delta => $target_plugin) { if ($target_plugin instanceof ConfigurableTargetInterface) { $this->mappings[$delta]['settings'] = $target_plugin->getConfiguration(); } else { unset($this->mappings[$delta]['settings']); } } $this->mappings = array_values($this->mappings); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if (!$this->isNew()) { foreach (array_keys($this->getLinks([], TRUE)) as $link_key) { $this->getMenuLinkManager()->removeDefinition($link_key, FALSE); } } }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // Prevent enabling of indexes when the server is disabled. if ($this->status() && !$this->isServerEnabled()) { $this->disable(); } // We first have to check for locked processors, otherwise their // preIndexSave() methods might not be called in the next step. $this->processor_settings = array(); foreach ($this->getProcessors(FALSE) as $processor_id => $processor) { if ($processor->isLocked() && !isset($this->processor_settings[$processor_id])) { $this->processor_settings[$processor_id] = array('plugin_id' => $processor_id, 'settings' => array()); } } foreach ($this->getProcessors() as $processor_id => $processor) { $this->processor_settings[$processor_id] = array('plugin_id' => $processor_id, 'settings' => $processor->getConfiguration()); } // Reset the canonical representation of the processors by running // ::getProcessors() again here after resetting them back to NULL. This is // only needed when creating a new Index. $this->processorInstances = NULL; $this->getProcessors(); // Add tracker settings. $tracker = $this->getTrackerInstance(); $tracker_id = $tracker->getPluginId(); $this->tracker_settings = array($tracker_id => array('plugin_id' => $tracker_id, 'settings' => $tracker->getConfiguration())); // Write the active datasources to the settings array. $this->datasource_settings = array(); foreach ($this->getDatasources() as $plugin_id => $datasource) { $this->datasource_settings[$plugin_id] = array('plugin_id' => $plugin_id, 'settings' => $datasource->getConfiguration()); } // Remove all "locked" and "hidden" flags from all fields of the index. If // they are still valid, they should be re-added by the processors. foreach ($this->getFields() as $field_id => $field) { $field->setIndexedLocked(FALSE); $field->setTypeLocked(FALSE); $field->setHidden(FALSE); } // Call the preIndexSave() method of all applicable processors. foreach ($this->getProcessorsByStage(ProcessorInterface::STAGE_PRE_INDEX_SAVE) as $processor) { $processor->preIndexSave(); } $this->field_settings = array(); foreach ($this->getFields() as $field_id => $field) { $this->field_settings[$field_id] = $field->getSettings(); } }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // Store whether or not the site is already multilingual so that we can // rebuild services if necessary during // \Drupal\language\Entity\ConfigurableLanguage::postSave(). $this->preSaveMultilingual = \Drupal::languageManager()->isMultilingual(); }
/** * {@inheritdoc} */ public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); // @todo Check whether isSyncing is needed. if (!$this->isSyncing()) { $this->addCacheMetadata(); } }