Attaching image files to nodes programmatically in Drupal 7

前端 未结 8 1522
耶瑟儿~
耶瑟儿~ 2020-12-07 14:07

Is it possible to add an image to a node programmatically?

8条回答
  •  日久生厌
    2020-12-07 14:21

    $node->field_image[LANGUAGE_NONE][0] = (array)$file;

    I tried this with a multilingual site. It failed fairly... but horribly. I had to specify the language in question. Simply put, this worked instead:

    $node->field_image['en'][0] = (array)$file;

    Without it, the attached file was viewable in the 'view' screen but not in the 'edit' screen.

提交回复
热议问题