Skip to main content
deleted 7 characters in body
Source Link
Jaypan
  • 18k
  • 3
  • 34
  • 65

You don't need to load all the fields, you can just load the image field:

$uuid = $vars['node']->get('field_image_image''field_hero')->getFieldDefinition()->getSetting('default_image')['uuid'];
$file = \Drupal::service('entity.manager')->loadEntityByUuid('file', $uuid);

On a different note, the first line of your code assumes that $vars['node'] exists, which it won't on non-node pages, so you should change it to:

if (isset($vars['node'], $vars['node']->field_hero))

You don't need to load all the fields, you can just load the image field:

$uuid = $vars['node']->get('field_image_image')->getFieldDefinition()->getSetting('default_image')['uuid'];
$file = \Drupal::service('entity.manager')->loadEntityByUuid('file', $uuid);

On a different note, the first line of your code assumes that $vars['node'] exists, which it won't on non-node pages, so you should change it to:

if (isset($vars['node'], $vars['node']->field_hero))

You don't need to load all the fields, you can just load the image field:

$uuid = $vars['node']->get('field_hero')->getFieldDefinition()->getSetting('default_image')['uuid'];
$file = \Drupal::service('entity.manager')->loadEntityByUuid('file', $uuid);

On a different note, the first line of your code assumes that $vars['node'] exists, which it won't on non-node pages, so you should change it to:

if (isset($vars['node'], $vars['node']->field_hero))
added 86 characters in body
Source Link
Jaypan
  • 18k
  • 3
  • 34
  • 65

You don't need to load all the fields, you can just load the image field:

$default_image$uuid = $vars['node']->getField>get('field_hero''field_image_image')->getFieldDefinition()->getSetting('default_image')['uuid'];
$file = \Drupal::service('entity.manager')->loadEntityByUuid('file', $uuid);

On a different note, the first line of your code assumes that $vars['node'] exists, which it won't on non-node pages, so you should change it to:

if (isset($vars['node'], $vars['node']->field_hero))

You don't need to load all the fields, you can just load the image field:

$default_image = $vars['node']->getField('field_hero')->getFieldDefinition()->getSetting('default_image');

On a different note, the first line of your code assumes that $vars['node'] exists, which it won't on non-node pages, so you should change it to:

if (isset($vars['node'], $vars['node']->field_hero))

You don't need to load all the fields, you can just load the image field:

$uuid = $vars['node']->get('field_image_image')->getFieldDefinition()->getSetting('default_image')['uuid'];
$file = \Drupal::service('entity.manager')->loadEntityByUuid('file', $uuid);

On a different note, the first line of your code assumes that $vars['node'] exists, which it won't on non-node pages, so you should change it to:

if (isset($vars['node'], $vars['node']->field_hero))
Source Link
Jaypan
  • 18k
  • 3
  • 34
  • 65

You don't need to load all the fields, you can just load the image field:

$default_image = $vars['node']->getField('field_hero')->getFieldDefinition()->getSetting('default_image');

On a different note, the first line of your code assumes that $vars['node'] exists, which it won't on non-node pages, so you should change it to:

if (isset($vars['node'], $vars['node']->field_hero))