DEV Community

James Candan
James Candan

Posted on

2

Drupal Install with Configs and hook_install()

I was able to perform the following steps to fix a config dependency error and then do a fresh install with config.

First, in order to bypass the --existing-config restriction on install profiles with a hook_install(), comment out web/core/profiles/standard/standard.install.

Then, do the following:

# A clean install to work with
lando drush si standard -y

# Export any individual missing configs.
# Example:
lando drush config:get comment.type.comment > config/sync/comment.type.comment.yml
lando drush config:get field.field.comment.comment.comment_body > config/sync/field.field.comment.comment.comment_body.yml

# Re-install with existing configs.
lando drush si standard --existing-config -y
Enter fullscreen mode Exit fullscreen mode

At this point, you have a working Drupal install with the imported existing configs.

We still want to run the standard profile's installation hook. So, copy the contents of standard_install(). In a text editor, paste and edit the PHP statements. Ensure the full paths are supplied to the class names. Copy this set of statements.

-  $user = User::load(1);
+  $user = Drupal\user\Entity\User::load(1);

-  $shortcut = Shortcut::create([
+  $shortcut = Drupal\shortcut\Entity\Shortcut::create([

-  $shortcut = Shortcut::create([
+  $shortcut = Drupal\shortcut\Entity\Shortcut::create([
Enter fullscreen mode Exit fullscreen mode

Hop into a PHP REPL, paste and run the PHP statements.

$ lando drush php
Psy Shell v0.10.12 (PHP 8.0.27 — cli) by Justin Hileman
Caonline Rebuild - Workbench Access (Drupal 9.4.5)
>>>   $user = Drupal\user\Entity\User::load(1);
...
  $shortcut->save();
=> 1
>>> exit
Enter fullscreen mode Exit fullscreen mode

At this point, you can export configs and commit.

lando drush cex -y 
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay