assignUser example


  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    /** @var \Drupal\shortcut\ShortcutSetInterface $set */
    $set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
    /** @var \Drupal\user\UserInterface $account */
    $account = User::load($row->getDestinationProperty('uid'));
    $this->shortcutSetStorage->assignUser($set$account);

    return [$set->id()$account->id()];
  }

}
// Switch to a different shortcut set.       /** @var \Drupal\shortcut\Entity\ShortcutSet $set */
      $set = $this->shortcutSetStorage->load($form_state->getValue('set'));
      $replacements = [
        '%user' => $this->user->getDisplayName(),
        '%set_name' => $set->label(),
      ];
      $this->messenger()->addStatus($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));
    }

    // Assign the shortcut set to the provided user account.     $this->shortcutSetStorage->assignUser($set$this->user);
  }

  /** * Checks access for the shortcut set switch form. * * @param \Drupal\user\UserInterface $user * (optional) The owner of the shortcut set. * * @return \Drupal\Core\Access\AccessResultInterface * The access result. */
  
$request_options = [];
    $request_options[RequestOptions::HEADERS]['Accept'] = 'application/vnd.api+json';
    $request_options = NestedArray::mergeDeep($request_options$this->getAuthenticationRequestOptions());

    // No results because the current user does not have access to shortcuts     // not in the user's assigned set or the default set.     $response = $this->request('GET', $collection_filter_url$request_options);
    $doc = Json::decode((string) $response->getBody());
    $this->assertCount(0, $doc['data']);

    // Assign the alternate shortcut set to the current user.     $this->container->get('entity_type.manager')->getStorage('shortcut_set')->assignUser($alternate_shortcut_set$this->account);

    // 1 result because the alternate shortcut set is now assigned to the     // current user.     $response = $this->request('GET', $collection_filter_url$request_options);
    $doc = Json::decode((string) $response->getBody());
    $this->assertCount(1, $doc['data']);
  }

  /** * {@inheritdoc} */
  
'switch shortcut sets',
      'access shortcuts',
      'access content',
    ]);

    // Create a node.     $this->node = $this->drupalCreateNode(['type' => 'article']);

    // Log in as admin and grab the default shortcut set.     $this->drupalLogin($this->adminUser);
    $this->set = ShortcutSet::load('default');
    \Drupal::entityTypeManager()->getStorage('shortcut_set')->assignUser($this->set, $this->adminUser);
  }

  /** * Creates a generic shortcut set. */
  public function generateShortcutSet($label = '', $id = NULL) {
    $set = ShortcutSet::create([
      'id' => $id ?? strtolower($this->randomMachineName()),
      'label' => empty($label) ? $this->randomString() : $label,
    ]);
    $set->save();
    
$this->assertSession()->statusCodeEquals(200);
    $current_set = shortcut_current_displayed_set($this->adminUser);
    $this->assertSame($current_set->id()$new_set->id(), 'Successfully switched own shortcut set.');
  }

  /** * Tests switching another user's shortcut set. */
  public function testShortcutSetAssign() {
    $new_set = $this->generateShortcutSet($this->randomMachineName());

    \Drupal::entityTypeManager()->getStorage('shortcut_set')->assignUser($new_set$this->shortcutUser);
    $current_set = shortcut_current_displayed_set($this->shortcutUser);
    $this->assertSame($current_set->id()$new_set->id(), "Successfully switched another user's shortcut set.");
  }

  /** * Tests switching a user's shortcut set and creating one at the same time. */
  public function testShortcutSetSwitchCreate() {
    $edit = [
      'set' => 'new',
      'id' => strtolower($this->randomMachineName()),
      
Home | Imprint | This part of the site doesn't use cookies.