Score:2

is it possible to make use of data stored using the user.data service ifor filtering views?

za flag

Allowing a user to bookmark a node i have created

 public function bookmark($nid,$uid) {
    $user_data = \Drupal::service('user.data');
    $bookmarked_nodes = $user_data->get('my_module', $uid, 'bookmark');
    $bookmarked_nodes[$nid] = $nid;
    $user_data->set('my_module', $uid, 'bookmark', $bookmarked_nodes);
    \Drupal::messenger()->addStatus(t('node bookmarked.'));
  }

i would like then to create a view listing only nodes that has been bookmarked by the current user.

Is it possible ?

Score:1
in flag

Better use the Flag module for a more robust bookmarking solution. Allows you to record a "flag" made by user (in this case, a bookmark) and has a ready-to-use Views integration to filter flags and relate the both user and the flagged entity.

Matoeil avatar
za flag
The module is not stable yet
in flag
@Matoeil Unless you have a company policy against unstable modules or modules not covered by Drupal security, it's stable enough for use. I would use Flag than reinvent the same thing myself (and have something even more unstable). Besides, if you find any flaws, you can always patch the module yourself with [`cweagans/composer-patches`](https://github.com/cweagans/composer-patches).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.