1

I'm building a custom install profile for Drupal 8.4. It uses the new core Media module, and includes custom config files for the entity forms for media's image and file entities. One of those changes depends on the Path module being enabled.

I have both "media" and "path" listed in my install profile's dependencies.

I have the following two custom files:

docroot/profiles/custom/myprofile/core.entity_form_display.media.file.default.yml docroot/profiles/custom/myprofile/core.entity_form_display.media.image.default.yml

And each of these form display files includes "path" among its own module dependencies. When I try to run the installer, I get the following error:

Drupal\Core\Config\UnmetDependenciesException: Configuration objects provided by media have unmet dependencies: core.entity_form_display.media.file.default (path) in Drupal\Core\Config\UnmetDependenciesException::create() (line 98 of /Users/dicksb/Sites/devdesktop/drupal84/docroot/core/lib/Drupal/Core/Config/UnmetDependenciesException.php).

This error does not occur if I remove the two config files.

I believe the problem is simply that "media" is being enabled, and reading these config files, before "path" is enabled, because the media module itself doesn't require path. I reported this as a bug, but didn't really get anywhere; see https://www.drupal.org/project/drupal/issues/2908046.

I get that making media depend on path is not the right solution, but I'm not sure what is.

A workaround

I'm not sure if this is the best, or even a good, way to do this, but it seems to work. I've moved the troublesome configuration files from myprofile/config/install to myprofile/config/post-install. I've then added the following code to a task that runs after installation is complete:

$dir = DRUPAL_ROOT . '/profiles/custom/myprofile/config/post-install';
$files = glob($dir . '/*.yml');
$source = new \Drupal\Core\Config\FileStorage($dir);
$config_storage = \Drupal::service('config.storage');
foreach ($files as $file) {
  $components = explode(DIRECTORY_SEPARATOR, $file);
  $config_name = str_replace('.yml', '', end($components));
  $config_storage->write($config_name, $source->read($config_name));
}
  • Reading the issue you linked, there is also a core issue: drupal.org/project/drupal/issues/2922417 Did you test that patch as well? – Patrick Kenny Dec 5 '17 at 2:49
  • I did indeed. I'm sorry, I should have linked both. The issue I linked includes a (very simple) patch I submitted to add path as a dependency for the media module, an idea that was (rightly) rejected -- but it does actually solve my problem. The core patch linked later in the thread applies without any trouble, but has no effect on my problem. – WRD Dec 5 '17 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.