/** * Causes the container to be rebuilt on the next request. * * This event subscriber assumes that the new default langcode and old default * langcode are valid langcodes. If the schema definition of either * system.site:default_langcode or language.negotiation::url.prefixes changes * then this event must be changed to work with both the old and new schema * definition so this event is update safe. * * @param ConfigCrudEvent $event * The configuration event. */ public function onConfigSave(ConfigCrudEvent $event) { $saved_config = $event->getConfig(); if ($saved_config->getName() == 'system.site' && $event->isChanged('default_langcode')) { $new_default_langcode = $saved_config->get('default_langcode'); $default_language = $this->configFactory->get('language.entity.' . $new_default_langcode); // During an import the language might not exist yet. if (!$default_language->isNew()) { $this->languageDefault->set(new Language($default_language->get())); $this->languageManager->reset(); // Directly update language negotiation settings instead of calling // language_negotiation_url_prefixes_update() to ensure that the code // obeys the hook_update_N() restrictions. $negotiation_config = $this->configFactory->getEditable('language.negotiation'); $negotiation_changed = FALSE; $url_prefixes = $negotiation_config->get('url.prefixes'); $old_default_langcode = $saved_config->getOriginal('default_langcode'); if (empty($url_prefixes[$old_default_langcode])) { $negotiation_config->set('url.prefixes.' . $old_default_langcode, $old_default_langcode); $negotiation_changed = TRUE; } if (empty($url_prefixes[$new_default_langcode])) { $negotiation_config->set('url.prefixes.' . $new_default_langcode, ''); $negotiation_changed = TRUE; } if ($negotiation_changed) { $negotiation_config->save(TRUE); } } // Trigger a container rebuild on the next request by invalidating it. ConfigurableLanguageManager::rebuildServices(); } }
/** * Checks that configuration complies with its schema on config save. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. * * @throws \Drupal\Core\Config\Schema\SchemaIncompleteException * Exception thrown when configuration does not match its schema. */ public function onConfigSave(ConfigCrudEvent $event) { // Only validate configuration if in the default collection. Other // collections may have incomplete configuration (for example language // overrides only). These are not valid in themselves. $saved_config = $event->getConfig(); if ($saved_config->getStorage()->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) { return; } $name = $saved_config->getName(); $data = $saved_config->get(); $checksum = hash('crc32b', serialize($data)); $exceptions = array('config_schema_test.noschema', 'config_schema_test.someschema', 'config_schema_test.schema_data_types', 'config_schema_test.no_schema_data_types', 'config_test.dynamic.system'); if (!in_array($name, $exceptions) && !isset($this->checked[$name . ':' . $checksum])) { $this->checked[$name . ':' . $checksum] = TRUE; $errors = $this->checkConfigSchema($this->typedManager, $name, $data); if ($errors === FALSE) { throw new SchemaIncompleteException("No schema for {$name}"); } elseif (is_array($errors)) { $text_errors = []; foreach ($errors as $key => $error) { $text_errors[] = SafeMarkup::format('@key @error', array('@key' => $key, '@error' => $error)); } throw new SchemaIncompleteException("Schema errors for {$name} with the following errors: " . implode(', ', $text_errors)); } } }
/** * Rebuilds the router when the default or admin theme is changed. * * @param \Drupal\Core\Config\ConfigCrudEvent $event */ public function onConfigSave(ConfigCrudEvent $event) { $saved_config = $event->getConfig(); if ($saved_config->getName() == 'system.theme' && ($event->isChanged('admin') || $event->isChanged('default'))) { $this->routerBuilder->setRebuildNeeded(); } }
/** * Invalidate cache tags when a color theme config object changes. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The Event to process. */ public function onChange(ConfigCrudEvent $event) { // Changing a theme's color settings causes the theme's asset library // containing the color CSS file to be altered to use a different file. if (strpos($event->getConfig()->getName(), 'color.theme.') === 0) { $this->cacheTagsInvalidator->invalidateTags(['library_info']); } }
/** * Invalidate the 'rendered' cache tag whenever the settings are modified. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The Event to process. */ public function onSave(ConfigCrudEvent $event) { // Changing the Global Redirect settings means that any cached page might // result in a different response, so we need to invalidate them all. if ($event->getConfig()->getName() === 'globalredirect.settings') { $this->cacheTagsInvalidator->invalidateTags(['rendered']); } }
/** * Clearing the cached definitions whenever the settings are modified. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The Event to process. */ public function onSave(ConfigCrudEvent $event) { // Changing the Captcha settings means that any page might result in other // settings for captcha so the cached definitions need to be cleared. if ($event->getConfig()->getName() === 'captcha.settings') { \Drupal::service('element_info')->clearCachedDefinitions(); } }
/** * Causes the container to be rebuilt on the next request. * * @param ConfigCrudEvent $event * The configuration event. */ public function onConfigSave(ConfigCrudEvent $event) { $saved_config = $event->getConfig(); if ($saved_config->getName() == 'system.site' && $event->isChanged('langcode')) { // Trigger a container rebuild on the next request by deleting compiled // from PHP storage. PhpStorageFactory::get('service_container')->deleteAll(); } }
/** * Updates the locale strings when a translated active configuration is saved. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */ public function onConfigSave(ConfigCrudEvent $event) { // Only attempt to feed back configuration translation changes to locale if // the update itself was not initiated by locale data changes. if (!drupal_installation_attempted() && !$this->localeConfigManager->isUpdatingTranslationsFromLocale()) { $config = $event->getConfig(); $langcode = $config->get('langcode') ?: 'en'; $this->updateLocaleStorage($config, $langcode); } }
/** * Deletes files from the configured active config directory when a * ConfigEvents::DELETE event is dispatched. * * @param ConfigCrudEvent $event */ public function deleteConfig(ConfigCrudEvent $event) { $config = \Drupal::config('config_files.config'); $active_dir = $config->get('directory'); if ($active_dir) { $object = $event->getConfig(); $file_name = $object->getName() . '.yml'; unlink($active_dir . '/' . $file_name); } }
/** * Invalidate the 'rendered' cache tag whenever a theme setting is modified. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The Event to process. */ public function onSave(ConfigCrudEvent $event) { // Global theme settings. if ($event->getConfig()->getName() === 'system.theme.global') { $this->cacheTagsInvalidator->invalidateTags(['rendered']); } // Theme-specific settings, check if this matches a theme settings // configuration object, in that case, clear the rendered cache tag. foreach (array_keys($this->themeHandler->listInfo()) as $theme_name) { if ($theme_name == $event->getConfig()->getName()) { $this->cacheTagsInvalidator->invalidateTags(['rendered']); break; } } }
/** * Causes the container to be rebuilt on the next request. * * @param ConfigCrudEvent $event * The configuration event. */ public function onConfigSave(ConfigCrudEvent $event) { $saved_config = $event->getConfig(); if ($saved_config->getName() == 'system.site' && $event->isChanged('default_langcode')) { $language = $this->languageManager->getLanguage($saved_config->get('default_langcode')); // During an import the language might not exist yet. if ($language) { $this->languageDefault->set($language); $this->languageManager->reset(); language_negotiation_url_prefixes_update(); } // Trigger a container rebuild on the next request by invalidating it. ConfigurableLanguageManager::rebuildServices(); } }
/** * Causes the container to be rebuilt on the next request. * * @param ConfigCrudEvent $event * The configuration event. */ public function onConfigSave(ConfigCrudEvent $event) { $saved_config = $event->getConfig(); if ($saved_config->getName() == 'system.site' && $event->isChanged('langcode')) { $language = $this->languageManager->getLanguage($saved_config->get('langcode')); // During an import the language might not exist yet. if ($language) { $this->languageDefault->set($language); $this->languageManager->reset(); language_negotiation_url_prefixes_update(); } // Trigger a container rebuild on the next request by deleting compiled // from PHP storage. PhpStorageFactory::get('service_container')->deleteAll(); } }
/** * Reacts to a config delete and records information in state for testing. * * @param \Drupal\Core\Config\ConfigCrudEvent $event */ public function onConfigDelete(ConfigCrudEvent $event) { $config = $event->getConfig(); if ($config->getName() == 'action.settings') { $value = $this->state->get('ConfigImportUITest.action.settings.delete', 0); $this->state->set('ConfigImportUITest.action.settings.delete', $value + 1); } }
/** * Invalidate cache tags when particular system config objects are saved. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The Event to process. */ public function onSave(ConfigCrudEvent $event) { // Changing the site settings may mean a different route is selected for the // front page. Additionally a change to the site name or similar must // invalidate the render cache since this could be used anywhere. if ($event->getConfig()->getName() === 'system.site') { $this->cacheTagsInvalidator->invalidateTags(['route_match', 'rendered']); } // Theme configuration and global theme settings. if (in_array($event->getConfig()->getName(), ['system.theme', 'system.theme.global'], TRUE)) { $this->cacheTagsInvalidator->invalidateTags(['rendered']); } // Theme-specific settings, check if this matches a theme settings // configuration object, in that case, clear the rendered cache tag. foreach (array_keys($this->themeHandler->listInfo()) as $theme_name) { if ($theme_name == $event->getConfig()->getName()) { $this->cacheTagsInvalidator->invalidateTags(['rendered']); break; } } }
public function deleteConfig(ConfigCrudEvent $event) { $config = \Drupal::config('git_config.config'); $private_key = $config->get('private_key'); $git_url = $config->get('git_url'); $active_dir = \Drupal::config('config_files.config')->get('directory'); if ($active_dir && !empty($private_key) && !empty($git_url)) { $wrapper = new GitWrapper(); $wrapper->setPrivateKey($config->get('private_key')); $git = $wrapper->workingCopy($active_dir); $object = $event->getConfig(); $file_name = $object->getName() . '.yml'; try { $user = \Drupal::currentUser(); $name = $user->getAccount()->getUsername(); $git->rm($file_name)->commit(t('Removed by @name', array('@name' => $name)))->push(); } catch (GitException $e) { drupal_set_message($e->getMessage(), 'warning'); } } }
/** * Removes stale static cache entries when configuration is deleted. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */ public function onConfigDelete(ConfigCrudEvent $event) { // Ensure that the static cache does not contain deleted configuration. foreach ($this->getConfigCacheKeys($event->getConfig()->getName()) as $cache_key) { unset($this->cache[$cache_key]); } }
/** * Removes configuration entity from key store. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */ public function onConfigDelete(ConfigCrudEvent $event) { $saved_config = $event->getConfig(); $entity_type_id = $this->configManager->getEntityTypeIdByName($saved_config->getName()); if ($entity_type_id) { $entity_type = $this->configManager->getEntityManager()->getDefinition($entity_type_id); $this->deleteConfigKeyStore($entity_type, $saved_config); } }
/** * Removes stale static cache entries when configuration is saved. * * @param ConfigCrudEvent $event * The configuration event. */ public function onConfigSave(ConfigCrudEvent $event) { // Ensure that the static cache contains up to date configuration objects by // replacing the data on any entries for the configuration object apart // from the one that references the actual config object being saved. $saved_config = $event->getConfig(); foreach ($this->getConfigCacheKeys($saved_config->getName()) as $cache_key) { $cached_config = $this->cache[$cache_key]; if ($cached_config !== $saved_config) { $this->cache[$cache_key]->setData($saved_config->getRawData()); } } }
/** * React to configuration ConfigEvent::SAVE events. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The event to process. */ public function onConfigSave(ConfigCrudEvent $event) { $this->autoExportConfig($event->getConfig()); }
/** * {@inheritdoc} */ public function onConfigDelete(ConfigCrudEvent $event) { $config = $event->getConfig(); $name = $config->getName(); foreach (\Drupal::languageManager()->getLanguages() as $language) { $config_translation = $this->getOverride($language->getId(), $name); if (!$config_translation->isNew()) { $config_translation->delete(); } } }
/** * Invalidates the container when the definition settings are updated. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. */ public function onConfigSave(ConfigCrudEvent $event) { if ($event->getConfig()->getName() === 'libraries.settings' && $event->isChanged('definition')) { $this->kernel->invalidateContainer(); } }
/** * Reacts to config event. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The configuration event. * @param string $name * The event name. */ public function configEventRecorder(ConfigCrudEvent $event, $name) { $config = $event->getConfig(); $this->state->set('config_events_test.event', array('event_name' => $name, 'current_config_data' => $config->get(), 'original_config_data' => $config->getOriginal(), 'raw_config_data' => $config->getRawData())); }
/** * Invalidates the entity type definition cache whenever settings are changed. * * @param \Drupal\Core\Config\ConfigCrudEvent $event * The Event to process. */ public function onSave(ConfigCrudEvent $event) { if ($event->getConfig()->getName() === 'contact_storage.settings') { \Drupal::entityTypeManager()->clearCachedDefinitions(); } }