I try to get a php command line job running, actually testing it currently by calling it via an url for convenience.
There are all kinds of source code examples for reading a node from drupal, all end with the same problem when calling the nodes save method.
I can read the node without any problem, but when storing the updated value i.e. title it throws:
PHP Fatal error: Call to undefined function Drupal\\Core\\Entity\\Plugin\\DataType\\entity_load() in /var/www/mysite/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php on line 70
define('DRUPAL_DIR', '/var/www/mysite/');
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
use Drupal\node\Entity\Node;
$autoloader = require_once DRUPAL_DIR . 'autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
define('TESTID', 12);
$storage = \Drupal::entityManager()->getStorage('node');
$node = $storage->load(TESTID);
$fTitle = $node->get('title');
$sTitle = $fTitle->value;
echo $sTitle;
$fTitle->value = 'New Title';
$node->save();
Comments
Comment #2
kkretsch commentedComment #3
dawehnerIn order to fully load drupal you also need to execute
$kernel->preHandle():(Comment #4
kkretsch commentedThanks, that did it:
Now I can save that node. Case closed!
Comment #5
kkretsch commented