Ulozenie GD lib image ako image field v Node content type


#1

Dobry den, mam v umysle ulozit jednoduchy obdlznikovy obrazok vytvoreny z GD kniznice a nechat si ho zobrazit ako Node custom type.

$img = imagecreatetruecolor(300, 250);
$color = imagecolorallocate($img, 0,255,0);
imagefilledrectangle($img, 0, 0, 300, 250, $color);

Vytvoril som si vlastny content type s nazvom heatmap s dvomi fieldami(title a field_heatmap). ked som echoval $img tak mi vypisalo “Resource id #469”. Snazil som sa to teda ulozit nasledovne:

$this->NodeStorage = \Drupal::entityTypeManager()->getStorage(‘node’);
$node_fields = [
‘title’ =>‘Titulok pre moj img’,
‘field_heatmap’ => [
‘target_id’ => $img,
‘alt’ => ‘Ja som img’,
],
‘status’ => 1,
‘type’ => ‘heatmap’,
‘promote’ => 1,
‘langcode’ => ‘en’,
];
$node = $this->NodeStorage->create($node_fields);
$this->NodeStorage->save($node);

Bol to z mojej strany, cisty tip, lebo mi hadze:InvalidArgumentException: Value is not a valid entity. in Drupal\Core\Entity\Plugin\DataType\EntityReference->setValue() (line 109 of /data/www/bealoc.org/www.bealoc.org/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityReference.php).
Viete pripadne poradit ako inak by som dosiahol nieco podobne? Dakujem


#2

Subor je tiez entita, takze najprv musis vytvorit tu entitu a potom ju priradit do pola.