diff --git a/src/Plugin/monitoring/SensorPlugin/ContentEntityAggregatorSensorPlugin.php b/src/Plugin/monitoring/SensorPlugin/ContentEntityAggregatorSensorPlugin.php index a56b888..94dba93 100644 --- a/src/Plugin/monitoring/SensorPlugin/ContentEntityAggregatorSensorPlugin.php +++ b/src/Plugin/monitoring/SensorPlugin/ContentEntityAggregatorSensorPlugin.php @@ -201,9 +201,9 @@ class ContentEntityAggregatorSensorPlugin extends DatabaseAggregatorSensorPlugin // ); // Load entities. - $entity_type = $this->getEntityTypeId(); + $entity_type_id = $this->getEntityTypeId(); $entities = $this->entityManager - ->getStorage($entity_type) + ->getStorage($entity_type_id) ->loadMultiple($entity_ids); // Get the fields to display from the settings. @@ -211,6 +211,7 @@ class ContentEntityAggregatorSensorPlugin extends DatabaseAggregatorSensorPlugin // Render entities. $rows = []; + /* @var \Drupal\Core\Entity\FieldableEntityInterface $entity */ foreach ($entities as $id => $entity) { $row = []; foreach ($fields as $field) { @@ -242,9 +243,14 @@ class ContentEntityAggregatorSensorPlugin extends DatabaseAggregatorSensorPlugin break; default: - $property = $entity->getFieldDefinition($field)->getFieldStorageDefinition()->getMainPropertyName(); - $value = $entity->$field->view(['label' => 'hidden']); - $row[] = $value ? \Drupal::service('renderer')->renderPlain($value) : $entity->$field->$property; + if ($entity->hasField($field)) { + $property = $entity->getFieldDefinition($field)->getFieldStorageDefinition()->getMainPropertyName(); + $value = $entity->$field->view(['label' => 'hidden']); + $row[] = $value ? \Drupal::service('renderer')->renderPlain($value) : $entity->$field->$property; + } + else { + $row[] = t('invalid field'); + } break; } } @@ -255,7 +261,7 @@ class ContentEntityAggregatorSensorPlugin extends DatabaseAggregatorSensorPlugin ); } if (count($rows) > 0) { - $header = $this->sensorConfig->getSetting('verbose_fields'); + $header = $this->sensorConfig->getSetting('verbose_fields', ['ID, Label']); $output['entities'] = array( '#type' => 'table', '#header' => $header, @@ -416,7 +422,7 @@ class ContentEntityAggregatorSensorPlugin extends DatabaseAggregatorSensorPlugin ); $entity_type = $this->entityManager->getDefinition($this->getEntityTypeId()); $form['verbose_fields']['available_fields'] = [ - '#markup' => t('Available Fields for entity %type: %fields', [ + '#markup' => t('Available Fields for entity %type: %fields', [ '%type' => $entity_type->getLabel(), '%fields' => implode(', ', array_keys($this->entityManager->getBaseFieldDefinitions($this->getEntityTypeId()))) ]