You are here

function radioactivity_entity_load in Radioactivity 8.3

Same name and namespace in other branches
  1. 4.0.x radioactivity.module \radioactivity_entity_load()

Implements hook_entity_load().

File

./radioactivity.module, line 54
Provides a field type which can be used as a hotness metric.

Code

function radioactivity_entity_load($entities, $type) {

  // In order for the field formatters to be rendered we need to make sure
  // the field actually has something in it to trigger the formatters.
  $fields = radioactivity_get_field_names();

  /** @var \Drupal\Core\Entity\FieldableEntityInterface[] $entities */
  foreach ($entities as &$entity) {
    foreach ($fields as $field_name) {
      if (is_a($entity, FieldableEntityInterface::class) && $entity
        ->hasField($field_name)) {
        if (!$entity
          ->get($field_name)->energy) {
          $entity
            ->get($field_name)->energy = 0;
          $entity
            ->get($field_name)->timestamp = 0;
        }
      }
    }
  }
}