You are here

protected function ImportTrainingForm::importTraining in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Form/ImportTrainingForm.php \Drupal\opigno_module\Form\ImportTrainingForm::importTraining()

Create training entity.

Parameters

array $training_content: List of settings from imported file.

Return value

Group

Throws

\Exception

1 call to ImportTrainingForm::importTraining()
ImportTrainingForm::submitForm in src/Form/ImportTrainingForm.php
Form submission handler.

File

src/Form/ImportTrainingForm.php, line 440

Class

ImportTrainingForm
Import Course form.

Namespace

Drupal\opigno_module\Form

Code

protected function importTraining($training_content) {
  $training = $this
    ->buildEntityOptions($training_content, 'learning_path');
  $new_training = Group::create($training);
  if (!empty($training_content['field_learning_path_description'][0])) {
    $new_training->field_learning_path_description->format = $training_content['field_learning_path_description'][0]['format'];
  }

  // Create media for training image.
  $image = $this
    ->importTrainingImage($training_content);
  if (!empty($image)) {
    $new_training->field_learning_path_media_image->target_id = $image
      ->id();
  }
  $new_training
    ->save();
  return $new_training;
}