CompletenessController.php

PHOTO EMBED

Sun Dec 26 2021 17:23:20 GMT+0000 (UTC)

Saved by @igor #drupal #php

<?php

namespace Drupal\musin_core\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\musin_core\Service\UserHelperService;

class CompletenessController extends ControllerBase {

  protected $entityTypeManager;

  public function populateCompleteness()
  {
    $query = \Drupal::entityQuery('user');
    $uids = $query->execute();

    foreach ($uids as $key => $id) {
      $user = \Drupal::entityTypeManager()->getStorage('user')->load($id);
      $result = UserHelperService::getProfileCompleteness($user);
      $user->set('field_completeness', $result);
      $user->save();
    }
    return [];
  }
}
content_copyCOPY