hasChanges example

$config = $this->config($config_name);
      $this->configExists = !$config->isNew() ? $config : FALSE;
    }

    // Use ConfigImporter validation.     if (!$form_state->getErrors()) {
      $source_storage = new StorageReplaceDataWrapper($this->configStorage);
      $source_storage->replaceData($config_name$data);
      $storage_comparer = new StorageComparer($source_storage$this->configStorage);

      $storage_comparer->createChangelist();
      if (!$storage_comparer->hasChanges()) {
        $form_state->setErrorByName('import', $this->t('There are no changes to import.'));
      }
      else {
        $config_importer = new ConfigImporter(
          $storage_comparer,
          $this->eventDispatcher,
          $this->configManager,
          $this->lock,
          $this->typedConfigManager,
          $this->moduleHandler,
          $this->moduleInstaller,
          
$sync = $this->container->get('config.storage.sync');
    $snapshot = $this->container->get('config.storage.snapshot');
    $config_name = 'config_test.system';
    $config_key = 'foo';
    $new_data = 'foobar';

    $active_snapshot_comparer = new StorageComparer($active$snapshot);
    $sync_snapshot_comparer = new StorageComparer($sync$snapshot);

    // Verify that we have an initial snapshot that matches the active     // configuration. This has to be true as no config should be installed.     $this->assertFalse($active_snapshot_comparer->createChangelist()->hasChanges());

    // Install the default config.     $this->installConfig(['config_test']);
    // Although we have imported config this has not affected the snapshot.     $this->assertTrue($active_snapshot_comparer->reset()->hasChanges());

    // Update the config snapshot.     \Drupal::service('config.manager')->createSnapshot($active$snapshot);

    // The snapshot and active config should now contain the same config     // objects.

  public function buildForm(array $form, FormStateInterface $form_state) {
    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#value' => $this->t('Import all'),
    ];
    $syncStorage = $this->importTransformer->transform($this->syncStorage);
    $source_list = $syncStorage->listAll();
    $storage_comparer = new StorageComparer($syncStorage$this->activeStorage);
    $storage_comparer->createChangelist();
    if (empty($source_list) || !$storage_comparer->hasChanges()) {
      $form['no_changes'] = [
        '#type' => 'table',
        '#header' => [$this->t('Name')$this->t('Operations')],
        '#rows' => [],
        '#empty' => empty($source_list) ? $this->t('There is no staged configuration.') : $this->t('The staged configuration is identical to the active configuration.'),
      ];
      $form['actions']['#access'] = FALSE;
      return $form;
    }
    elseif (!$storage_comparer->validateSiteUuid()) {
      $this->messenger()->addError($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.'));
      
Home | Imprint | This part of the site doesn't use cookies.