Skip to content

Instantly share code, notes, and snippets.

@algotrader-dotcom
Forked from logii/script.php
Created May 20, 2018 18:11
Show Gist options
  • Save algotrader-dotcom/88408d61585b5b1468005865c91946f9 to your computer and use it in GitHub Desktop.
Save algotrader-dotcom/88408d61585b5b1468005865c91946f9 to your computer and use it in GitHub Desktop.
Create A Node Programmatically on Drupal 8
<?php
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$kernel = new DrupalKernel('prod', $autoloader);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
// $response->send();
use Drupal\node\Entity\Node;
use \Drupal\file\Entity\File;
// Create node object with attached file.
$node = Node::create([
'type' => 'article',
'title' => 'Druplicon test',
// 'field_image' => [
// 'target_id' => $file->id(),
// 'alt' => 'Hello world',
// 'title' => 'Goodbye world'
// ],
]);
$node->save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment