Explanation

Within my block's configuration code (which implements the admin panel for configuring my custom block), I am attempting to get a file Uri of some custom content I've created.

The content type I created (jssor_content_type), contains a list of files. So each content type has 1 to n files associated with it.

What I need

I need to access the File Uri's of all files associated with each content of type jssor_content_type. The commented out ksm() calls are me attempting to find the right information. I've also looked at the documentation. As I'm a beginner of Drupal, I'm not quite able to work my way through this one.

Code I currently have:

// Get all content of type jssor_content_type (thanks Jaypan!)
$query = \Drupal::entityQuery('node')
   ->condition('status', 1)
   ->condition('type', 'jssor_content_type');
$nids = $query->execute();

$nodes = node_load_multiple($nids);
$options = [];
foreach ($nodes as $node)
{
   $options[$node->id()] = Html::escape($node->getTitle());

   //$file_uri = $node->getFileUri();
   //ksm($file_uri);

   //ksm($node->getFieldDefinition('field_slide_image')->get('fieldStorage'));

   //ksm($node);
}

Comments

CatsFromStonehenge’s picture

Always use kint's debug function ksm() for investigation of your node!

The solution is:
$image_uri = $node->get('field_slide_image')->entity->getFileUri());

It was weird that Googling forever on this didn't help, even though I was close many times. I think Drupal is so powerful, that it's difficult to know all the terminology and what it can do. This complexity can sometimes through you off the scent as a noob. But on the positive, this is part of the learning process! :-)