本文整理汇总了PHP中Drupal\user\Entity\User::loadMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP User::loadMultiple方法的具体用法?PHP User::loadMultiple怎么用?PHP User::loadMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\user\Entity\User
的用法示例。
在下文中一共展示了User::loadMultiple方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCheckedOutUsers
public function getCheckedOutUsers()
{
$users = User::loadMultiple();
$checked_in_users = $this->getCheckedInUsers();
$result = array();
// Unset checked in users.
foreach ($checked_in_users as $user) {
unset($users[$user['uid']]);
}
// Set up result array.
foreach ($users as $key => $user) {
$uid = $user->id();
if (!in_array($uid, array(0, 1))) {
$account = User::load($uid);
// Exclude users with some statuses.
// (vacation, sick, day_off, business_trip).
if (!in_array($account->field_user_status->value, $this->getExcludedUserStatuses())) {
$result[$key]['uid'] = $uid;
$result[$key]['field_first_name'] = $account->field_first_name->value;
$result[$key]['field_last_name'] = $account->field_last_name->value;
$result[$key]['field_image'] = $account->user_picture->target_id ? file_create_url(File::load($account->user_picture->target_id)->uri->value) : NULL;
}
}
}
return $result;
}
示例2: view
public function view(Request $request)
{
$users = User::loadMultiple();
var_dump($users);
foreach ($users as &$user) {
$user->status = ['day_off' => 0, 'sick' => 1, 'business_trip' => 0, 'remote_work' => 1, 'vacation' => 0];
}
return new JsonResponse(['users' => $users]);
}
示例3: valueForm
protected function valueForm(&$form, FormStateInterface $form_state)
{
$users = $this->value ? User::loadMultiple($this->value) : array();
$default_value = EntityAutocomplete::getEntityLabels($users);
$form['value'] = array('#type' => 'entity_autocomplete', '#title' => $this->t('Usernames'), '#description' => $this->t('Enter a comma separated list of user names.'), '#target_type' => 'user', '#tags' => TRUE, '#default_value' => $default_value, '#process_default_value' => FALSE);
$user_input = $form_state->getUserInput();
if ($form_state->get('exposed') && !isset($user_input[$this->options['expose']['identifier']])) {
$user_input[$this->options['expose']['identifier']] = $default_value;
$form_state->setUserInput($user_input);
}
}
示例4: fetch
public function fetch()
{
$query = $this->getQuery();
$result = $query->execute();
if ($this->entityType === 'user') {
// ugly fix for custom fields on User
return empty($result) ? array() : \Drupal\user\Entity\User::loadMultiple($result);
} else {
$store = \Drupal::entityManager()->getStorage($this->entityType);
return empty($result) ? array() : $store->loadMultiple($result);
}
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$header = array('username' => array('data' => t('Username'), 'field' => 'u.name'), 'status' => array('data' => t('Status'), 'field' => 'u.status'));
$query = db_select('users_field_data', 'u');
$query->condition('u.uid', 0, '<>');
$query->condition('u.default_langcode', 1);
$count_query = clone $query;
$count_query->addExpression('COUNT(u.uid)');
$query = $query->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('Drupal\\Core\\Database\\Query\\TableSortExtender');
$query->fields('u', array('uid'))->limit(50)->orderByHeader($header)->setCountQuery($count_query);
$uids = $query->execute()->fetchCol();
$options = array();
foreach (User::loadMultiple($uids) as $account) {
$options[$account->id()] = array('title' => array('data' => array('#title' => $account->getUsername())), 'username' => $account->getUsername(), 'status' => $account->isActive() ? t('active') : t('blocked'));
}
$form['accounts'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => t('No people available.'));
return $form;
}
示例6: loadMultiple
/**
* {@inheritdoc}
*/
public static function loadMultiple(array $ids = NULL)
{
return User::loadMultiple($ids);
}
示例7: destroyTestUser
/**
* Destroy a user that matches a test user name.
*
* @param $role
* @return $this
*/
public function destroyTestUser($role)
{
$this->output->writeln("deleting test{$role}User...");
$users = \Drupal::entityQuery('user')->condition("name", "test{$role}User")->execute();
$users = User::loadMultiple($users);
foreach ($users as $user) {
$user->delete();
}
return $this;
}
示例8: processSummaryArguments
/**
* {@inheritdoc}
*/
public function processSummaryArguments(&$args)
{
// If the validation says the input is an username, we should reverse the
// argument so it works for example for generation summary urls.
$uids_arg_keys = array_flip($args);
if ($this->options['type'] == 'name') {
$users = User::loadMultiple($args);
foreach ($users as $uid => $account) {
$args[$uids_arg_keys[$uid]] = $account->name;
}
}
}