This problem has been occurring since the update to drupal 7.8. and has been seen on other contrib modules as well.
The scenario for og_create_permissions:
1. There is a group content type e.g. "article"
2. There is a group e.g. "group"
3. Authenticated users may be members of a group and post content article there (but they don't have to be part of a group to post an article).
When a group member tries to post content type article everything works fine.
When a non group member tries to post a content type article (and thus the group audience field is empty) we get an EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids().. The culprit seems to be line 48 of og_create_perms.module $entity = og_load_entity($entity_type, $entity); which later calls entity_extract_ids() for an empty entity.
Comments
Comment #1
bruitism commentedOk for a reference this here is the full error output:
Comment #2
mrfelton commentedI'm getting this too. Although, I get the problem when a group member who is allowed to post content tries to do so. I pinpointed it down to the same line of code. Actually I think that the problem is that in line 50
$entity = og_load_entity($entity_type, $entity)returns nothing. Then, further down in line 57 when$language_code = field_language($entity_type, $entity, $field_name);is called, $entity is empty, resulting in the EntityMalformedException.So, why does og_load_entity($entity_type, $entity); return nothing?
The problem seems to be that at the point when og_create_perms_field_attach_validate is run, there is no nid assigned to the entity. I wonder if
field_attach_form_validateshould be used, as the TODO in the code suggests... From http://api.drupal.org/api/drupal/modules--field--field.attach.inc/functi...Comment #3
mrfelton commentedThis patch looks to resolve the issue. It relies on the Drupal 7 core patch found at http://drupal.org/node/1220212#comment-4938924
Comment #4
andrés chandía commentedFor me it didn't solve it:
Som more help?
Comment #5
andrés chandía commentedDownload new version of OG, and problems will go away:
7.x-1.x-dev tar.gz (263.22 KB) | zip (304.33 KB) 2011-Oct-28
Comment #6
pav commentedI've got a completely fresh install (morning of October 29th). Same problem. Just tried substituting in the dev version of OG. Doesn't seem to work any better. Disabling OG_create_perms works, but is far from ideal. Must be an issue with that module. Somebody else has flagged it up at http://drupal.org/node/1324748#comment-5179618.
Comment #7
andrés chandía commentedSorry to hear that.
I've got next versions and everything works well, check the versions:
OG create permissions 7.x-1.0 with this patch:
0006-1321028-Fix-for-EntityMalformedException-Missing-bun.patch
Organic groups 7.x-1.3
Comment #8
pav commentedStill no joy... I can't get the patch this one depends on to install completely (http://drupal.org/node/1220212#comment-5181306).
Comment #9
andrés chandía commentedTo get the patch, if you work at a linux shell, from inside the og_create_perm directory, just do:
wget http://drupal.org/files/0006-1321028-Fix-for-EntityMalformedException-Mi...
(use sudo if you need it)
once you have it:
patch < 0006-1321028-Fix-for-EntityMalformedException-Missing-bun.patch
whatever question you see answer "yes"
that's it.
Comment #10
pav commentedHi, Andrés. The patch for og_create_perms installed just fine (sudo patch og_create_perms.module [patchname].patch), but had no real effect. The patch file includes the following line:
I downloaded the patch in question, but had problems applying it. Apparently there was a problem with the patch, but the guy who wrote it is in the process of fixing it.
Comment #11
brightboldMrfelton — In the patch, line 50 (the last line shown in the patch) is shown as
$account = user_load($user->uid);but in the module it's actually
$account = user_load($entity->uid);.Did you mean for that line to be changed or left as-is?
Comment #12
brightboldWell I tried it both ways and answered my own question. If you change the line to
$user->uidyou get a bunch of these:Notice: Trying to get property of non-object in user_access() (line 790 of /home/tremon5/public_html/hurleybak/modules/user/user.module).So
$entityit is.This does seem to solve the problem for me, getting rid of the error messages reported in #1 and #4, but now I'm seeing a new one:
Notice: Undefined property: stdClass::$group_audience in og_create_perms_field_attach_validate() (line 55 of /home/tremon5/public_html/hurleybak/sites/all/modules/contrib/og_create_perms/og_create_perms.module).Comment #13
andrés chandía commentedOops the problem reported in #4 is back, I've tryed both as in #12 but the problem persists:
Comment #14
pav commentedFor me, the problem disappeared when I applied the entities patch from http://drupal.org/node/1220212#comment-5181306.
That said, I get a bunch of similar looking error messages when I try to apply a group context filter to a panel layout, so it looks like og and entities aren't currently getting along in general.
Comment #15
andrés chandía commentedIt didn't work for me. I have followed the instruccions given in:
http://drupal.org/node/1220212#comment-5183078
but I still have this warning message when a user (non admin) creates content:
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of .../includes/entity.inc).Comment #16
othermachines commentedAndrés - sounds like we are having a similar problem. Interesting that the patch at http://drupal.org/node/1220212#comment-5181770 didn't work for you. It seems to work for me (applied against Drupal 7.8). I haven't applied #3 patch. Did the problem reappear after an upgrade?
** Edit: Seems I spoke too soon. Still an error for non-admin users. Poopy.
Comment #17
andrés chandía commentedThat's it, when a user (not admin) adds new content, it appears the message:
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of .../includes/entity.inc).I'm on the 7.9 version and just in case I applied the patch you mention ( http://drupal.org/node/1220212#comment-5181770 ) but the song remains the same! like Led Zeppelin sang once.
Comment #18
othermachines commentedSunshine, rainbows and ponies! Maybe?
Here's a fix just committed to OG dev. Give it a try:
http://drupal.org/node/1325378
Comment #19
andrés chandía commentedYeap, installing 7.x-1.x-dev did the trick, I was looking what the expression "Sunshine, rainbows and ponies! Maybe?" means, but no success, some explanation?
Comment #20
andrés chandía commentedI realize now that I did solve it once doing this but, I don't know how, something got the problem back, check this:
#5
Posted by Andrés Chandía on October 28, 2011 at 9:26am
Download new version of OG, and problems will go away:
7.x-1.x-dev tar.gz (263.22 KB) | zip (304.33 KB) 2011-Oct-28
As you can see dev I was referring to is from Oc. 28th, current dev is from Nov 2nd.
Comment #21
othermachines commentedYeah, I was scratching my head over that, too. OG version brain explosion could be related to this: Issue #1323244 by medden, othermachines: Fixed EntityMalformedException: Missing.... The timing would be right.
Anyway, as long as it works I'm not going to question it.
"Sunshine, rainbows and ponies!" - A cautious wish for something that is probably unobtainable. :)
Comment #22
arnoldbird commentedThis bug still happens just as the OP describes it.
My versions:
Drupal core 7.14
OG 7.x-1.4
If a user is not a member of any groups, posting an item of a group content type results in...
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /var/www/hiusa/public_html/includes/entity.inc).
Notice: Trying to get property of non-object in og_create_perms_field_attach_validate() (line 50 of /var/www/hiusa/public_html/sites/all/modules/og_create_perms/og_create_perms.module).
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /var/www/hiusa/public_html/includes/entity.inc).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7539 of /var/www/hiusa/public_html/includes/common.inc).
Comment #23
arnoldbird commentedComment #24
den33775 commentedFor what it's worth, I've added a whole load of echo diagnostic lines to see what contains what, and (having read all of the above), I think I can add something new.
I agree line 50 returns blank.
If you comment out line 50, then the $entity value used in line 55:
if (!$items = $entity->{$field_name}[$language_code]) {
is straight from the parameter $entity passed to the function:
function og_create_perms_field_attach_validate($entity_type, $entity, &$errors) {
And causes an error as attached.
This implies that the $entity value passed as a parameter is wrong.
I am afraid that I am new to php, although I have programmed in a number of other languages and worked as a tester, so got a bit stuck here (what called it?) Anyway, hope this moves us all forward a bit.
I've not tried the patches, etc., yet, to resolve the problem with line 50, but will do so when we get to the bottom of all this. :)
Thanks to all for the above comments - were useful.
Best wishes
Comment #25
hongpong commentedThis may be a tangent but if you have malformed files entities - see #1446440: Unable to view me media management pages (EntityMalformedException: Missing bundle property...) for my one-off SQL fix for column type in the files_managed table.
Comment #26
magtak commentedOk, I downloaded this as I needed the described functionality but on attempt #1 (where a user NOT belonging to a -public- group tried posting content to that group) crashed and burned. So i began surgically diagnosing the code.
The crash happens indeed on afforementioned line 50 where the $entity itself is NULL.
This happens cause 48: $entity = og_load_entity($entity_type, $entity); returns a blank entity.
This happens cause og_load_entity tries to load an entity via it's nid and on this case, the nid has not yet been created as we are on the process of saving a node (a simple print_r will show you that the nid field is blank.
Line 48 occurs in this if clause that checks if the field 'group_audience' is set.
In my experience, if a user that doesn't belong in a group, tries to post in one, that field will not show up at all.
So, the afforementioned if clause is a valid check in itself, and I do not believe we need to 'reload' the entity (which is impossible at this stage I think.
So, if we add the rest of a code in an else clause and give the following lines of code in this if clase (replacing line 48) it should exit with the correct result:
$errors[$field_name][$language_code][0][] = array(
'error' => 'og_create_perms:user not a member',
'message' => t('Attempt to post to an illegal group')
);
Also providing my first ever attempt for a patch to maybe fix this. Test it and report back.
Comment #27
magtak commentedComment #28
magtak commentedScratch that patch @ #26, it was too hasty and didn't cover most scenarios. Don't even try it.
On the other hand, another thing i've stumbled upon, is that if a user, clicks a link to add content to a group he is not a member of, he gets (of course) no way to add that group to the group audience field, and thus that field is set to NULL, BUT!: even though that SHOULD mean that that's a global content attempting to be created it is in fact created inside the group.
In code, the place where that is checked is here: (line 61)
if (is_null($group['gid'])) {
// null gid = global context
but sadly we can enter this if clause via 2 routes:
A) actually trying to create a global content
B) illegally creating content to a group we are not a member of
And for the moment I am stuck here.
Comment #29
andrés chandía commented