當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AccountInterface::save方法代碼示例

本文整理匯總了PHP中Drupal\Core\Session\AccountInterface::save方法的典型用法代碼示例。如果您正苦於以下問題:PHP AccountInterface::save方法的具體用法?PHP AccountInterface::save怎麽用?PHP AccountInterface::save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Session\AccountInterface的用法示例。


在下文中一共展示了AccountInterface::save方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testUserTokens

 function testUserTokens()
 {
     // Add a user picture to the account.
     $image = current($this->drupalGetTestFiles('image'));
     $edit = array('files[user_picture_0]' => drupal_realpath($image->uri));
     $this->drupalPostForm('user/' . $this->account->id() . '/edit', $edit, t('Save'));
     $storage = \Drupal::entityManager()->getStorage('user');
     // Load actual user data from database.
     $storage->resetCache();
     $this->account = $storage->load($this->account->id());
     $this->assertTrue(!empty($this->account->user_picture->target_id), 'User picture uploaded.');
     $picture = ['#theme' => 'user_picture', '#account' => $this->account];
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $user_tokens = array('picture' => $renderer->render($picture), 'picture:fid' => $this->account->user_picture->target_id, 'picture:size-raw' => 125, 'ip-address' => NULL, 'roles' => implode(', ', $this->account->getRoles()));
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
     // Remove the simpletest-created user role.
     $roles = $this->account->getRoles();
     $this->account->removeRole(end($roles));
     $this->account->save();
     // Remove the user picture field and reload the user.
     FieldStorageConfig::loadByName('user', 'user_picture')->delete();
     $storage->resetCache();
     $this->account = $storage->load($this->account->id());
     $user_tokens = array('picture' => NULL, 'picture:fid' => NULL, 'ip-address' => NULL, 'roles' => 'authenticated', 'roles:keys' => (string) DRUPAL_AUTHENTICATED_RID);
     $this->assertTokens('user', array('user' => $this->account), $user_tokens);
     // The ip address token should work for the current user token type.
     $tokens = array('ip-address' => \Drupal::request()->getClientIp());
     $this->assertTokens('current-user', array(), $tokens);
     $anonymous = new AnonymousUserSession();
     $tokens = array('roles' => 'anonymous', 'roles:keys' => (string) DRUPAL_ANONYMOUS_RID);
     $this->assertTokens('user', array('user' => $anonymous), $tokens);
 }
開發者ID:dev981,項目名稱:gaptest,代碼行數:33,代碼來源:TokenUserTest.php


注:本文中的Drupal\Core\Session\AccountInterface::save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。