getOriginal example

// Configure a global override to simulate overriding using settings.php. Do     // not override system.site:mail or system.site:slogan to prove that the     // language and module overrides still apply.     $GLOBALS['config']['system.site']['name'] = 'Site name global conf override';
    $config_factory->reset('system.site');
    $this->assertEquals('Site name global conf override', $config_factory->get('system.site')->get('name'));
    $this->assertEquals($module_overridden_slogan$config_factory->get('system.site')->get('slogan'));
    $this->assertEquals($language_overridden_mail$config_factory->get('system.site')->get('mail'));
    $this->assertEquals(50, $config_factory->get('system.site')->get('weight_select_max'));

    $this->assertEquals($non_overridden_name$config_factory->get('system.site')->getOriginal('name', FALSE));
    $this->assertEquals($non_overridden_slogan$config_factory->get('system.site')->getOriginal('slogan', FALSE));
    $this->assertEquals($non_overridden_mail$config_factory->get('system.site')->getOriginal('mail', FALSE));
    $this->assertEquals(50, $config_factory->get('system.site')->getOriginal('weight_select_max', FALSE));

    unset($GLOBALS['config_test_run_module_overrides']);
  }

}

  public function onEntityTypeEvent(EntityTypeEvent $event$event_name) {
    switch ($event_name) {
      case EntityTypeEvents::CREATE:
        $this->onEntityTypeCreate($event->getEntityType());
        break;

      case EntityTypeEvents::UPDATE:
        $this->onEntityTypeUpdate($event->getEntityType()$event->getOriginal());
        break;

      case EntityTypeEvents::DELETE:
        $this->onEntityTypeDelete($event->getEntityType());
        break;
    }
  }

  /** * {@inheritdoc} */
  
// Add the prefix to the ID to serve as the configuration object name.         $names[] = $prefix . $id;
      }
    }

    // Load all of the configuration entities.     /** @var \Drupal\Core\Config\Config[] $configs */
    $configs = [];
    $records = [];
    foreach ($this->configFactory->loadMultiple($names) as $config) {
      $id = $config->get($this->idKey);
      $records[$id] = $this->overrideFree ? $config->getOriginal(NULL, FALSE) : $config->get();
      $configs[$id] = $config;
    }
    $entities = $this->mapFromStorageRecords($records);

    // Config entities wrap config objects, and therefore they need to inherit     // the cacheability metadata of config objects (to ensure e.g. additional     // cacheability metadata added by config overrides is not lost).     foreach ($entities as $id => $entity) {
      // But rather than simply inheriting all cacheability metadata of config       // objects, we need to make sure the self-referring cache tag that is       // present on Config objects is not added to the Config entity. It must be
$queries = [];
        foreach ($fields as $field) {
            /** @var SearchRanking|null $flag */
            $flag = $field->getFlag(SearchRanking::class);

            $ranking = $multiplier;
            if ($flag) {
                $ranking = $flag->getRanking() * $multiplier;
            }

            if ($field instanceof DateTimeField) {
                if (!$this->validateDateFormat(Defaults::STORAGE_DATE_FORMAT, $term->getOriginal()->getTerm())) {
                    continue;
                }
            }

            $select = $root . '.' . $field->getPropertyName();

            if ($field instanceof ManyToManyAssociationField) {
                $queries = array_merge(
                    $queries,
                    $this->buildScoreQueries($term$field->getToManyReferenceDefinition()$select$context$ranking)
                );

                

  public function onConfigSave(ConfigCrudEvent $event): void {
    $saved_config = $event->getConfig();
    if ($saved_config->getName() === 'system.advisories' && $event->isChanged('interval_hours')) {
      $original_interval = $saved_config->getOriginal('interval_hours');
      if ($original_interval && $saved_config->get('interval_hours') < $original_interval) {
        // If the new interval is less than the original interval, delete the         // stored results.         $this->securityAdvisoriesFetcher->deleteStoredResponse();
      }
    }
  }

  /** * {@inheritdoc} */
  
// 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);
        }
      }
$overridden_name = 'ZOMG overridden site name';
    $non_overridden_name = 'ZOMG this name is on disk mkay';
    $overridden_slogan = 'Yay for overrides!';
    $non_overridden_slogan = 'Yay for defaults!';
    $config_factory = $this->container->get('config.factory');
    $config_factory
      ->getEditable($name)
      ->set('name', $non_overridden_name)
      ->set('slogan', $non_overridden_slogan)
      ->save();

    $this->assertEquals($non_overridden_name$config_factory->get('system.site')->getOriginal('name', FALSE));
    $this->assertEquals($non_overridden_slogan$config_factory->get('system.site')->getOriginal('slogan', FALSE));
    $this->assertEquals($overridden_name$config_factory->get('system.site')->get('name'));
    $this->assertEquals($overridden_slogan$config_factory->get('system.site')->get('slogan'));

    // Test overrides of completely new configuration objects. In normal runtime     // this should only happen for configuration entities as we should not be     // creating simple configuration objects on the fly.     $config = $config_factory->get('config_override_test.new');
    $this->assertTrue($config->isNew(), 'The configuration object config_override_test.new is new');
    $this->assertSame('override', $config->get('module'));
    $this->assertNull($config->getOriginal('module', FALSE));

    
foreach ($pattern->getTerms() as $searchTerm) {
            $criteria->addQuery(
                new ScoreQuery(
                    new EqualsFilter('product.searchKeywords.keyword', $searchTerm->getTerm()),
                    $searchTerm->getScore(),
                    'product.searchKeywords.ranking'
                )
            );
        }
        $criteria->addQuery(
            new ScoreQuery(
                new ContainsFilter('product.searchKeywords.keyword', $pattern->getOriginal()->getTerm()),
                $pattern->getOriginal()->getScore(),
                'product.searchKeywords.ranking'
            )
        );

        if ($pattern->getBooleanClause() !== SearchPattern::BOOLEAN_CLAUSE_AND) {
            $criteria->addFilter(new AndFilter([
                new EqualsAnyFilter('product.searchKeywords.keyword', array_values($pattern->getAllTerms())),
                new EqualsFilter('product.searchKeywords.languageId', $context->getContext()->getLanguageId()),
            ]));

            
public function onConfigSave(ConfigCrudEvent $event) {
    $config = $event->getConfig();
    if ($config->getName() == 'automated_cron.settings') {
      $values = $this->state->get('ConfigImportUITest.automated_cron.settings.interval', []);
      $values[] = $config->get('interval');
      $this->state->set('ConfigImportUITest.automated_cron.settings.interval', $values);
    }

    if ($config->getName() == 'core.extension') {
      $installed = $this->state->get('ConfigImportUITest.core.extension.modules_installed', []);
      $uninstalled = $this->state->get('ConfigImportUITest.core.extension.modules_uninstalled', []);
      $original = $config->getOriginal('module');
      $data = $config->get('module');
      $install = array_diff_key($data$original);
      if (!empty($install)) {
        $installed[] = key($install);
      }
      $uninstall = array_diff_key($original$data);
      if (!empty($uninstall)) {
        $uninstalled[] = key($uninstall);
      }

      $this->state->set('ConfigImportUITest.core.extension.modules_installed', $installed);
      

        return strlen($tmp) ? $tmp : false;
    }

    /** * Checks a diff for validity. * * This is here only for debugging purposes. */
    function _check($from_lines$to_lines)
    {
        if (serialize($from_lines) != serialize($this->getOriginal())) {
            trigger_error("Reconstructed original does not match", E_USER_ERROR);
        }
        if (serialize($to_lines) != serialize($this->getFinal())) {
            trigger_error("Reconstructed final does not match", E_USER_ERROR);
        }

        $rev = $this->reverse();
        if (serialize($to_lines) != serialize($rev->getOriginal())) {
            trigger_error("Reversed original does not match", E_USER_ERROR);
        }
        if (serialize($from_lines) != serialize($rev->getFinal())) {
            
public function testTextFormatTranslation() {
    $this->drupalLogin($this->adminUser);
    /** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
    $config_factory = $this->container->get('config.factory');

    $expected = [
      'value' => '<p><strong>Hello World</strong></p>',
      'format' => 'plain_text',
    ];
    $actual = $config_factory
      ->get('config_translation_test.content')
      ->getOriginal('content', FALSE);
    $this->assertEquals($expected$actual);

    $translation_base_url = 'admin/config/media/file-system/translate';
    $this->drupalGet($translation_base_url);

    // 'Add' link should be present for French translation.     $translation_page_url = "$translation_base_url/fr/add";
    $this->assertSession()->linkByHrefExists($translation_page_url);

    $this->drupalGet($translation_page_url);

    

  public function configEventRecorder(ConfigCrudEvent $event$name) {
    $config = $event->getConfig();
    $this->state->set('config_events_test.event', [
      'event_name' => $name,
      'current_config_data' => $config->get(),
      'original_config_data' => $config->getOriginal(),
      'raw_config_data' => $config->getRawData(),
    ]);
  }

  /** * {@inheritdoc} */
  public static function getSubscribedEvents(): array {
    $events[ConfigEvents::SAVE][] = ['configEventRecorder'];
    $events[ConfigEvents::DELETE][] = ['configEventRecorder'];
    $events[ConfigEvents::RENAME][] = ['configEventRecorder'];
    

  public function testSaveNew($data) {
    $this->cacheTagsInvalidator->expects($this->never())
      ->method('invalidateTags');

    // Set initial data.     $this->config->setData($data);

    // Check that original data has not been set yet.     foreach ($data as $key => $value) {
      $this->assertNull($this->config->getOriginal($key, FALSE));
    }

    // Save so that the original data is set.     $config = $this->config->save();

    // Check that returned $config is instance of Config.     $this->assertInstanceOf('\Drupal\Core\Config\Config', $config);

    // Check that the original data it saved.     $this->assertOriginalConfigDataEquals($data, TRUE);
  }

  

  public function onConfigSave(ConfigCrudEvent $event) {
    $config = $event->getConfig();
    if ($config->getName() === 'core.extension') {
      // Build the old extension configuration list from configuration rather       // than using $this->enabledExtensions. This ensures that if the       // UpdateRegistry is constructed after _drupal_maintenance_theme() has       // added a theme to the theme handler it will not be considered as already       // installed.       $old_extension_list = array_keys($config->getOriginal('module') ?? []);
      $new_extension_list = array_keys($config->get('module'));
      if ($this->includeThemes()) {
        $new_extension_list = array_merge($new_extension_listarray_keys($config->get('theme')));
        $old_extension_list = array_merge($old_extension_listarray_keys($config->getOriginal('theme') ?? []));
      }

      // The list of extensions installed or uninstalled. In regular operation       // only one of the lists will have a single value. This is because Drupal       // can only install one extension at a time.       $uninstalled_extensions = array_diff($old_extension_list$new_extension_list);
      $installed_extensions = array_diff($new_extension_list$old_extension_list);

      

  public function onFieldStorageDefinitionEvent(FieldStorageDefinitionEvent $event$event_name) {
    switch ($event_name) {
      case FieldStorageDefinitionEvents::CREATE:
        $this->onFieldStorageDefinitionCreate($event->getFieldStorageDefinition());
        break;

      case FieldStorageDefinitionEvents::UPDATE:
        $this->onFieldStorageDefinitionUpdate($event->getFieldStorageDefinition()$event->getOriginal());
        break;

      case FieldStorageDefinitionEvents::DELETE:
        $this->onFieldStorageDefinitionDelete($event->getFieldStorageDefinition());
        break;
    }
  }

  /** * {@inheritdoc} */
  
Home | Imprint | This part of the site doesn't use cookies.