Hello,
As you may notice, recently I've added support of Metatag module for Profile2 (#1858512: Add Metatag integration for Profile2 pages). Metatags work only for separate profile pages, and that is absolutely okay. But profile2 module has one interesting feature for separate pages - if user didn't add any content to his profile (actually, didn't save his profile at least once), then a profile page is still available, but profile2 entity generates on the fly with default values (no raw for this profile entity in the database). As a result, this entity doesn't have entity ID value. This issue leads to the following php warnings on an unsaved user profile:

The reason of this warning is that in metatag_generate_entity_metatags() you are trying to reload entity by ID, which is actually empty (who can expect that, huh?). Patch that solves this issue is attached.
Steps to reproduce:
1. Enable Profile2 and Profile2 pages modules.
2. Add any metatags for profile2 entity.
3. Go to /profile-main page. You'll see that warning there.
So if user doesn't have created profile yet and metatags support is enabled, then you will see those warnings there.
| Comment | File | Size | Author |
|---|---|---|---|
| metatag-problems-with-profile2-integration.patch | 965 bytes | spleshka | |
| metatag_php_warnings.png | 18.6 KB | spleshka |
Comments
Comment #1
spleshkaComment #2
damienmckennaThanks, I'll give this a review and try to get it into 1.5.
Comment #3
spleshkaCool, looking forward for that!
Comment #4
damienmckennaThis should be safe as it only affects the values used to compile the cache ID. Normally it would use $entity_id as one of the most obvious & important values, however because that is empty it would have to rely upon the URL being different instead. Does Profile2 Pages provide different URLs for each user's profile2-type page for that user, e.g. "user/123/profile2-test", or is it uniform for all users, e.g. "user/profile2-test"?
Comment #5
spleshkaActually, both variants are possible. Profile pages work the same way as user page in Drupal: if you request only /profile-main page, it will show your profile. If you request /profile-main/[uid] then it will show specified profile of user with chosen uid.
Comment #6
damienmckennaSo, given Metatag's caching, how well do the meta tags look on the /profile-page -style page? In fact, does this introduce problems with the token-based default values?
Comment #7
spleshkaTokens there display well, but I didn't test metatags with tokens on that page, so can't tell you for sure if there are any issues with token-based default values. Will test this soon.
Comment #8
spleshkaTest showed that for profile page when profile doesn't exist no field values can be fetched for tokens (both default and not default). So, no entity == no fields data available, no matter if that value is default or not.
Comment #9
damienmckennaOk, I think this is an acceptable change for this (slightly odd) scenario.
Comment #11
spleshkaI agree, that is the best solution we can make here. Otherwise we should change A LOT in profile2 :) Thanks for commiting this!