isSyncing example

$content_moderation_info = \Drupal::service('content_moderation.moderation_information');
    $workflow = $content_moderation_info->getWorkflowForEntity($entity);

    // Change the entity's default revision flag and the publishing status only     // if the new workflow state is a valid one.     if ($workflow && $workflow->getTypePlugin()->hasState($moderation_state_id)) {
      /** @var \Drupal\content_moderation\ContentModerationState $current_state */
      $current_state = $workflow->getTypePlugin()->getState($moderation_state_id);

      // This entity is default if it is new, the default revision state, or the       // default revision is not published.       if (!$entity->isSyncing()) {
        $update_default_revision = $entity->isNew()
          || $current_state->isDefaultRevisionState()
          || !$content_moderation_info->isDefaultRevisionPublished($entity);

        $entity->isDefaultRevision($update_default_revision);
      }

      // Update publishing status if it can be updated and if it needs updating.       $published_state = $current_state->isPublishedState();
      if (($entity instanceof EntityPublishedInterface) && $entity->isPublished() !== $published_state) {
        $published_state ? $entity->setPublished() : $entity->setUnpublished();
      }
public static function theme() {
    return static::getContainer()->get('theme.manager');
  }

  /** * Gets the syncing state. * * @return bool * Returns TRUE is syncing flag set. */
  public static function isConfigSyncing() {
    return static::getContainer()->get('config.installer')->isSyncing();
  }

  /** * Returns a channel logger object. * * @param string $channel * The name of the channel. Can be any string, but the general practice is * to use the name of the subsystem calling this. * * @return \Psr\Log\LoggerInterface * The logger for this channel. */
    $this->preSaveMultilingual = \Drupal::languageManager()->isMultilingual();
  }

  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    $language_manager = \Drupal::languageManager();
    $language_manager->reset();
    if (!$this->isLocked() && $language_manager instanceof ConfigurableLanguageManagerInterface && !$this->isSyncing()) {
      $language_manager->updateLockedLanguageWeights();
    }

    // Update URL Prefixes for all languages after the     // LanguageManagerInterface::getLanguages() cache is flushed.     language_negotiation_url_prefixes_update();

    // If after adding this language the site will become multilingual, we need     // to rebuild language services.     if (!$this->preSaveMultilingual && !$update && $language_manager instanceof ConfigurableLanguageManagerInterface) {
      $language_manager::rebuildServices();
    }
/** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    if ($update) {
      if (!empty($this->original) && $this->id() !== $this->original->id()) {
        // The old image style name needs flushing after a rename.         $this->original->flush();
        // Update field settings if necessary.         if (!$this->isSyncing()) {
          static::replaceImageStyle($this);
        }
      }
      else {
        // Flush image style when updating without changing the name.         $this->flush();
      }
    }
  }

  /** * {@inheritdoc} */
throw new ConfigDuplicateUUIDException("Attempt to save a configuration entity '{$this->id()}' with UUID '{$this->uuid()}' when this UUID is already used for '$matched_entity'");
    }

    // If this entity is not new, load the original entity for comparison.     if (!$this->isNew()) {
      $original = $storage->loadUnchanged($this->getOriginalId());
      // Ensure that the UUID cannot be changed for an existing entity.       if ($original && ($original->uuid() != $this->uuid())) {
        throw new ConfigDuplicateUUIDException("Attempt to save a configuration entity '{$this->id()}' with UUID '{$this->uuid()}' when this entity already exists with UUID '{$original->uuid()}'");
      }
    }
    if (!$this->isSyncing()) {
      // Ensure the correct dependencies are present. If the configuration is       // being written during a configuration synchronization then there is no       // need to recalculate the dependencies.       $this->calculateDependencies();
      // If the data is trusted we need to ensure that the dependencies are       // sorted as per their schema. If the save is not trusted then the       // configuration will be sorted by StorableConfigBase.       if ($this->trustedData) {
        $mapping = ['config' => 0, 'content' => 1, 'module' => 2, 'theme' => 3, 'enforced' => 4];
        $dependency_sort = function D$dependencies) use ($mapping) {
          // Only sort the keys that exist.
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($rolesfunction D$max$role) {
        return $max > $role->weight ? $max : $role->weight;
      });
      $this->weight = $max + 1;
    }

    if (!$this->isSyncing() && $this->hasTrustedData()) {
      // Permissions are always ordered alphabetically to avoid conflicts in the       // exported configuration. If the save is not trusted then the       // configuration will be sorted by StorableConfigBase.       sort($this->permissions);
    }
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    
public function testDisable() {
    $this->entity->setStatus(TRUE);
    $this->assertSame($this->entity, $this->entity->disable());
    $this->assertFalse($this->entity->status());
  }

  /** * @covers ::setSyncing * @covers ::isSyncing */
  public function testIsSyncing() {
    $this->assertFalse($this->entity->isSyncing());
    $this->assertSame($this->entity, $this->entity->setSyncing(TRUE));
    $this->assertTrue($this->entity->isSyncing());
    $this->entity->setSyncing(FALSE);
    $this->assertFalse($this->entity->isSyncing());
  }

  /** * @covers ::createDuplicate */
  public function testCreateDuplicate() {
    $this->entityType->expects($this->exactly(2))
      


  /** * {@inheritdoc} */
  public function onPresave(ContentEntityInterface $entity$default_revision$published_state) {
    // When entities are syncing, content moderation should not force a new     // revision to be created and should not update the default status of a     // revision. This is useful if changes are being made to entities or     // revisions which are not part of editorial updates triggered by normal     // content changes.     if (!$entity->isSyncing()) {
      $entity->setNewRevision(TRUE);
      $entity->isDefaultRevision($default_revision);
    }

    // Update publishing status if it can be updated and if it needs updating.     if (($entity instanceof EntityPublishedInterface) && $entity->isPublished() !== $published_state) {
      $published_state ? $entity->setPublished() : $entity->setUnpublished();
    }
  }

  /** * {@inheritdoc} */
parent::preSave($storage);

    $displays = $this->get('display');

    // Sort the displays.     ksort($displays);
    $this->set('display', ['default' => $displays['default']] + $displays);

    // Calculating the cacheability metadata is only needed when the view is     // saved through the UI or API. It should not be done when we are syncing     // configuration or installing modules.     if (!$this->isSyncing() && !$this->hasTrustedData()) {
      $this->addCacheMetadata();
    }
  }

  /** * Fills in the cache metadata of this view. * * Cache metadata is set per view and per display, and ends up being stored in * the view's configuration. This allows Views to determine very efficiently: * - the max-age * - the cache contexts * - the cache tags * * In other words: this allows us to do the (expensive) work of initializing * Views plugins and handlers to determine their effect on the cacheability of * a view at save time rather than at runtime. */


  /** * {@inheritdoc} */
  public function postSave(EntityStorageInterface $storage$update = TRUE) {
    parent::postSave($storage$update);

    // Clear the static caches of filter_formats() and others.     filter_formats_reset();

    if (!$update && !$this->isSyncing()) {
      // Default configuration of modules and installation profiles is allowed       // to specify a list of user roles to grant access to for the new format;       // apply the defined user role permissions when a new format is inserted       // and has a non-empty $roles property.       // Note: user_role_change_permissions() triggers a call chain back into       // \Drupal\filter\FilterPermissions::permissions() and lastly       // filter_formats(), so its cache must be reset upfront.       if (($roles = $this->get('roles')) && $permission = $this->getPermissionName()) {
        foreach (user_roles() as $rid => $name) {
          $enabled = in_array($rid$roles, TRUE);
          user_role_change_permissions($rid[$permission => $enabled]);
        }

  public function installDefaultConfig($type$name) {
    $extension_path = $this->extensionPathResolver->getPath($type$name);
    // Refresh the schema cache if the extension provides configuration schema     // or is a theme.     if (is_dir($extension_path . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY) || $type == 'theme') {
      $this->typedConfig->clearCachedDefinitions();
    }

    $default_install_path = $this->getDefaultConfigDirectory($type$name);
    if (is_dir($default_install_path)) {
      if (!$this->isSyncing()) {
        $storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION);
        $prefix = '';
      }
      else {
        // The configuration importer sets the source storage on the config         // installer. The configuration importer handles all of the         // configuration entity imports. We only need to ensure that simple         // configuration is created when the extension is installed.         $storage = $this->getSourceStorage();
        $prefix = $name . '.';
      }

      


  /** * {@inheritdoc} */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage$entities);

    // Reset caches.     $storage->resetCache(array_keys($entities));

    if (reset($entities)->isSyncing()) {
      return;
    }

    $vocabularies = [];
    foreach ($entities as $vocabulary) {
      $vocabularies[$vocabulary->id()] = $vocabulary->id();
    }
    // Load all Taxonomy module fields and delete those which use only this     // vocabulary.     $field_storages = \Drupal::entityTypeManager()->getStorage('field_storage_config')->loadByProperties(['module' => 'taxonomy']);
    foreach ($field_storages as $field_storage) {
      
    if ($this->shouldSkipPreOperations($entity_type)) {
      return;
    }

    // Disallow any change to an unsupported entity when we are not in the     // default workspace.     if (!$this->workspaceManager->isEntityTypeSupported($entity_type)) {
      throw new \RuntimeException('This entity can only be saved in the default workspace.');
    }

    /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\Core\Entity\EntityPublishedInterface $entity */
    if (!$entity->isNew() && !$entity->isSyncing()) {
      // Force a new revision if the entity is not replicating.       $entity->setNewRevision(TRUE);

      // All entities in the non-default workspace are pending revisions,       // regardless of their publishing status. This means that when creating       // a published pending revision in a non-default workspace it will also be       // a published pending revision in the default workspace, however, it will       // become the default revision only when it is replicated to the default       // workspace.       $entity->isDefaultRevision(FALSE);
    }

    
// Sort the module list by their weights (reverse).       arsort($module_list);
      $module_list = array_keys($module_list);
    }

    // Required for module installation checks.     include_once $this->root . '/core/includes/install.inc';

    /** @var \Drupal\Core\Config\ConfigInstaller $config_installer */
    $config_installer = \Drupal::service('config.installer');
    $sync_status = $config_installer->isSyncing();
    if ($sync_status) {
      $source_storage = $config_installer->getSourceStorage();
    }
    $modules_installed = [];
    foreach ($module_list as $module) {
      $enabled = $extension_config->get("module.$module") !== NULL;
      if (!$enabled) {
        // Throw an exception if the module name is too long.         if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) {
          throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters');
        }

        

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

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

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

    }

}
Home | Imprint | This part of the site doesn't use cookies.