You are here

function heartbeat_update_type_weight in Heartbeat 8

Implements hook_cron().

File

./heartbeat.module, line 460
Contains heartbeat.module.

Code

function heartbeat_update_type_weight() {

  //Iterate over the Heartbeat Types and ensure that the weight of bundle-specific types are lower than that of their

  //parent type. This will allow us to ensure Bundle specific types end up being published as opposed to

  //Types which represent all content types
  $heartbeatTypes = \Drupal::service('entity.query')
    ->get('heartbeat_type')
    ->condition('mainentity', 'node')
    ->execute();
  if (count($heartbeatTypes) > 1) {
    foreach ($heartbeatTypes as $heartbeatType) {
      $entity = \Drupal::service('entity_type.manager')
        ->getStorage('heartbeat_type')
        ->load($heartbeatType);
      if ($entity
        ->getBundle() === null) {
        $entity
          ->setWeight(99);
        $entity
          ->save();
      }
      else {
        $entity
          ->setWeight(0);
        $entity
          ->save();
      }
    }
  }
}