public function LearningPathController::duplicateModule in Opigno module 8
Same name and namespace in other branches
- 3.x src/Controller/LearningPathController.php \Drupal\opigno_module\Controller\LearningPathController::duplicateModule()
Duplicate index.
1 string reference to 'LearningPathController::duplicateModule'
File
- src/
Controller/ LearningPathController.php, line 41
Class
- LearningPathController
- Class LearningPathController.
Namespace
Drupal\opigno_module\ControllerCode
public function duplicateModule($opigno_module) {
$duplicate = $opigno_module
->createDuplicate();
$current_name = $duplicate
->label();
$duplicate
->setName($this
->t('Duplicate of ') . $current_name);
$activities = $opigno_module
->getModuleActivities();
$current_time = \Drupal::time()
->getCurrentTime();
$add_activities = [];
foreach ($activities as $activity) {
$add_activities[] = OpignoActivity::load($activity->id);
}
$duplicate
->setOwnerId(\Drupal::currentUser()
->id());
$duplicate
->set('created', $current_time);
$duplicate
->set('changed', $current_time);
$duplicate
->save();
$duplicate_id = $duplicate
->id();
$opigno_module_obj = \Drupal::service('opigno_module.opigno_module');
$opigno_module_obj
->activitiesToModule($add_activities, $duplicate);
return $this
->redirect('opigno_module.edit', [
'opigno_module' => $duplicate_id,
]);
}