Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display profile data on layouts #12

Closed
oadaeh opened this issue Jul 26, 2022 · 11 comments · Fixed by #28
Closed

Display profile data on layouts #12

oadaeh opened this issue Jul 26, 2022 · 11 comments · Fixed by #28

Comments

@oadaeh
Copy link
Contributor

oadaeh commented Jul 26, 2022

Is it possible to add profile fields to a layout, and if so, how?
I've been playing with it for a few hours, even creating a LayoutRelationship handler, but the data only displays on the normal user page.

@argiepiano
Copy link
Contributor

I believe this is not possible at the moment, as Profiles are custom entities. I'm pretty sure Layouts don't support custom entities as contexts, and therefore it's not possible to access their properties, or fields attached to them.

I also need this feature for my own custom entities, so I will (at some point) try creating a contrib module to expose these. I'll keep you posted (or perhaps you beat me to it? :)

@docwilmot
Copy link
Member

Hi @oadaeh did you mean the whole profile as a block or individual fields from the Profile? We can expose Profiles as blocks using relationships, and could likely do same with Profile fields, but I'm feeling like exposing every Profile field might be a lot of fields blocks. Or maybe not. What would be most in demand though?

@argiepiano
Copy link
Contributor

argiepiano commented Oct 5, 2022

@oadaeh, a workaround to show Profile fields in blocks is:

  1. Patch Profile with BOTH Issue #13. Make Profile Rules-ready #14 and Issue #15. Implement bundle() #16
  2. Enable Entity Tokens and Entity Plus
  3. Enable Token Block
  4. Create a layout to display user accounts (e.g. with a path user/%)
  5. Add a Tokens for user account entities block to the layout
  6. Type a token such as [user:profile_main:FIELD_NAME]

That will display that field from the main profile. If you have created other profile types, then you'll need to use profile_MYTYPE in the token.

All that thanks to the magic of Entity Tokens and Token Block!

@bugfolder
Copy link
Collaborator

Version 1.1.1 of Profile has been released, which incorporates both patches in Step 1 above.

With this release, the workaround described in the previous comment meets the need of this issue, but that approach (adding 3 contrib modules) is not at all obvious to the average user, so I'm wondering if we should add @argiepiano's prescription to the "Usage" section of this module's README. Thoughts?

@docwilmot
Copy link
Member

I had a branch that enables a Profile block in any layout with a User context. We could incorporate this or provide a separate module. Any thoughts? I had paused to ask the question above, which is do we want individual Profile fields or entire Profiles as a block (the latter is what I've got so far).

@bugfolder
Copy link
Collaborator

Adding the entire Profile as a block would be a great addition (and for large profiles, much easier than lots of tokens).

docwilmot added a commit that referenced this issue Oct 15, 2022
@docwilmot
Copy link
Member

I've pushed the Profile block branch. To test create a layout for user/%, or a node/% layout with an Author relationship.

@argiepiano
Copy link
Contributor

This looks great, @docwilmot - thanks for providing.

I do have a suggestion: it would be helpful to add some configuration to the block, so that the user chooses which display mode to use for displaying the profile. And then use that option to build the view of the entity using profile_view($profile, $view_mode) instead of manually building the render array as you are currently doing.

To get a list of all defined view modes, you can use $info = entity_get_info('profile'); and get array_keys($info['view_modes']);

You can even consider letting the user choose between the default language or another installed language in the settings ui, and then pass that as the 3rd parameter of profile_view.

@docwilmot
Copy link
Member

Good points

@oadaeh
Copy link
Contributor Author

oadaeh commented Jan 23, 2023

Wow! You all carried on without me. I totally forgot I even created this issue. ☹️
I don't remember what I was trying to accomplish, but I was probably trying to do some custom field arrangement and grouping in a grid to separate parts of a profile on the same page.
Thanks for pushing this forward without me @argiepiano @docwilmot and @bugfolder ! 😅
I'll take a look at the new changes, but I first have to remember what I was doing with them. ☹️

oadaeh added a commit to oadaeh/profile that referenced this issue Jan 23, 2023
@oadaeh
Copy link
Contributor Author

oadaeh commented Jan 23, 2023

That commit was me incorrectly adding a 12, instead of a 20, to my branch name, comment, etc. for this issue instead of issue #20.

bugfolder added a commit that referenced this issue Nov 13, 2023
Issue #12: Display profile data on layouts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants