installOptionalConfig example

/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    // Install the optional configs from the standard profile.     $extension_path = $this->container->get('extension.list.profile')->getPath('standard');
    $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
    $storage = new FileStorage($optional_install_path);
    $this->container->get('config.installer')->installOptionalConfig($storage, '');
    // Reset all the static caches and list caches.     $this->container->get('config.factory')->reset();

    // This test is going to test the display, so we need the standalone URL.     \Drupal::configFactory()
      ->getEditable('media.settings')
      ->set('standalone_url', TRUE)
      ->save(TRUE);

    $this->container->get('router.builder')->rebuild();
  }

  
// During a drupal installation optional configuration is installed at the     // end of the installation process. Once the install profile is installed     // optional configuration should be installed as usual.     // @see install_install_profile()     $profile_installed = in_array($this->drupalGetProfile()$this->getEnabledExtensions(), TRUE);
    if (!$this->isSyncing() && (!InstallerKernel::installationAttempted() || $profile_installed)) {
      $optional_install_path = $extension_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
      if (is_dir($optional_install_path)) {
        // Install any optional config the module provides.         $storage = new FileStorage($optional_install_path, StorageInterface::DEFAULT_COLLECTION);
        $this->installOptionalConfig($storage, '');
      }
      // Install any optional configuration entities whose dependencies can now       // be met. This searches all the installed modules config/optional       // directories.       $storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE, $this->installProfile);
      $this->installOptionalConfig($storage[$type => $name]);
    }

    // Reset all the static caches and list caches.     $this->configFactory->reset();
  }

  
public function installDefaultConfig($type$name)
        {
            return $this->lazyLoadItself()->installDefaultConfig($type$name);
        }

        /** * {@inheritdoc} */
        public function installOptionalConfig(?\Drupal\Core\Config\StorageInterface $storage = NULL, $dependency = array (
        ))
        {
            return $this->lazyLoadItself()->installOptionalConfig($storage$dependency);
        }

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

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