getConfigObjects example

try {
        if ($this->themeInstaller->install([$theme])) {
          $themes = $this->themeHandler->listInfo();
          $this->messenger()->addStatus($this->t('The %theme theme has been installed.', ['%theme' => $themes[$theme]->info['name']]));
        }
        else {
          $this->messenger()->addError($this->t('The %theme theme was not found.', ['%theme' => $theme]));
        }
      }
      catch (PreExistingConfigException $e) {
        $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
        $this->messenger()->addError(
          $this->formatPlural(
            count($config_objects),
            'Unable to install @extension, %config_names already exists in active configuration.',
            'Unable to install @extension, %config_names already exist in active configuration.',
            [
              '%config_names' => implode(', ', $config_objects),
              '@extension' => $theme,
            ])
        );
      }
      

  protected function modulesFailToEnableMessage(array $modules, PreExistingConfigException $exception): PluralTranslatableMarkup {
    $config_objects = $exception->flattenConfigObjects($exception->getConfigObjects());
    return $this->formatPlural(
      count($config_objects),
      'Unable to install @extension, %config_names already exists in active configuration.',
      'Unable to install @extension, %config_names already exist in active configuration.',
      [
        '%config_names' => implode(', ', $config_objects),
        '@extension' => $modules['install'][$exception->getExtension()],
      ]);
  }

}

        }
        else {
          $this->messenger()->addStatus($this->t('The %theme theme has been installed.', ['%theme' => $themes[$theme]->info['name']]));
        }
      }
      else {
        $this->messenger()->addError($this->t('The %theme theme was not found.', ['%theme' => $theme]));
      }
    }
    catch (PreExistingConfigException $e) {
      $config_objects = $e->flattenConfigObjects($e->getConfigObjects());
      $this->messenger()->addError(
        $this->formatPlural(
          count($config_objects),
          'Unable to install @extension, %config_names already exists in active configuration.',
          'Unable to install @extension, %config_names already exist in active configuration.',
          [
            '%config_names' => implode(', ', $config_objects),
            '@extension' => $theme,
          ])
      );
    }
    
$data = $collection_storage->read('config_collection_install_test.test');
      $this->assertEquals($collection$data['collection']);
    }

    // Tests that clashing configuration in collections is detected.     try {
      \Drupal::service('module_installer')->install(['config_collection_clash_install_test']);
      $this->fail('Expected PreExistingConfigException not thrown.');
    }
    catch (PreExistingConfigException $e) {
      $this->assertEquals('config_collection_clash_install_test', $e->getExtension());
      $this->assertEquals(['another_collection' => ['config_collection_install_test.test'], 'collection.test1' => ['config_collection_install_test.test'], 'collection.test2' => ['config_collection_install_test.test']]$e->getConfigObjects());
      $this->assertEquals('Configuration objects (another_collection/config_collection_install_test.test, collection/test1/config_collection_install_test.test, collection/test2/config_collection_install_test.test) provided by config_collection_clash_install_test already exist in active configuration', $e->getMessage());
    }

    // Test that the we can use the config installer to install all the     // available default configuration in a particular collection for enabled     // extensions.     \Drupal::service('config.installer')->installCollectionDefaultConfig('entity');
    // The 'entity' collection will not exist because the 'config_test' module     // is not enabled.     $this->assertEquals($collections$active_storage->getAllCollectionNames());
    // Enable the 'config_test' module and try again.
    $config_entity = $this->config($default_configuration_entity);
    $this->assertFalse($config_entity->isNew());
    $this->assertSame('Customized integration config label', $config_entity->get('label'));

    // Reinstall the integration module.     try {
      \Drupal::service('module_installer')->install(['config_integration_test']);
      $this->fail('Expected PreExistingConfigException not thrown.');
    }
    catch (PreExistingConfigException $e) {
      $this->assertEquals('config_integration_test', $e->getExtension());
      $this->assertEquals([StorageInterface::DEFAULT_COLLECTION => ['config_test.dynamic.config_integration_test']]$e->getConfigObjects());
      $this->assertEquals('Configuration objects (config_test.dynamic.config_integration_test) provided by config_integration_test already exist in active configuration', $e->getMessage());
    }

    // Delete the configuration entity so that the install will work.     $config_entity->delete();
    \Drupal::service('module_installer')->install(['config_integration_test']);

    // Verify the integration module's config was re-installed.     \Drupal::configFactory()->reset($default_config);
    \Drupal::configFactory()->reset($default_configuration_entity);
    $config_static = $this->config($default_config);
    
Home | Imprint | This part of the site doesn't use cookies.