setSyncing example



  /** * {@inheritdoc} */
  public function importUpdate($name, Config $new_config, Config $old_config) {
    $id = static::getIDFromConfigName($name$this->entityType->getConfigPrefix());
    $entity = $this->load($id);
    if (!$entity) {
      throw new ConfigImporterException("Attempt to update non-existing entity '$id'.");
    }
    $entity->setSyncing(TRUE);
    $entity = $this->updateFromStorageRecord($entity$new_config->get());
    $entity->save();
    return TRUE;
  }

  /** * {@inheritdoc} */
  public function importDelete($name, Config $new_config, Config $old_config) {
    $id = static::getIDFromConfigName($name$this->entityType->getConfigPrefix());
    $entity = $this->load($id);
    

  public function doSyncStep($sync_step, &$context) {
    if (is_string($sync_step) && method_exists($this$sync_step)) {
      \Drupal::service('config.installer')->setSyncing(TRUE);
      $this->$sync_step($context);
    }
    elseif (is_callable($sync_step)) {
      \Drupal::service('config.installer')->setSyncing(TRUE);
      $sync_step($context$this);
    }
    else {
      throw new \InvalidArgumentException('Invalid configuration synchronization step');
    }
    \Drupal::service('config.installer')->setSyncing(FALSE);
  }

  
foreach ($tracked_entities as $entity_type_id => $revision_difference) {
          $entity_revisions = $this->entityTypeManager->getStorage($entity_type_id)
            ->loadMultipleRevisions(array_keys($revision_difference));
          $default_revisions = $this->entityTypeManager->getStorage($entity_type_id)
            ->loadMultiple(array_values($revision_difference));

          /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
          foreach ($entity_revisions as $entity) {
            // When pushing workspace-specific revisions to the default             // workspace (Live), we simply need to mark them as default             // revisions.             $entity->setSyncing(TRUE);
            $entity->isDefaultRevision(TRUE);

            // The default revision is not workspace-specific anymore.             $field_name = $entity->getEntityType()->getRevisionMetadataKey('workspace');
            $entity->{$field_name}->target_id = NULL;

            $entity->original = $default_revisions[$entity->id()];
            $entity->save();
          }
        }
      });
    }
// Set new default language.     \Drupal::service('language.default')->set($default_language);
    \Drupal::service('string_translation')->setDefaultLangcode($default_language->getId());

    $languages = \Drupal::service('language_manager')->getLanguages(LanguageInterface::STATE_ALL);
    $this->assertEquals(['default', 'und', 'zxx']array_keys($languages));

    $configurableLanguage = ConfigurableLanguage::create(['label' => $this->randomMachineName(), 'id' => 'test', 'weight' => 1]);
    // Simulate a configuration sync by setting the flag otherwise the locked     // language weights would be updated whilst saving.     // @see \Drupal\language\Entity\ConfigurableLanguage::postSave()     $configurableLanguage->setSyncing(TRUE)->save();

    $languages = \Drupal::service('language_manager')->getLanguages(LanguageInterface::STATE_ALL);
    $this->assertEquals(['default', 'test', 'und', 'zxx']array_keys($languages));
  }

}
->willReturn($query);
    $storage->expects($this->any())
      ->method('loadUnchanged')
      ->willReturn($this->entity);

    // Saving an entity will not reset the dependencies array during config     // synchronization.     $this->entity->set('dependencies', ['module' => ['node']]);
    $this->entity->preSave($storage);
    $this->assertEmpty($this->entity->getDependencies());

    $this->entity->setSyncing(TRUE);
    $this->entity->set('dependencies', ['module' => ['node']]);
    $this->entity->preSave($storage);
    $dependencies = $this->entity->getDependencies();
    $this->assertContains('node', $dependencies['module']);
  }

  /** * @covers ::addDependency */
  public function testAddDependency() {
    $method = new \ReflectionMethod('\Drupal\Core\Config\Entity\ConfigEntityBase', 'addDependency');
    
// When a view is saved normally we have to recalculate the cacheability     // metadata, since it is possible changes have been made to the view that     // affect cacheability.     $view = $this->entityTypeManager->getStorage('view')->load(self::TEST_VIEW_ID);
    $view->save();
    $this->assertCacheableMetadataHasBeenCalculated(TRUE);
    $this->resetState();

    // When a view is being saved due to config being synchronized, the     // cacheability metadata doesn't change so it should not be recalculated.     $view->setSyncing(TRUE);
    $view->save();
    $this->assertCacheableMetadataHasBeenCalculated(FALSE);
  }

  /** * Checks whether the view has calculated its cacheability metadata. * * @param bool $expected_result * TRUE if it is expected that the cacheability metadata has been * calculated. FALSE otherwise. * * @internal */
// A multiple permissions that do not exist.     $this->expectException(\RuntimeException::class);
    $this->expectExceptionMessage('Adding non-existent permissions to a role is not allowed. The incorrect permissions are "does not exist, also does not exist".');
    $role->grantPermission('does not exist')
      ->grantPermission('also does not exist')
      ->save();
  }

  public function testPermissionRevokeAndConfigSync() {
    $role = Role::create(['id' => 'test_role', 'label' => 'Test role']);
    $role->setSyncing(TRUE);
    $role->grantPermission('a')
      ->grantPermission('b')
      ->grantPermission('c')
      ->save();
    $this->assertSame(['a', 'b', 'c']$role->getPermissions());
    $role->revokePermission('b')->save();
    $this->assertSame(['a', 'c']$role->getPermissions());
  }

}
Error::logException($this->logger, $e, 'An error occurred while notifying the creation of the @name field storage definition: "@message" in %function (line %line of %file).', ['@name' => $storage_definition->getName()]);
                }
              }
            }
          }
        }

        // Install default configuration of the module.         $config_installer = \Drupal::service('config.installer');
        if ($sync_status) {
          $config_installer
            ->setSyncing(TRUE)
            ->setSourceStorage($source_storage);
        }
        \Drupal::service('config.installer')->installDefaultConfig('module', $module);

        // If the module has no current updates, but has some that were         // previously removed, set the version to the value of         // hook_update_last_removed().         if ($last_removed = $this->moduleHandler->invoke($module, 'update_last_removed')) {
          $version = max($version$last_removed);
        }
        $this->updateRegistry->setInstalledVersion($module$version);

        

class EntityShortcutSet extends EntityConfigBase {

  /** * {@inheritdoc} */
  protected function getEntity(Row $row, array $old_destination_id_values) {
    $entity = parent::getEntity($row$old_destination_id_values);
    // Set the "syncing" flag to TRUE, to avoid duplication of default     // shortcut links     $entity->setSyncing(TRUE);
    return $entity;
  }

}
/** * Tests no new revision is forced during a sync. */
  public function testNoRevisionForcedDuringSync() {
    $entity = EntityTestMulRevPub::create([
      'moderation_state' => 'draft',
      'name' => 'foo',
    ]);
    $entity->save();
    $initial_revision_id = $entity->getRevisionId();

    $entity->setSyncing(TRUE);
    $entity->name = 'bar';
    $entity->save();

    $this->assertEquals($entity->getRevisionId()$initial_revision_id);
  }

  /** * Tests changing the moderation state during a sync. */
  public function testSingleRevisionStateChangedDuringSync() {
    $entity = EntityTestMulRevPub::create([
      
'settings' => [
            // Misconfiguration aspects:             // 1. `<a>`, not `<a href>`, while `DrupalLink` is enabled             // 2. `<p style>` even though `style` is globally disallowed by             // filter_html             // 3. `<a onclick>` even though `on*` is globally disallowed by             // filter_html             'allowed_html' => '<p style> <br> <a onclick>',
          ],
        ],
      ],
    ])->setSyncing(TRUE)->save();
    Editor::create([
      'format' => 'minimal_ckeditor_wrong_allowed_html',
      'editor' => 'ckeditor',
      'settings' => [
        'toolbar' => [
          'rows' => [
            0 => [
              [
                'name' => 'Basic Formatting',
                'items' => [
                  'DrupalLink',
                ],

        public function getSourceStorage()
        {
            return $this->lazyLoadItself()->getSourceStorage();
        }

        /** * {@inheritdoc} */
        public function setSyncing($status)
        {
            return $this->lazyLoadItself()->setSyncing($status);
        }

        /** * {@inheritdoc} */
        public function isSyncing()
        {
            return $this->lazyLoadItself()->isSyncing();
        }

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