Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default content for completely reproducible website #2

Closed
geerlingguy opened this issue Feb 10, 2019 · 3 comments
Closed

Add default content for completely reproducible website #2

geerlingguy opened this issue Feb 10, 2019 · 3 comments

Comments

@geerlingguy
Copy link
Owner

As the title says; basically add the default_content module, then add default nodes and a default admin user so I can have the entire site (including nodes) be reproducible inside the repository.

This may or may not be the best idea—otherwise I could create the content in a CSV or something and use Migrate to import after install...

@geerlingguy
Copy link
Owner Author

Have to create menu links manually in a hook_install()... but other than that most things seem to be coming along nicely here. I'm doing this work alongside #3, so I can have some content to theme.

@geerlingguy
Copy link
Owner Author

In the previous, commit, I'm calling the following function from within hook_install(), but it seems to not take effect... like after installation, config is imported and/or content is created and all the menu links are wiped out for some reason:

/**
 * Custom function to create menu links, until default_content can export them.
 *
 * @see https://www.drupal.org/project/default_content/issues/2885285
 * @see https://www.drupal.org/project/drupal/issues/2577923
 */
function _pidramble_default_content_create_menu_links() {
  $items = [
    [
      'uri' => 'route:<front>',
      'title' => 'Home',
      'weight' => 0,
    ],
    [
      'uri' => 'internal:/node/5',
      'title' => 'Wiki',
      'weight' => 5,
    ],
    [
      'uri' => 'internal:/node/2',
      'title' => 'About',
      'weight' => 10,
    ],
  ];

  foreach($items as $item) {
    $menu_link = MenuLinkContent::create([
      'title' => $item['title'],
      'link' => ['uri' => $item['uri']],
      'weight' => $item['weight'],
      'menu_name' => 'main',
      'expanded' => TRUE,
    ]);
    $menu_link->save();
  }
}

I'm trying to figure out if there's a way I can get these menu links to exist immediately following a fresh installation...

@geerlingguy
Copy link
Owner Author

As it turns out, the Default Content module creates a Drupal\default_content\Event\ImportEvent that I can subscribe to. So in the commit above I added the class ImportEventSubscriber, which basically waits for that event, then creates the menu items (it seems the menu item creation fails when I implement it directly in hook_install().

So, yay!

Need to document this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant