Skip to content
Snippets Groups Projects
Commit 2c9200d7 authored by Jakob P's avatar Jakob P
Browse files

Merge branch '2966909-ctools-block-field' into '8.x-3.x'

Check if a field exists before setting it in the build array.

See merge request !58
parents 6cd9b13c 29e09813
No related branches found
No related tags found
No related merge requests found
Pipeline #140403 skipped
......@@ -137,10 +137,13 @@ class EntityField extends BlockBase implements ContextAwarePluginInterface, Cont
/** @var \Drupal\Core\Entity\FieldableEntityInterface $entity */
$entity = $this->getContextValue('entity');
$build = [];
/** @var \Drupal\Core\Field\FieldItemListInterface $field */
$field = $entity->{$this->fieldName};
$display_settings = $this->getConfiguration()['formatter'];
$build['field'] = $field->view($display_settings);
if ($entity->hasField($this->fieldName)) {
/** @var \Drupal\Core\Field\FieldItemListInterface $field */
$field = $entity->{$this->fieldName};
$display_settings = $this->getConfiguration()['formatter'];
$build['field'] = $field->view($display_settings);
}
// Set the cache data appropriately.
$build['#cache']['contexts'] = $this->getCacheContexts();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment