Provide Views argument for current user's profile ID

Created on 14 December 2016, over 7 years ago
Updated 8 April 2024, 3 months ago

Problem/Motivation

When constructing a view of profiles, a Profile ID contextual filter can be added.

A potentially common use case for the contextual filter is a profile of the current user. For example, if I'm building a view to allow a user to browse other users' profiles, I would want to add a contextual filter for the user's Profile ID, so that I could exclude their own profile from the results.

Another instance is in #2835638: Proximity filter when argument is not on primary table . The Geolocation module allows sorting a view of profiles by proximity, but requires an argument that provides the profile ID of the user to calculate proximity to.

However, there is currently no default argument for a profile of a current user.

Proposed resolution

  • Provide a default views argument value for the current user's ID for a given profile type.
  • In the argument configuration form, provide a select element for the profile type. Show only profile types that don't support multiple profiles.

To test:

  • Install Drupal core and then install the Profile module.
  • Create a new view of profiles.
  • Add a contextual filter "Profile ID".
  • Configure the contextual filter to use a default value of "Current user's Profile ID".

Remaining tasks

Write unit test coverage. Can be adapted from similar unit tests in core for views arguments.

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

🇨🇦Canada nedjo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024