Programmatically place image field as default value in form plugin I have a content type that has an image field that allows you to upload up to 4 photos. I'm creating a form for users to use that will allow them to edit existing items of this content type. The form fields need to be filled with the existing node field values by default. Retrieving fields such as textfields and supplying the default value works just fine, like so:

class EquipmentEditForm extends ConfigFormBase {
    private $imageNum = 4;

    protected function getEditableConfigNames() {
        return array(
            'equipment.form',
        );
    }
    public function buildForm(array $form, FormStateInterface $form_state) {
        $equipment_id = 10306;
        $node = NODE::load($equipment_id);

        $contact        = $node-&gt;get('field_contact')-&gt;value;
        $description    = $node-&gt;get('field_description')-&gt;value;

        $form = [
            'container'    =&gt; [
                '#type'       =&gt; 'container',
                '#attributes' =&gt; [
                    'class'      =&gt; ['equipment-entry'],
                ],
                'contact'      =&gt; [
                    '#type'       =&gt; 'textfield',
                    '#title'      =&gt; t('Contact Person'),
                    '#attributes' =&gt; [
                        'name'       =&gt; 'contact',
                    ],
                    '#default_value' =&gt; $contact,
                ],
                'description'    =&gt; [
                    '#type'       =&gt; 'textfield',
                    '#title'      =&gt; t('Description'),
                    '#attributes' =&gt; [
                        'name'       =&gt; 'description',
                    ],
                    '#default_value' =&gt; $description,
                ],
           ],
        ];
    }
}


This generates the form and populated the fields from the node just fine. However I'm not sure how to populate the image field.
I've attempted the following with no luck.

    if ($node-&gt;get('field_equipment_photo')-&gt;entity != null) {
        $photos = $node-&gt;get('field_equipment_photo');
    }
    for ($i = 1; $i &lt;= $this-&gt;imageNum; $i += 1) {

        $title = ($i == 1)?'Image '.$i:'Image '.$i.' (extra)';

        $form['image'.$i] = [
            '#type'            =&gt; 'managed_file',
            '#upload_location' =&gt; 'public://images/',
            '#title'           =&gt; t($title),
            '#name'            =&gt; 'image'.$i,
            '#default_value'   =&gt; $photos[$i],
        ];
    }


It just provides an error


  Recoverable fatal error: Object of class
  Drupal\Core\TypedData\Plugin\DataType\IntegerData could not be
  converted to string in
  Drupal\Core\Entity\ContentEntityStorageBase->buildCacheId() (line 659
  of core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php).


I know I'm retrieving the images because if I perform a statement like this:

die(print_r($photos[1]-&gt;entity));


I do get a list of the information contained in the 2 uploaded image. Including the filename.

How would I programmatically retrieve the values of an image field array of a node and place them into the default values of a form field?

UPDATE: I'm able to discover the fid using

die(print_r($photos[0]-&gt;entity-&gt;fid-&gt;value));


but using $photos[0]->entity->fid->value as the default value leads to this error


  Warning: Invalid argument supplied for foreach() in
  Drupal\file\Element\ManagedFile::valueCallback()
Turns out I needed to get the fid of the images and place them into an array. First I started by retrieving the images like I did before 

    if ($node-&gt;get('field_equipment_photo')-&gt;entity != null) {
        $photos = $node-&gt;get('field_equipment_photo');
    }


Then I grabbed the fid and placed them into the default value like so

if ($photos[$i]-&gt;entity-&gt;fid-&gt;value != null) {
                $form['image'.$i]['#default_value'] = array($photos[$i]-&gt;entity-&gt;fid-&gt;value);
            }


For some reason even though the fid is just one value it still needs to be wrapped in an array when being used as the default value.