kiamlaluno's picture

I noticed that Backdrop core uses user_cookie_save() only for anonymous users, as the code expressly check that $user->uid is zero, before calling it.

Is there any issue, or known problem, when user_cookie_save() is used for registered accounts?

Accepted answer

Is there any issue, or known problem, when user_cookie_save() is used for registered accounts?

 

After a quick look through the code, it doesn't seem problematic. However keep in mind that the store values are used by the comment and contact forms to prepopulate values only for anonymous users - the stored cookie values are ignored if you are logged in.  

Is there any particular goal for storing these values in the Backdrop.visitor. cookies for logged in users? The values currently stored in the cookies are easy to obtain directly from the user (account) entity for the logged in user, except for homepage, which is currently not a field in the user entity.

If the goal is to use the cookie to store info for other purposes (other than the comment and contact forms), then I'd suggest avoiding user_cookie_save()and instad creating a custom function and a different cookie name to avoid issues with contrib etc.

Comments

Is there any issue, or known problem, when user_cookie_save() is used for registered accounts?

 

After a quick look through the code, it doesn't seem problematic. However keep in mind that the store values are used by the comment and contact forms to prepopulate values only for anonymous users - the stored cookie values are ignored if you are logged in.  

Is there any particular goal for storing these values in the Backdrop.visitor. cookies for logged in users? The values currently stored in the cookies are easy to obtain directly from the user (account) entity for the logged in user, except for homepage, which is currently not a field in the user entity.

If the goal is to use the cookie to store info for other purposes (other than the comment and contact forms), then I'd suggest avoiding user_cookie_save()and instad creating a custom function and a different cookie name to avoid issues with contrib etc.

Thank you for your reply! This is something I have wondered since Drupal 7. I have never found any pro in using user_save_cookie() and thought it should have been a "private" function.