- Issue created by @sidgrafix
- πΊπΈUnited States cilefen
The best way forward is to add validated steps to reproduce starting with a clean Drupal install.
- πΊπΈUnited States sidgrafix
OK "Steps to Reproduce" step by step (just did this with a fresh install of Drupal 10.2.6, PHP 8.1.16, Apache 2.4.38 Debian)
Step 1:
Go to/admin/config/people/accounts/fields
- Now add at least one field (I added 2 Number (integer) fields to be specific) with the "+ Create a new field" button.
For each field I set configuration as follows:
- Field Storage: Allowed number of values (Limited : 1)
- Set the Minimum value that should be allowed to: -1 (negative 1)
- Check on "Set default value"
- Set the default value to: 0
- SaveStep 2:
Go to/admin/structure/views
- Now add a view with the " + Add view" button.
Create the view with this configuration.
- Leave "View settings" default (Show: Content of type: All)
- Under Block settings, Check "Create a Block"
- Set the "Block display settings" to (Display format: Unformatted list of: fields)
- Set the "Items per block" to 1
- Click on Save and edit buttonStep 2B:
Configure the view block and add the user account fields we previously created:
- Under the "Advanced" section (right hand view column) expand it open if it is not.
- Across from Relationships click on the "Add" button to add a relationship to the view.
- In the Add relationship dialog find under Title "User" where Category is "Content" and the Description reads "The username of the content author"
- Next click on "Add and configure relationships" button at the bottom of the dialog
- In the Configure Relationship: User dialog, Don't make any changes and just click the "Apply" button at the bottom of the dialog.
- Next also under Advanced across from "Contextual filters" click add
- In the Add contextual filters dialog find under Title "User ID" where Category is "User" and the description reads "The user ID"
- Next click on "Add and configure contextual filters" button at the bottom of the dialog.
- In the Configure contextual filter: User: User ID dialog Where it says "When the filter value is NOT available" check the "Provide default value"
- In the "Type" dropdown that appears select: "User ID from route context"
- Leave everything else as is and click the "Apply" button at the bottom of the dialog.Step 2C:
- Now on the left column of the view display across from "Fields" click on the Add button.
- In the "Add fields" dialog find the field or fields you created in step 1.
- The "Category" should be "User" with a description that reads "Appears in: user." when you have it/them selected click on "Add and configure fields" button at the bottom of the dialog.
- In the "Configure field: User: Name of the Field" you can just hit the "Apply" button at the bottom of the dialog.
- When all field configuration is done and the dialog is closed click on the "Title" field listed under the Fields section above the field or fields you just added, when the dialog opens click the "Remove" button at the bottom of the dialog.
- Below fields (also in the views first column) where it says "Filter criteria" click on "Content: Published (= Yes) and when the dialog opens click on the "Remove" button at the bottom of the dialog to remove it.
- Next below that where it says "Sort criteria" click on "Content: Authored on (desc)" and when that dialog opens do the same as you did for the filter and click on the "Remove" button at the bottom of the dialog.
- Next under the views configuration and above the views preview area hit the "Save" button to save the view.Step 3:
Create a new user as an authenticated user, no admin privileges and give value to the new account fields:
Go to:/admin/people
- Click the "+ Add user" bottom near the top of the page.
- Provide the "Username" and add a "Password"
- Under Roles "Authenticated user" should be checked by default and grayed out.
- Scroll to the bottom of the add user form and locate your added field or fields and give them values. (I set the first field of my two to "2" and the second number field to "4")
- Then at the bottom of the form hit the "Save" button.Step 4
Place the view block on user account pages:
Go to:/admin/structure/block
- Scroll down to either a "Content" region or a "Sidebar" region (I used the right sidebar)
- When your at the region you want to use click on the "Place block" button to the right of the region name you are using.
- In the "Place block" dialog find the view block you created by name (using the search field and typing in part of its name should bring it right to you, its category will read "Lists (Views)" and under "Operations" click on the "Place block" button that is displayed to the right of the view block name.
- In the Configure block dialog under "Visibility" click on the "Pages" tab.
- In the Pages input field put/user/*
and make sure "Show for the listed pages" is checked
- Depending on what you named the view and if you added a block name the "Machine-readable name" may be to long and you will have to shorten it to save the block.
- Finally click on the "Save block" button at the bottom of the dialog.Step 5:
Now visit the users page:
Go to:/admin/people
- In the user list under "Username" find the user you just created and click on the name to go to their user account page (as admin doesn't matter if users can see each others account pages)
- You should be at:/user/2
(if there is only you the admin and 1 user account the path would be /user/2 otherwise it will be /user/[user-id].What you will see is unexpected:
- Under the user account details you will see the two fields with the values you set
- However...The view block will only have the title of the view block and there will NOT be any field data and if you inspect the html the view content is empty. I would expect to see the same information displayed by the fields and clearly is not.I'll include a screen cap of the new user account page at this point (fresh-install-same-issue.jpg).
Now if you want to give your new test user the ability to add an article or basic page you will also need to grant the "Authenticated User" role to allow it - if you do and you login as the new test user and create an article or basic page and then view their user account page admin or the user you will see the block then has the field information.
-> If you need instructions on how to do that let me know!Couple of things to note (I did straight basic setup for the steps to reproduce) but there are reasons why I did a few things that you wouldn't get from this setup and may explain why I chose the view type I did for our use case.
1. I used a view to display content not user because for my use case I need content worked into this display seamlessly using attachments that also relate to the user and there content (which they may not have any especially when they are a new account)
2. The actual fields created on user accounts can only be set or updated by an admin or the corresponding module being developed to work with those fields on behalf of the user. The user has permission to view their field info (thus why it would be able to display in a view block), but they cannot change it. Furthermore the default fields are even hidden for our use case. As we just need it displayed in a block that does a lot more than just display the field info/data.Any questions or problems let me know.
- πΊπΈUnited States cilefen
Thanks for that. That information will be most useful if it is in the issue summary rather than in a comment. This template β is normally used in that way.
- πΊπΈUnited States sidgrafix
Just to add to the issue:
I just found that deleting a users node if they only had one - also produces the same issue and the account fields are not rendered in the view block. Guess it's time for a workaround...
- π³πΏNew Zealand quietone New Zealand
Fixes are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies. Also, 10.2 is in security mode now.