protected function importPages() {
    $data = $this->loadDataArray('node');
    if (!empty($data)) {

      $uuids = [];

      foreach ($data as $item) {

        // Prepare content.
        $values = [
          'type' => $item['type'],
          'title' => $item['title'],
        ];
        // Fields mapping starts.
        // Set Body Field.
        if (!empty($item['body'])) {
          $body = $this->getBodyData($item['body']);
          if ($body !== FALSE) {
            $values['body'] = [
              'value' => $body,
              'format' => 'rich_text',
            ];
          }
        }

        if (!empty($item['summary'])) {
          $values['body']['summary'] = $item['summary'];
        }
        // Set node alias if exists.
        if (!empty($item['path'])) {
          $values['path'] = [
            'alias' => $item['path'],
            'pathauto' => 0,
          ];
        }

        $this->loadProcessorPlugins($values, $item, 'node');

        // Set article author.
        $values['uid'] = 1;

        // Create Node.
        $node = $this->entityTypeManager->getStorage('node')->create($values);
        $node->setPublished(TRUE);
        $node->set('moderation_state', "published");
        $node->save();

        // Create menu links.
        if (!empty($item['menu'])) {
          $item['menu']['link'] = [
            'uri' => 'internal:/node/' . $node->id(),
          ];
          $menu_link = $this->entityTypeManager->getStorage('menu_link_content')->create($item['menu']);
          $menu_link->save();
        }
        // Set page to front page is 'front_page' is equals TRUE.
        if (!empty($item['front_page']) && $item['front_page'] == TRUE) {
          \Drupal::service('config.factory')->getEditable('system.site')->set('page.front', '/node/' . $node->id())->save();
        }

        $uuids[$node->uuid()] = 'node';
      }
      $this->storeCreatedContentUuids($uuids);
    }
    return $this;
  }
protected function importPages() {
    $data = $this->loadDataArray('node');
    if (!empty($data)) {

      $uuids = [];

      foreach ($data as $item) {

        // Prepare content.
        $values = [
          'type' => $item['type'],
          'title' => $item['title'],
        ];
        // Fields mapping starts.
        // Set Body Field.
        if (!empty($item['body'])) {
          $body = $this->getBodyData($item['body']);
          if ($body !== FALSE) {
            $values['body'] = [
              'value' => $body,
              'format' => 'rich_text',
            ];
          }
        }

        if (!empty($item['summary'])) {
          $values['body']['summary'] = $item['summary'];
        }
        // Set node alias if exists.
        if (!empty($item['path'])) {
          $values['path'] = [
            'alias' => $item['path'],
            'pathauto' => 0,
          ];
        }

        $this->loadProcessorPlugins($values, $item, 'node');

        // Set article author.
        $values['uid'] = 1;

        // Create Node.
        $node = $this->entityTypeManager->getStorage('node')->create($values);
        $node->setPublished(TRUE);
        $node->set('moderation_state', "published");
        $node->save();

        // Create menu links.
        if (!empty($item['menu'])) {
          $item['menu']['link'] = [
            'uri' => 'internal:/node/' . $node->id(),
          ];
          $menu_link = $this->entityTypeManager->getStorage('menu_link_content')->create($item['menu']);
          $menu_link->save();
        }
        // Set page to front page is 'front_page' is equals TRUE.
        if (!empty($item['front_page']) && $item['front_page'] == TRUE) {
          \Drupal::service('config.factory')->getEditable('system.site')->set('page.front', '/node/' . $node->id())->save();
        }

        $uuids[$node->uuid()] = 'node';
      }
      $this->storeCreatedContentUuids($uuids);
    }
    return $this;
  }
protected function importPages ( ) { $ data = $ this -> loadDataArray ( 'node' ) ; if ( ! empty ( $ data ) ) { $ uuids = [ ] ; foreach ( $ data as $ item ) { // Prepare content. $ values = [ 'type' => $ item [ 'type' ] , 'title' => $ item [ 'title' ] , ] ; // Fields mapping starts. // Set Body Field. if ( ! empty ( $ item [ 'body' ] ) ) { $ body = $ this -> getBodyData ( $ item [ 'body' ] ) ; if ( $ body !== FALSE ) { $ values [ 'body' ] = [ 'value' => $ body , 'format' => 'rich_text' , ] ; } } if ( ! empty ( $ item [ 'summary' ] ) ) { $ values [ 'body' ] [ 'summary' ] = $ item [ 'summary' ] ; } // Set node alias if exists. if ( ! empty ( $ item [ 'path' ] ) ) { $ values [ 'path' ] = [ 'alias' => $ item [ 'path' ] , 'pathauto' => 0 , ] ; } $ this -> loadProcessorPlugins ( $ values , $ item , 'node' ) ; // Set article author. $ values [ 'uid' ] = 1 ; // Create Node. $ node = $ this -> entityTypeManager -> getStorage ( 'node' ) -> create ( $ values ) ; $ node -> setPublished ( TRUE ) ; $ node -> set ( 'moderation_state' , "published" ) ; $ node -> save ( ) ; // Create menu links. if ( ! empty ( $ item [ 'menu' ] ) ) { $ item [ 'menu' ] [ 'link' ] = [ 'uri' => 'internal:/node/' . $ node -> id ( ) , ] ; $ menu_link = $ this -> entityTypeManager -> getStorage ( 'menu_link_content' ) -> create ( $ item [ 'menu' ] ) ; $ menu_link -> save ( ) ; } // Set page to front page is 'front_page' is equals TRUE. if ( ! empty ( $ item [ 'front_page' ] ) && $ item [ 'front_page' ] == TRUE ) { \ Drupal :: service ( 'config.factory' ) -> getEditable ( 'system.site' ) -> set ( 'page.front' , '/node/' . $ node -> id ( ) ) -> save ( ) ; } $ uuids [ $ node -> uuid ( ) ] = 'node' ; } $ this -> storeCreatedContentUuids ( $ uuids ) ; } return $ this ; }
Imports pages.
Imports pages .