getUnprocessedConfiguration example


  public static function process(array &$context, ConfigImporter $config_importer) {
    if (!isset($context['sandbox']['field'])) {
      static::initializeSandbox($context$config_importer);
    }

    // Get the list of field storages to purge.     $field_storages = static::getFieldStoragesToPurge($context['sandbox']['field']['extensions']$config_importer->getUnprocessedConfiguration('delete'));
    // Get the first field storage to process.     $field_storage = reset($field_storages);
    if (!isset($context['sandbox']['field']['current_storage_id']) || $context['sandbox']['field']['current_storage_id'] != $field_storage->id()) {
      $context['sandbox']['field']['current_storage_id'] = $field_storage->id();
      // If the storage has not been deleted yet we need to do that. This is the       // case when the storage deletion is staged.       if (!$field_storage->isDeleted()) {
        $field_storage->delete();
      }
    }
    field_purge_batch($context['sandbox']['field']['purge_batch_size']$field_storage->getUniqueStorageIdentifier());
    


  /** * Checks if there are any unprocessed configuration changes. * * @return bool * TRUE if there are changes to process and FALSE if not. */
  public function hasUnprocessedConfigurationChanges() {
    foreach ($this->storageComparer->getAllCollectionNames() as $collection) {
      foreach (['delete', 'create', 'rename', 'update'] as $op) {
        if (count($this->getUnprocessedConfiguration($op$collection))) {
          return TRUE;
        }
      }
    }
    return FALSE;
  }

  /** * Gets list of processed changes. * * @param string $collection * (optional) The configuration collection to get processed changes for. * Defaults to the default collection. * * @return array * An array containing a list of processed changes. */
/** * Validates the configuration to be imported. * * @param \Drupal\Core\Config\ConfigImporterEvent $event * The Event to process. * * @throws \Drupal\Core\Config\ConfigNameException */
  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    foreach (['delete', 'create', 'update'] as $op) {
      foreach ($event->getConfigImporter()->getUnprocessedConfiguration($op) as $name) {
        try {
          Config::validateName($name);
        }
        catch (ConfigNameException $e) {
          $message = $this->t('The config name @config_name is invalid.', ['@config_name' => $name]);
          $event->getConfigImporter()->logError($message);
        }
      }
    }
    $config_importer = $event->getConfigImporter();
    if ($config_importer->getStorageComparer()->getSourceStorage()->exists('core.extension')) {
      
// Recreate with the same type - this will have a different UUID.     $content_type = NodeType::create([
      'type' => $type_name,
      'name' => 'Node type two',
    ]);
    $content_type->save();
    node_add_body_field($content_type);

    $this->configImporter->reset();
    // A node type, a field, an entity view display and an entity form display     // will be recreated.     $creates = $this->configImporter->getUnprocessedConfiguration('create');
    $deletes = $this->configImporter->getUnprocessedConfiguration('delete');
    $this->assertCount(5, $creates, 'There are 5 configuration items to create.');
    $this->assertCount(5, $deletes, 'There are 5 configuration items to delete.');
    $this->assertCount(0, $this->configImporter->getUnprocessedConfiguration('update'), 'There are no configuration items to update.');
    $this->assertSame($createsarray_reverse($deletes), 'Deletes and creates contain the same configuration names in opposite orders due to dependencies.');

    $this->configImporter->import();

    // Verify that there is nothing more to import.     $this->assertFalse($this->configImporter->reset()->hasUnprocessedConfigurationChanges());
    $content_type = NodeType::load($type_name);
    

function hook_config_import_steps_alter(&$sync_steps, \Drupal\Core\Config\ConfigImporter $config_importer) {
  $deletes = $config_importer->getUnprocessedConfiguration('delete');
  if (isset($deletes['field.storage.node.body'])) {
    $sync_steps[] = '_additional_configuration_step';
  }
}

/** * Alter config typed data definitions. * * For example you can alter the typed data types representing each * configuration schema type to change default labels or form element renderers * used for configuration translation. * * If implementations of this hook add or remove configuration schema a * ConfigSchemaAlterException will be thrown. Keep in mind that there are tools * that may use the configuration schema for static analysis of configuration * files, like the string extractor for the localization system. Such systems * won't work with dynamically defined configuration schemas. * * For adding new data types use configuration schema YAML files instead. * * @param $definitions * Associative array of configuration type definitions keyed by schema type * names. The elements are themselves array with information about the type. * * @see \Drupal\Core\Config\TypedConfigManager * @see \Drupal\Core\Config\Schema\ConfigSchemaAlterException */

  public function __construct(ConfigManagerInterface $config_manager, EntityTypeManagerInterface $entity_type_manager) {
    $this->configManager = $config_manager;
    $this->entityTypeManager = $entity_type_manager;
  }

  /** * {@inheritdoc} */
  public function onConfigImporterValidate(ConfigImporterEvent $event) {
    foreach (['update', 'delete'] as $op) {
      $unprocessed_configurations = $event->getConfigImporter()->getUnprocessedConfiguration($op);
      foreach ($unprocessed_configurations as $unprocessed_configuration) {
        if ($workflow = $this->getWorkflow($unprocessed_configuration)) {
          if ($op === 'update') {
            $original_workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->getSourceStorage()
              ->read($unprocessed_configuration);
            $workflow_config = $event->getConfigImporter()
              ->getStorageComparer()
              ->getTargetStorage()
              ->read($unprocessed_configuration);
            
'name' => $this->randomMachineName(),
      'uuid' => $uuid,
    ]);
    $content_type->save();

    // Confirm that the staged configuration is detected as a rename since the     // UUIDs match.     $this->configImporter->reset();
    $expected = [
      'node.type.' . $content_type->id() . '::config_test.dynamic.' . $test_entity_id,
    ];
    $renames = $this->configImporter->getUnprocessedConfiguration('rename');
    $this->assertSame($expected$renames);

    // Try to import the configuration. We expect an exception to be thrown     // because the staged entity is of a different type.     try {
      $this->configImporter->import();
      $this->fail('Expected ConfigImporterException thrown when a renamed configuration entity does not match the existing entity type.');
    }
    catch (ConfigImporterException $e) {
      $expected = [
        new FormattableMarkup('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', ['@old_type' => 'node_type', '@new_type' => 'config_test', '@old_name' => 'node.type.' . $content_type->id(), '@new_name' => 'config_test.dynamic.' . $test_entity_id]),
      ];
$field_storage_uuid_2 = FieldStorageConfig::load($field_storage_id_2)->uuid();

    $active = $this->container->get('config.storage');
    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($active$sync);
    $this->assertTrue($sync->delete($field_storage_config_name)new FormattableMarkup('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name]));
    $this->assertTrue($sync->delete($field_storage_config_name_2)new FormattableMarkup('Deleted field storage: @field_storage', ['@field_storage' => $field_storage_config_name_2]));
    $this->assertTrue($sync->delete($field_config_name)new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name]));
    $this->assertTrue($sync->delete($field_config_name_2a)new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name_2a]));
    $this->assertTrue($sync->delete($field_config_name_2b)new FormattableMarkup('Deleted field: @field', ['@field' => $field_config_name_2b]));

    $deletes = $this->configImporter()->getUnprocessedConfiguration('delete');
    $this->assertCount(5, $deletes, 'Importing configuration will delete 3 fields and 2 field storages.');

    // Import the content of the sync directory.     $this->configImporter()->import();

    // Check that the field storages and fields are gone.     \Drupal::entityTypeManager()->getStorage('field_storage_config')->resetCache([$field_storage_id]);
    $field_storage = FieldStorageConfig::load($field_storage_id);
    $this->assertNull($field_storage, 'The field storage was deleted.');
    \Drupal::entityTypeManager()->getStorage('field_storage_config')->resetCache([$field_storage_id_2]);
    $field_storage_2 = FieldStorageConfig::load($field_storage_id_2);
    
Home | Imprint | This part of the site doesn't use cookies.