Hello i have created one plugin to integrate the profile2 system for the new drupal 7
this is my first patch/addon, so please can anyone review it and probably add to ctool module.

With this module you can choose one of created profile types and display it on every page you want

currently it works only if you have not checked "Provide a separate page for editing profiles." in the profile settings

CommentFileSizeAuthor
#104 profile2-ctools-relationship-from-user-1011370-104.patch3.05 KBSpleshka
user_profile2.inc_.zip1.22 KBleonsio
#11 user_profile2.txt2.51 KBericbroder
#17 profile2-ctools.patch6.38 KBandypost
#21 1011370-profile2-ctools.patch6.4 KBandypost
#38 profile 2 context b.jpg30.4 KBcalefilm
#38 keyword duplicate a.jpg18.22 KBcalefilm
#54 profile_ctools.png27.16 KBandypost
#54 profile_entity_api.png22.83 KBandypost
#54 relations.png10.63 KBandypost
#54 1011370-profile2-ctools-54.patch6.55 KBandypost
#57 profile2_panels_context.jpg76.79 KBCountzero
#82 profile2-1011370-82-ctools-relationship-from-user.patch6.62 KBjoshf
#84 profile2-1011370-84-ctools-relationship-from-user.patch5.99 KBjoshf
#86 profile2-1011370-85-ctools-relationship-from-user.patch5.96 KBjoshf
#87 1.png192.73 KBMKorostoff
#87 2.png190 KBMKorostoff
#87 3.png195.33 KBMKorostoff
#87 4.png419.1 KBMKorostoff
#87 5.png239.29 KBMKorostoff
#87 6.png292.21 KBMKorostoff
#87 7.png199.89 KBMKorostoff
#87 profile2-ctools-relationship-from-user-1011370-87.patch3.64 KBMKorostoff
#87 interdiff.txt4.69 KBMKorostoff
#91 profile2-ctools-relationship-from-user-1011370-91.patch3.5 KBMKorostoff
#91 1.png154.32 KBMKorostoff
#91 2.png617.62 KBMKorostoff
#91 3.png620.69 KBMKorostoff
#91 4.png487.67 KBMKorostoff
#97 profile2-ctools-relationship-from-user-1011370-97.patch4.59 KBMKorostoff
#97 interdiff.txt1.49 KBMKorostoff
#100 profile2-ctools-relationship-from-user-1011370-100.patch4.26 KBMKorostoff
#100 interdiff.txt2.11 KBMKorostoff
#101 interdiff.txt2.76 KBSpleshka
#101 profile2-ctools-relationship-from-user-1011370-101.patch3.06 KBSpleshka
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Status: Needs review » Closed (won't fix)

profile2 is not a core feature. I assume it's a contrib module. It should provide the plugins. If the maintainer of profile2 does not want that, then a 3rd profile2_extras module or something should be created to offer these plugins.

With 5,000+ contrib modules and a robust API, CTools can't keep code for them.

merlinofchaos’s picture

Project: Chaos Tool Suite (ctools) » Profile 2
Component: Plugins system » Miscellaneous
Status: Closed (won't fix) » Needs review

Sending over to profile 2 -- maybe it's useful.

Note that CTools has a patch to handle at least some of the entity stuff automatically, and I don't know if that patch would end up superceding this stuff or not.

fago’s picture

Title: Profile2 Intergation » Ctools integration

Probably it would. Also probably Ctools could make use of entity relationships that the entity API is aware of via hook_entity_property_info()? Then we'd get profile2 support too, as well as many others.

andeim’s picture

Doesn't work for me...
I uploaded it in sites/all/modules/profile2/plugins/content_types
I don't see any profile2 in all tab' s panel...
"Provide...." is not checked and i tried to uninstall "separate page" module but no results.

So what is the solution or the way to display some profile type in panels ? :-)

Regards

zarudnyi’s picture

Thank you Leonsio.
Plugin works fine.

ben kuper’s picture

Same as andeim,
how to use it ?
Tried to integrate it in the profile2.info files[] but no sucess..

Jerome F’s picture

I'm also looking for the way to display some profile type in panels.

Jerome F’s picture

I tried to add a context for the profile type I created, it worked, but then this error shows up :
and there's nothing new in the content to be added related to profile.

* Notice : Undefined offset: 1 in ctools_context_create_entity() (line 80 dans (...)/public_html/sites/all/modules/ctools/plugins/contexts/entity.inc).
* Notice : Undefined offset: 1 in ctools_context_create_entity() (line 80 dans (...)/public_html/sites/all/modules/ctools/plugins/contexts/entity.inc).
* Notice : Undefined index: context_entity:profile2_type_1 in theme_ctools_context_list() (line 200 dans (...)/public_html/sites/all/modules/ctools/includes/context.theme.inc).

I also looked for a way to use the profile page /profile-artist_profile/1 (http://drupal.org/node/1074296) and insert it as a node, but I'm not quite sure this is a node actually... Can't find the nid, nothing shows up in the site content about the profile...

Jerome F’s picture

A nice work around which worked for me is to create a view of the type profile, with profile fields and create a view content pane display and add it to the panel page. It's appropriate I think as then I can control markup, labels and classes in views.

Shadlington’s picture

Subbing

ericbroder’s picture

Component: Miscellaneous » Code
Status: Needs review » Needs work
FileSize
2.51 KB

Here's a txt version of the inc file in the original attachment. Looks like mostly a copy of plugins/content_types/user_context/user_profile.inc from ctools module. Definitely needs work.

Chaos Tools (CTools) Plugin Example module is useful for writing new plugins. For example:

Module setup and hooks

Your module must provide a few things so that your plugins can be found.

First, you need to implement hook_ctools_plugin_directory(). Here we're telling CTools that our plugins will be found in the module's directory in the plugins/<plugintype> directory. Context plugins will be in ctools_plugin_example/plugins/contexts, Content-type plugins will be in ctools_plugin_example/plugins/content_types.

<?php
function ctools_plugin_example_ctools_plugin_directory($module, $plugin) {
  if ($module == 'ctools' && !empty($plugin)) {
    return "plugins/$plugin";
  }
}
?>
Shadlington’s picture

I believe the patch mentioned in #2 was #1138708: Auto create "content-type" CTools plugins from tokens and was committed. So is this now resolved?

Jerome F’s picture

When I add the Relationship Profile from User (on profile.uid) to the panel context, the following error message is appearing:
An illegal choice has been detected. Please contact the site administrator.

If I ignore this and go on adding some content from the profile2 fields to the panel, I receive the error documented in this issue: http://drupal.org/node/1186702

No content is printed on the page.
When I use the customize this page button, I have many panes with that type of error :
Placeholder for empty "entity_field:profile2:field_subscriber_about_text will not display due to missing context"

geshido’s picture

Hello,

Is there any quick solution to add a condition of Profile2 type when adding it as a Relationship in Panels "Contexts" tab?
Now there is common "entity_from_schema" relationship plugin used, but it takes profile2 object of random type.

Thanks a lot.

andypost’s picture

Suppose when adding relation there's should ability to choose a bundle to use for relation

EDIT: And big +1 to current patch

elBradford’s picture

Category: feature » bug

Hope this is still coming along. An issue that is directly related to what a lot of us need #1100956: Profiles and Ctools/Panel integration issues has been closed and is redirecting us here, but this one seems kind of dead. Just want to encourage anyone who can help that this is needed. Thanks for all your hard work!

I personally think this is a bug since you can add profile2 fields to panels easily, they just don't show up. I'm marking it that way, feel free to change it though if I'm wrong.

andypost’s picture

Status: Needs work » Needs review
FileSize
6.38 KB

Patch introduces a content_type and relation from user plugins

I think this is minimal required integration.

1) having user in context now it's possible to add relation to a profile type and display separate fields

2) content type allows to display profile2 entity of selected type in different build modes

andypost’s picture

The only thing I thinking about to implement forms for editing, but still not found a good example....

Status: Needs review » Needs work

The last submitted patch, profile2-ctools.patch, failed testing.

fago’s picture

Category: bug » feature
andypost’s picture

Status: Needs work » Needs review
FileSize
6.4 KB

Standard patch with -p1

Status: Needs review » Needs work

The last submitted patch, 1011370-profile2-ctools.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review

The test bot broken because dependency on entity module & seems OG

elBradford’s picture

fago,

Care to address why this is a feature request and not a bug? If profile2 fields appear to be usable in panels but aren't I think that's a bug. I'm interested in your perspective.

Bradford

fago’s picture

>If profile2 fields appear to be usable in panels but aren't I think that's a bug.

Profile2 does not integrate with ctools yet. If something of profile2 appears there, I guess this is some generic integration provided by ctools. Thus you should file an issue over there.

fago’s picture

for displaying a profile see #1325126: uninstallation troubles due to outdated entity info, what contains a patch for generic entity display. Please test it with profile2 and report there whether it works for you.

What maybe remains is a possibility to get the profile context from a user context. Or is that magically working via's Ctools foreign-keys schema-magic?

fago’s picture

elBradford’s picture

I'm on the rc1 of Entity, rc1 of ctools, and 3.0 of panels (stable) and 1.2 of profile2 (stable) - I can get some profile2 fields to now show up but they show the wrong user - in the panels context settings I have it set up to get the profile from the "user being viewed" however it shows some random user's information. It's a big step forward but I think it might be confused. Or I'm confused, but it's not working as expected :) I'm not sure what changed either, it might be when panels was updated recently but I'm not sure. I also got the current dev release of entity however that didn't change anything.

bryancasler’s picture

Reporting the same problem as elBradford. I'm using Display Suite with panels integration and the semi-recent releases of everything.

Jan 03 - Profile 2 v1.2
Jan 17 - Display Suite dev
Jan 18 - Panels v3.0
Jan 23 - Ctools dev
Feb 15th - Entity API dev

UID 1 shows the next lowest UID's profile information.
Every other user profile is completely blank.

I've tried all configurations imaginable, nothing seems to get it working. In one configuration I do get these warnings.

Notice: Undefined index: #profile2 in ds_extras_render_panel_layout() (line 934 of C:\xampp\htdocs\playground6\sites\all\modules\ds\modules\ds_extras\ds_extras.module).

EntityMalformedException: Missing bundle property on entity of type profile2. in entity_extract_ids() (line 7500 of C:\xampp\htdocs\playground6\includes\common.inc).

Not sure if that helps any.

fago’s picture

I guess the Ctools user-profile2 relation is broken. To verify this is the problem, please try using the render-plugin with a profile2 specified by profile-id (!= user id).

Jody Lynn’s picture

The ctools relationship uses entity_from_schema.inc based on the fact that profile2 has a foreign key for uid. This relationship does not actually work to get a profile from a user because there is no profile id on the user entity, and there cannot be as there may be multiple profiles. We should get rid of this relationship in the interface since it doesn't work. Possibly we need to remove the foreign key from the schema?

The patch in #21 works well to add the relationship properly though.

nagiek’s picture

Hi all,

I wrote a patch to get profile2 from a user context over at #1273026: Profile2 context from relationship doesn't work. Feel free to use it!

andypost’s picture

@nagiek Your patch should be marked as duplicate of this issue.
#21 already has the same implementation of relation plugin

andypost’s picture

#21: 1011370-profile2-ctools.patch queued for re-testing.

bryancasler’s picture

Did the test bot get stuck?

fago’s picture

Status: Needs review » Needs work

We already have rendere-entity ctools support via the entity api, so no need to include this here. Another issue is the broken relationship. Still, couldn't we do the entity relationship easily via the entity api's property api + wrappers generically? I guess so, so let's better do that. (feel free to create an appropriate issue in the entity api queue and link it here)

calefilm’s picture

I can't add much to the discussion here... other than to say that I tried the patch in #21 and it worked, but I still don't see the fields pop up in my substitution list... What gets me really frustrated.. Yesterday I didn't need to apply any patches. Everything worked fine! But I made some adjustments to my users and messed around with the content types.. then went back to the panel and all of a sudden the new profile's keywords weren't popping up in my substitution list.. and if selected individually in the pane, they don't appear. So am frustrated that it's not just automatically working like it was yesterday.

I had 7x-1.2 installed and 7.x-1.0-rc3 installed. Anyway, patch works, I can add the fields to my pane, but i cannot use any keyword substitutions in any custom pane..... like i could yesterday. So very confused. I almost thought I couldn't use Profile 2 anymore as I couldn't add any fields to my Panes! So without this patch can I not use Profile 2? Will the next version have this included? I'm a rather newbie so sorry for the questions but trying to pinpoint what I'm doing wrong.. or right at this point so i can use this module.

calefilm’s picture

Just a quick update to my thread above regarding 'keywords': I found out that when I install Entity Tokens along with Entity API i get duplicates in my keyword substitutions list (so they do appear in the list--just don't work). As I stated before, I had this working without the patch in #21.. but now when I add keywords from my substituions list in custom panes they don't appear. So just for my own notes: I can't use Keywords in custom panes but if I use patch in #21 I can add fields to pane just fine. Don't understand duplicate issue so I will disable entity tokens.

andypost’s picture

Suppose each of contexts should have own name

ajmartin’s picture

any updates for #21: 1011370-profile2-ctools.patch being committed?

Edit: Just applied the patch, and while the relationship Profile from User (on profile.uid) now works, only fields on the first (lightest) profile type are displayed on the page. I can add fields from other profile types in panels, but no display.... Is there a patch for this?

Anonymous’s picture

Changes to profile2.module "@@ -781,3 +781,11 @@ function profile2_user_get_properties($account, array $options, $name) {" are not accurate in 1.2 or dev versions and removal causes WSOD.

Code starts on line 807 not 781 in 1.2 version and includes "$profile = profile2_load_by_user($account, substr($name, 8));"

function profile2_user_get_properties($account, array $options, $name) {
// Remove the leading 'profile_' from the property name to get the type name.
$profile = profile2_load_by_user($account, substr($name, 8));
return $profile ? $profile : NULL;

Cannot apply patch.

sevanden’s picture

Applied the patch and it works but only for user 1 (admin).
Any fields from other users are not being displayed in mini panels, there are not even values retrieved for them. Verified by overriding the Title in the mini panel.

ajmartin’s picture

Profile Lite is an alternative that plays nicely with Panels.

areynolds’s picture

Regarding the lack of field substitution tokens, from a glance at the debugger it seems that the Profile2 relationship (created from the patch in #21) utilizes the entity ctools plugin to attempt and generate a list of tokens (see ctools/plugins/contexts/entity.inc). However, when this plugin runs token_info(), no information about profile2 tokens is found. Perhaps this is because Profile2 doesn't implement hook_token_info(), so no token information is generated?

This make sense to anyone who knows the token system?

andypost’s picture

Because ctools has broken token support for now. See #1727804: Keywords substitution doesn't work as expected

areynolds’s picture

Thanks andypost, although I think the confusion was mostly my own; apparently entity_token wasn't enabled on my project. Enabling them made the tokens available, although I'm experiencing calefilm's problem of duplicated tokens in the substitutions list (comment 38).

Without entity_token, the token substitution list is not generated and token keywords do not work.

marcus_w’s picture

Status: Needs work » Needs review

#21: 1011370-profile2-ctools.patch queued for re-testing.

fago’s picture

Status: Needs review » Closed (duplicate)

Entity API 1.0 ships with the entity render plugin - so what's left is having the relationship to the profile entity. I still think this should be provided by the entity api module in a generic fashion

Anyway let's use the dedicated issue for tracking this: #1834920: Create profile2 ctools relationship context from node

fago’s picture

Title: Ctools integration » Ctools relationship from user
Status: Closed (duplicate) » Needs work

Realized #1834920: Create profile2 ctools relationship context from node is about relationships from nodes, re-opening this one.

fago’s picture

Let's implement this in a general fashion in the entity api module: #1874006: Expose entity references as CTools relationships

Leaving this issue open as a reference and issue for discussions specific to profile2.

andypost’s picture

Status: Needs work » Needs review

#21: 1011370-profile2-ctools.patch queued for re-testing.

andypost’s picture

@fago I don't think that it's possible to introduce a generic relation here because we should choose a type of profile to relate else we get a multiple records. So both plugins uses a settings to choose a profile type

+++ b/plugins/content_types/profile2.inc
@@ -0,0 +1,134 @@
+  'defaults' => array('type' => 'main', 'build_mode' => 'account'),

Profile type is required here, so generic render does not work

+++ b/plugins/relationships/profile2.inc
@@ -0,0 +1,59 @@
+  'edit form' => 'profile2_from_user_settings_form',
+  'defaults' => array('type' => 'main'),

Same here

andypost’s picture

Suppose we should change a required context from deprecated "user" to "entity:user"

andypost’s picture

Re-roll with #53 changes. tested locally.
The only trouble here that entity API adds another relation without pointing profile type

There's 2 relation types
relations.png

Standard relation does not allows to choose a profile type
profile_entity_api.png

After patch - the second relation works as expected
profile_ctools.png

fago’s picture

We already expose per profile-type relations to the entity API, see profile2_entity_property_info_alter(). Once we let entity api expose this to ctools we should be fine.

The other relation stems from ctools itself which parses schema information. Not sure whether we can disable or overwrite this relationship.

andypost’s picture

makes sense. also we need a context/relation plugins to allow deeper relations to be attached

for example add relation to business profile and then add relation to company (node reference) from this profile

Countzero’s picture

FileSize
76.79 KB

Excellent patch, but I get an error when saving (see attached screenshot : sorry for the french stuff).

I have two profile2 types, with one variant for each, selection rule based on respective roles. Everything works with the first, but not with the second.

I thank you a lot for your work on this. It's extremely useful for my use case (and probably for anything involving Panels and advanced user management).

Countzero’s picture

Found this http://drupal.org/node/1257336#comment-5680366 when trying to search d.o for hints.

The issue (which originates from the same type of error message) seems to boil down to a problem with the global $user object, which is not a fully loaded one.

I guess you core coders are aware of this, but wanted to mention it just in case.

capynet’s picture

#54: 1011370-profile2-ctools-54.patch queued for re-testing.

capynet’s picture

Status: Needs review » Reviewed & tested by the community

#54 solves the problem. +1

Rosamunda’s picture

I´ve just installed this patch (that seems to affect: ctools/plugins/content_types/profile2.inc, ctools/plugins/relationships/profile2.inc, and profile2/profile2.module).
I can confirm that it works and solves the problem.
I´ll keep testing it just in case it produces any errors, but it works.
Is it going to be committed?
Thanks!

spyderpie’s picture

Much needed here too! Would love to know when its committed .. subscribing ;)

spyderpie’s picture

Patch works WELL!!!!! Thank You!!!!!

I did have to have the dev version of entity API installed ;)

DamienMcKenna’s picture

+1 for the patch in #54, it resolved a massive confusion I had trying to access the Profile2 data, good work! That said, I'll follow #1874006 to see what comes of the "correct" fix.

Frank Ralf’s picture

queenvictoria’s picture

#54 Fixes it for me. Reviewed +1. Can we get it in please?

jeroen_drenth’s picture

#54 works well for me too. Can you please commit?

letrotteur’s picture

#54 works well for me. There are many issues regarding this and got a bit confused about what was going on. But #54 works so I'll just go with it as of now. Thanks.

ergophobe’s picture

#54 works for me too.

Triumphent’s picture

#54 seems to work for rendered elements but not for field edit forms (like the profile owner wants to change the content of the fields.) Am I missing something or was the issue of the field edit forms not addressed in this thread?

andypost’s picture

@fago this patch lacks only form relation pligin, and because profile2 attaches only via extra field to user entity I see no other relation plugins able to solve the issue, ER does nothinh about standard profile2 setup.

See profile2_field_extra_fields()
1) forms profile2_form_user_profile_form_alter() & profile2_form_user_register_form_alter()
2) render profile2_user_view()

stewart.adam’s picture

Does anyone have any ideas about #1965148: Load the full Panelizer default object? After applying the patch in #54 it works very well, but only on the user view (user_view at /user/%user). When editing any other panels, I can add the user context and this profile relationship but no fields become available to add.

jhedstrom’s picture

Not sure what the state of #1874006: Expose entity references as CTools relationships is, but the patch in #54 works great.

The really confusing thing without this patch is that individual profile2 fields appear as ctools content in the admin UI, they just fail to work when viewing the saved panel.

sk33lz’s picture

Confirming that #54 works even with profile2-7.x-1.3. Let's get this patch committed, so you can close this 3 year old issue.

jsibley’s picture

Issue summary: View changes

Is there a decision not to commit the patch from #54, over 1 year ago?

If so, is there another solution that has been committed in the meantime?

Thanks.

DamienMcKenna’s picture

@jsibley: There has not been a decision to not commit the patch, there has just been no effort to maintain the project in almost a year.

johnkingeu’s picture

Commit commit commit :-)

fago’s picture

Status: Reviewed & tested by the community » Needs work

The relationship looks good, but we do not need the entity render plugin. Entity api already provides that generically. -> Needs work.

There is also a patch for #1874006: Expose entity references as CTools relationships which would provide the feature as well, but as noted there it provides worse UX. So adding this relationship here also would be fine with me.

ad #76: Yep, I had to less time to maintain profile2 properly recently as core eats up all my contribution time. Luckily, a co-maintainer has stepped up - see #2202231: Co-maintainership request.

sketman’s picture

Has the patch been commited please?

DamienMcKenna’s picture

Issue tags: -profile2

@sketman: The issue's status of "needs work" indicates that it has not been committed.

rerooting’s picture

Patch #54 is no longer applying!

joshf’s picture

Re-rolled patch from #54.

MKorostoff’s picture

The patch in #82 works for me

joshf’s picture

Status: Needs work » Needs review
FileSize
5.99 KB

Removed profile2_profile2_content_type_render() per #78.

Status: Needs review » Needs work

The last submitted patch, 84: profile2-1011370-84-ctools-relationship-from-user.patch, failed testing.

joshf’s picture

Status: Needs work » Needs review
FileSize
5.96 KB
MKorostoff’s picture

FileSize
192.73 KB
190 KB
195.33 KB
419.1 KB
239.29 KB
292.21 KB
199.89 KB
3.64 KB
4.69 KB

joshf, I think you may have missunderstood fago earlier. It's not the the render function isn't necessary, it's that the entire content_type plugin (plugins/content_types/profile2.inc) )isn't necessary, because the same thing is currently available from entity API, even without this relationship.

What is available right now, without this patch

You can embed any profile, using any view mode, on any panel page
profile types

view modes

This becomes available as soon as the "User" context is added like so:
user context

I have attached a patch that removes the duplicated functionality from #85. I like the user experience in #85 better, but there's no sense in duplicating core functionality provided by entity API.

What is available after this patch is applied

adding relationships

adding visibility criteria

adding selection rules

embedding individual fields

One last thing is that, as you note, the default profile relationship supplied by entity API really adds no value for us, and the relationship provided by joshf is clearly superior. In my updated patch, I have removed the default entity API relationship from the page manager relationship selector.

Spleshka’s picture

For me #87 looks pretty good. Does anyone againts commiting this? Otherwise I will test myself and then commit.

kristiaanvandeneynde’s picture

Such forms are provided by a CTools plugin, so they should be alterable just like any form. I would, however double-check that this is the right solution before committing it :)

  1. +++ b/profile2.module
    @@ -1058,3 +1058,21 @@ function profile2_ctools_plugin_directory($owner, $plugin_type) {
    + * option, and provide out own relationship.
    

    our own*

  2. +++ b/profile2.module
    @@ -1058,3 +1058,21 @@ function profile2_ctools_plugin_directory($owner, $plugin_type) {
    +  if (isset($form['right']['relationships_table']['buttons']['relationship']['item']['#options']['entity_from_schema:uid-user-profile2'])) {
    +    unset($form['right']['relationships_table']['buttons']['relationship']['item']['#options']['entity_from_schema:uid-user-profile2']);
    +  }
    

    No need for the isset() if the array $form exists (which it does)

Spleshka’s picture

The one thing I am really affraid is that someone could already use entity api core behavior, and with #87 patch we will kill that integration and site will be broken. Of course, it will be broken only after form is resaved, but I think that we have to provide an update to avoid this situation. So for me current status becomes NW.

MKorostoff’s picture

FileSize
3.5 KB
154.32 KB
617.62 KB
620.69 KB
487.67 KB

Thanks for the feedback kristiaanvandeneynde and Spleshka. The patch attached to this comment implements both of the suggestions from kristiaanvandeneynde.

Spleshka I had the same concern about breaking existing relationship, but I think the patch in #87 deals with that in the most reverse compatible way possible. Note that all I'm doing to prevent users from adding the default Entity API relationship is removing the option from the "Relationships" select list. I'm not actually altering (or removing) the default ctools entity relationship.

Test Case: A user with an Entity API relationship to a Profile edits their panel page, AFTER applying this patch

1. A user defines a panel page using the default entity API relationship. This panel page contains a Profile2 field that was made available by adding the relationship.
default relationship

2. The user updates Profile2 to the latest dev version, including this patch. The user opens their panel editor. The user should see that their default entity API relationship is preserved.
Default relationship preserved

3. All functionality provided by the default entity API relationship is preserved.
default behaviors preserved

4. The user saves the panel editor form. The panel page continues to work as before.

5. The user attempts to define a new panel page. The user is forced to use our new relationship, the default entity API relationship is not available.
new panel page

kristiaanvandeneynde’s picture

Status: Needs review » Reviewed & tested by the community

Looks good from the screenshots, the logic behind them and the code.

Off topic: #87 and #91 are some of the most thorough patch providing comments I've ever seen on d.o., great work!

MKorostoff’s picture

haha, thanks kristiaanvandeneynde

Spleshka’s picture

Status: Reviewed & tested by the community » Needs work

@MKorostoff, thanks for your new patch! I tested it, everything looks amaizing. Just one small issue: when panel has no context and then you add new user context => in relationships list you still see core Entity API relationship to profile2. And after page reload it disapears.

I debuged a little bit and noticed that somewhy hook_form_FORM_ID_alter() was not invoked. After solving this small problem we can finally commit this, because I really like how patch works! I just have a feeling that this bug may confuse users because of having two similar relationship names.

MKorostoff’s picture

Good catch, I'll take a look after work today

Spleshka’s picture

Would be great :-) Looking forward to commit this.

MKorostoff’s picture

Thinking about this a little closer, if we're committing to not altering the default relationship (which I think we all agree on) then I'm pretty sure that suppressing the first appearance of "Profile2 from user" comes down to two options:

Option 1) hook_preprocess_select, which I'm super uncomfortable with, because it would be called all the time by thousands of different modules.

Option 2) Drupal.behaviors. I think this is the cleaner, safer option, because we can choose to load our custom JS only on the panel editor page, thus limiting the impact to be extremely narrow.

A patch implementing option 2 is attached.

MKorostoff’s picture

Status: Needs work » Needs review
Spleshka’s picture

Status: Needs review » Needs work

Aha, I see these two options. To be honest, they both look like a workarounds :) Current output of entity relationships are generated somewhere, and we need to alter function that doing this (or at least its output). If you have no time to do this, then I'll try to find some time myself to find out where this list is generated.

P.S. No worries, patch authorship will be yours, you deserve it ;)

MKorostoff’s picture

Status: Needs work » Needs review
FileSize
4.26 KB
2.11 KB

Spleshka you are exactly right! Thank you for pushing to make this the best it can be :). I had a good hard look at ctools_context_ajax_item_add and I saw that it bypasses form_alter by calling form_builder() directly. Though ctools_context_ajax_item_add doesn't provide an explicit alter hook, it does make proper use of the theme system. Which allows us to do this:

function profile2_preprocess_ctools_context_item_form(&$vars) {
  unset($vars['form']['buttons']['relationship']['item']['#options']['entity_from_schema:uid-user-profile2']);
}

Huzzah! Updated patch attached.

Spleshka’s picture

Aha, very cool that you love to make a perfect solutions! So, I've tested this patch also and noted that now we don't need hook_FORM_ID_alter() anymore, because profile2_preprocess_ctools_context_item_form() completely covers both cases of relationship display. I removed this hook from patch and made minor changes. Please, review/test it, and then we are ready to commit it.

The last submitted patch, 101: profile2-ctools-relationship-from-user-1011370-101.patch, failed testing.

kristiaanvandeneynde’s picture

Changes (code) look good, even though testing fails.

Spleshka’s picture

Forgot to add new folder to patch ;) New patch attached.

MKorostoff’s picture

Status: Needs review » Reviewed & tested by the community

I've tested this, and I can confirm the the functionality documented in #87 and #91 is preserved in the latest version of the patch.

  • Spleshka committed 724a5e9 on 7.x-1.x authored by MKorostoff
    Issue #1011370 by MKorostoff, Spleshka, kristiaanvandeneynde, et al:...
Spleshka’s picture

Status: Reviewed & tested by the community » Fixed

So, patch was finally commited! Thanks everyone :-) And especially @MKorostoff, I wish every contributor was as much passionate and engaged into the contribution as you are :)

MKorostoff’s picture

And thank you Spleshka for your work as a maintainer!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Anonymous’s picture

Hi, I cant seem to apply to patch, I get the following error on the command line:

rummans-mbp:profile2 Ruman$ git apply -v profile2-ctools-relationship-from-user-1011370-104.patch
Checking patch plugins/relationships/profile2.inc...
error: plugins/relationships/profile2.inc: already exists in working directory
Checking patch profile2.module...
error: while searching for:
  $profile = profile2_load_by_user($account, substr($name, 8));
  return $profile ? $profile : NULL;
}

error: patch failed: profile2.module:1049
error: profile2.module: patch does not apply
MKorostoff’s picture

@Rumman Amin you don't need to apply the patch, you just need to download the latest dev version of profile2 https://www.drupal.org/node/681558

Anonymous’s picture

@MKorostoff Any way I can use this for public profiles as well as just from the current user?

The last submitted patch, 84: profile2-1011370-84-ctools-relationship-from-user.patch, failed testing.