You are here

function drush_social_demo_generate in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/custom/social_demo/social_demo.drush.inc \drush_social_demo_generate()
  2. 8.7 modules/custom/social_demo/social_demo.drush.inc \drush_social_demo_generate()
  3. 8.8 modules/custom/social_demo/social_demo.drush.inc \drush_social_demo_generate()
  4. 10.3.x modules/custom/social_demo/social_demo.drush.inc \drush_social_demo_generate()
  5. 10.1.x modules/custom/social_demo/social_demo.drush.inc \drush_social_demo_generate()
  6. 10.2.x modules/custom/social_demo/social_demo.drush.inc \drush_social_demo_generate()

Creates demo content.

File

modules/custom/social_demo/social_demo.drush.inc, line 175
Contains social_demo.drush.inc.

Code

function drush_social_demo_generate() {
  social_demo_drush_require();
  \Drupal::currentUser()
    ->setAccount(User::load(1));
  $input_args = func_get_args();
  $content_types = [];
  foreach ($input_args as $input_arg) {
    $pieces = explode(':', $input_arg);
    $content_type = $pieces[0];
    $content_types[] = $content_type;
    $num_content_types[$content_type] = $pieces[1];
  }
  $manager = \Drupal::service('plugin.manager.demo_content');
  $plugins = $manager
    ->createInstances($content_types);

  /** @var \Drupal\social_demo\DemoContentInterface $plugin */
  foreach ($plugins as $plugin) {
    $num = $num_content_types[$plugin
      ->getPluginId()];
    $definition = $plugin
      ->getPluginDefinition();
    $plugin
      ->createContent(TRUE, $num);
    $count = $plugin
      ->count();
    if ($count !== FALSE) {
      drush_log("{$count} {$definition['label']}(s) created", LogLevel::INFO);
    }
  }
}