private function createSession(array $class) {
    // Get/Create class.
    try {
      $sessionClass = $this->getClass($class);
    }
    catch (Exception $exception) {
      $message = sprintf(
        'Failed to get class for Groupex class %s with message %s',
        $class['class_id'],
        $exception->getMessage()
      );
      throw new Exception($message);
    }

    // Get session time paragraph.
    try {
      $sessionTime = $this->getSessionTime($class);
    }
    catch (Exception $exception) {
      $message = sprintf(
        'Failed to get session time for Groupex class %s with message %s',
        $class['class_id'],
        $exception->getMessage()
      );
      throw new Exception($message);
    }

    // Get session_exclusions.
    $sessionExclusions = $this->getSessionExclusions($class);

    $session = Node::create([
      'uid' => 1,
      'lang' => 'und',
      'type' => 'session',
      'title' => $class['title'],
    ]);

    $session->set('field_session_class', $sessionClass);
    $session->set('field_session_time', $sessionTime);
    $session->set('field_session_exclusions', $sessionExclusions);
    $session->set('field_session_location', ['target_id' => $class['location_id']]);
    $session->set('field_session_room', $class['studio']);
    $session->set('field_session_instructor', $class['instructor']);

    $session->setUnpublished();

    $session->save();
    $this->logger
      ->debug(
        'Session has been created. ID: %id, Location ID: %loc_id, Class ID: %class_id',
        [
          '%id' => $session->id(),
          '%loc_id' => $class['location_id'],
          '%class_id' => $class['class_id'],
        ]
      );

    return $session;
  }
private function createSession(array $class) {
    // Get/Create class.
    try {
      $sessionClass = $this->getClass($class);
    }
    catch (Exception $exception) {
      $message = sprintf(
        'Failed to get class for Groupex class %s with message %s',
        $class['class_id'],
        $exception->getMessage()
      );
      throw new Exception($message);
    }

    // Get session time paragraph.
    try {
      $sessionTime = $this->getSessionTime($class);
    }
    catch (Exception $exception) {
      $message = sprintf(
        'Failed to get session time for Groupex class %s with message %s',
        $class['class_id'],
        $exception->getMessage()
      );
      throw new Exception($message);
    }

    // Get session_exclusions.
    $sessionExclusions = $this->getSessionExclusions($class);

    $session = Node::create([
      'uid' => 1,
      'lang' => 'und',
      'type' => 'session',
      'title' => $class['title'],
    ]);

    $session->set('field_session_class', $sessionClass);
    $session->set('field_session_time', $sessionTime);
    $session->set('field_session_exclusions', $sessionExclusions);
    $session->set('field_session_location', ['target_id' => $class['location_id']]);
    $session->set('field_session_room', $class['studio']);
    $session->set('field_session_instructor', $class['instructor']);

    $session->setUnpublished();

    $session->save();
    $this->logger
      ->debug(
        'Session has been created. ID: %id, Location ID: %loc_id, Class ID: %class_id',
        [
          '%id' => $session->id(),
          '%loc_id' => $class['location_id'],
          '%class_id' => $class['class_id'],
        ]
      );

    return $session;
  }
private function createSession ( array $ class ) { // Get/Create class. try { $ sessionClass = $ this -> getClass ( $ class ) ; } catch ( Exception $ exception ) { $ message = sprintf ( 'Failed to get class for Groupex class %s with message %s' , $ class [ 'class_id' ] , $ exception -> getMessage ( ) ) ; throw new Exception ( $ message ) ; } // Get session time paragraph. try { $ sessionTime = $ this -> getSessionTime ( $ class ) ; } catch ( Exception $ exception ) { $ message = sprintf ( 'Failed to get session time for Groupex class %s with message %s' , $ class [ 'class_id' ] , $ exception -> getMessage ( ) ) ; throw new Exception ( $ message ) ; } // Get session_exclusions. $ sessionExclusions = $ this -> getSessionExclusions ( $ class ) ; $ session = Node :: create ( [ 'uid' => 1 , 'lang' => 'und' , 'type' => 'session' , 'title' => $ class [ 'title' ] , ] ) ; $ session -> set ( 'field_session_class' , $ sessionClass ) ; $ session -> set ( 'field_session_time' , $ sessionTime ) ; $ session -> set ( 'field_session_exclusions' , $ sessionExclusions ) ; $ session -> set ( 'field_session_location' , [ 'target_id' => $ class [ 'location_id' ] ] ) ; $ session -> set ( 'field_session_room' , $ class [ 'studio' ] ) ; $ session -> set ( 'field_session_instructor' , $ class [ 'instructor' ] ) ; $ session -> setUnpublished ( ) ; $ session -> save ( ) ; $ this -> logger -> debug ( 'Session has been created. ID: %id, Location ID: %loc_id, Class ID: %class_id' , [ '%id' => $ session -> id ( ) , '%loc_id' => $ class [ 'location_id' ] , '%class_id' => $ class [ 'class_id' ] , ] ) ; return $ session ; }
Create session.

@param array $class
Class properties.

@return \Drupal\Core\Entity\ContentEntityInterface
Session node.

@throws \Exception
Create session .