Created
May 9, 2016 19:59
-
-
Save logii/8a406d3abc41e884adaacc6dd3362856 to your computer and use it in GitHub Desktop.
Create A Node Programmatically on Drupal 8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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