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

bruitism’s picture

Ok for a reference this here is the full error output:

Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /Users/stephen/Sites/timebank/includes/entity.inc).
Notice: Trying to get property of non-object in og_create_perms_field_attach_validate() (line 50 of /Users/stephen/Sites/timebank/sites/all/modules/vendor/og_create_perms/og_create_perms.module).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /Users/stephen/Sites/timebank/includes/entity.inc).
Warning: array_flip() [function.array-flip]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of /Users/stephen/Sites/timebank/includes/entity.inc).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7389 of /Users/stephen/Sites/timebank/includes/common.inc).
mrfelton’s picture

Priority: Normal » Major

I'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_validate should be used, as the TODO in the code suggests... From http://api.drupal.org/api/drupal/modules--field--field.attach.inc/functi...

$entity The entity being submitted. The 'bundle', 'id' and (if applicable) 'revision' keys should be present. The actual field values will be read from $form_state['values'].

mrfelton’s picture

Status: Active » Needs review
StatusFileSize
new1.15 KB

This patch looks to resolve the issue. It relies on the Drupal 7 core patch found at http://drupal.org/node/1220212#comment-4938924

andrés chandía’s picture

For me it didn't solve it:

Notice: Undefined property: stdClass::$original in og_create_perms_field_attach_validate() (line 48 of .../sites/all/modules/og_create_perms/og_create_perms.module).
    Notice: Trying to get property of non-object in og_create_perms_field_attach_validate() (line 50 of .../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 .../includes/entity.inc).
    Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->cacheGet() (line 354 of .../includes/entity.inc).
    EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7405 of .../includes/common.inc).

Som more help?

andrés chandía’s picture

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

pav’s picture

I'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.

andrés chandía’s picture

Sorry 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

pav’s picture

Still no joy... I can't get the patch this one depends on to install completely (http://drupal.org/node/1220212#comment-5181306).

andrés chandía’s picture

To 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.

pav’s picture

Hi, 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:

+      // NOTE: This currently relies on the Drupal 7 patch found at http://drupal.org/node/1220212#comment-4938924

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.

brightbold’s picture

Mrfelton — 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?

brightbold’s picture

Well I tried it both ways and answered my own question. If you change the line to $user->uid you 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 $entity it 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).

andrés chandía’s picture

Oops the problem reported in #4 is back, I've tryed both as in #12 but the problem persists:

Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of .../includes/entity.inc).
pav’s picture

For 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.

andrés chandía’s picture

It 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).

othermachines’s picture

André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.

andrés chandía’s picture

That'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.

othermachines’s picture

Sunshine, rainbows and ponies! Maybe?

Here's a fix just committed to OG dev. Give it a try:
http://drupal.org/node/1325378

andrés chandía’s picture

Yeap, 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?

andrés chandía’s picture

I 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.

othermachines’s picture

Yeah, 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. :)

arnoldbird’s picture

This 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).

arnoldbird’s picture

Status: Needs review » Active
den33775’s picture

For 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

hongpong’s picture

This 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.

magtak’s picture

StatusFileSize
new5.17 KB

Ok, 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.

magtak’s picture

Status: Active » Needs review
magtak’s picture

Status: Needs review » Active

Scratch 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.

andrés chandía’s picture

Issue summary: View changes
Status: Active » Closed (outdated)