Programmatically accessing field values for a file in a custom form I have the kint() output below.



How do I get the values for the destination index?
Since the values array is a protected value, you can only access its value with a method (e.g. a magic method).

The File class extends ContentEntityBase, from which it gets the values property and the magic method that allows to access it. Supposing that $file is the variable containing an \Drupal\file\Entity\File object, you just need the following code.

$destination = $file['destination'];


Longer Explanation

The method that allows to access the content of the values array is ContentEntityBase::__get() (a magic method) that allows to access the value of an object as it would be an array. ContentEntityBase::__get() checks also the content of the values array; in fact it contains the following code.

  // Else directly read/write plain values. That way, non-field entity
  // properties can always be accessed directly.
  if (!isset($this-&gt;values[$name])) {
    $this-&gt;values[$name] = NULL;
  }
  return $this-&gt;values[$name];


So, using $file['destination'], that method would return you the value of $file-&gt;values['destination'] you cannot directly access.