I've installed Drupal 8, I've created a PHP file to read a XML file and insert some items, but I'm getting this error.
Fatal error: Uncaught Error: Class 'Drupal\node\Entity\Node' not found in C:\xampp\htdocs\drupal8\migracion.php:12 Stack trace: #0 {main} thrown in C:\xampp\htdocs\drupal8\migracion.php on line 12
This is the code I am using.
define('DRUPAL_DIR', __DIR__);
use \Drupal\Core\DrupalKernel;
use \Symfony\Component\HttpFoundation\Request;
use \Drupal\node\Entity\Node;
use \Drupal\file\Entity\File;
use \Drupal\pathauto\PathautoState;
$fileContentXML = file_get_contents(DRUPAL_DIR . "/sites/default/files/migration/data.xml");
$xml_file = simplexml_load_string($fileContentXML);
foreach ($xml_file->channel->item as $item) {
$node = Node::create(['type' => 'article']);
$nid = trim($item->nid);
$node->set('nid', $nid);
$node->set('uid', 1);
$node->enforceIsNew();
$node->save();
}
This is line 12 $node = Node::create(['type' => 'article']);
Do you have some idea howHow can iI fix this error?