Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a content type with a file field. I have a custom module which implements hook_form_alter()
which adds an extra submission handler to the node edit form.
$form['actions']['submit']['#submit'][] = 'anexar_aplicacion_submit';
function anexar_applicayion_submit(&$form, &$form_state) {
$reto_nid = $form_state['values']['reto_nid'];
$aplicacion_nid = $form_state['node']->nid;
$reto = node_load($reto_nid);
$reto->field_aplicaciones[LANGUAGE_NONE][]['target_id'] = $aplicacion_nid;
field_attach_update('node', $reto);
field_attach_presave('node', $reto);
entity_get_controller('node')->resetCache(array($reto->nid));
}
This exception is thrown when I create a node of this content type, with the file. It is not thrown when the file is not attached to the node.
EntityMalformedException: Missing bundle property on entity of type node in entity_extract_ids() line 7929
Comment | File | Size | Author |
---|---|---|---|
#10 | 2931500-8-EntityMalformedException-Fix-2.patch | 924 bytes | mmaranao |
#8 | 2931500-8-EntityMalformedException-Fix.patch | 948 bytes | Souvik Pal |
Issue fork drupal-2931500
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
RoslinMary CreditAttribution: RoslinMary at DrupalPartners for Innoppl Technologies Pvt. Ltd commentedHere is the responsible code which is thrown by Drupal core (file: common.inc):
When you try to print $form_state['values'] in node, You will get nid under array format. The same when you print $form_state['node'], You will get nid in object format.
In your above example, I understood that you are referring another node id in current node,
$reto_nid = $form_state['values']['reto_nid'];
If Not Kindly let me know, What value you are trying to get ? So that we can proceed further.
Comment #3
MustangGB CreditAttribution: MustangGB commentedSupport requests aren't critical.
Comment #4
mdjamiruddin CreditAttribution: mdjamiruddin at SynapseIndia Outsourcing Pvt. Ltd. commentedI am also getting the same issue in my project developed in Drupal 7.59 while accessing few particular pages, not for all pages. I am currently investigating on the issue to rectify it.
It would be appreciable if anyone share the reason behind this with possible solutions.
Comment #5
Marco Aurelio Rocca CreditAttribution: Marco Aurelio Rocca commentedSimilar case here with me: typeA content is "room", that relates to a possibly present typeB content: "reservation". Reservation content type has RULES LINK assigned, to "cancel reservation". A VIEWS-page-display tries to list all Rooms along with eventually present Reservations --- and, in that case, along with the Rules Link to Cancel Reservation.
All goes well as long as I ONLY list those Rooms for which there are Reservations and their respectiva Cancel rules-link. If I try to include also those Rooms with no Reservations, I get that EntityMalFormedException. If I delete from the View that Cancel-rules-link, I can get listed all Rooms, were they related to a Reservation of not.
I dare to figure that the Rules Link requires the node entity to be raised into memory, as a Parameter. So, if no Reservation is present, no Cancel Reservation rule link can be formed... and it umpolitely crashes.
Comment #7
Souvik Pal CreditAttribution: Souvik Pal as a volunteer and at Innoraft for Drupal India Association commentedI too faced a similar kind of issue. I am on Drupal 7.78. I had a code where the node id was extracted as...
$nodeid = arg(1);
Found that if I had them wrapped in a check condition like this...
the issue went away.
However, if I modified the check condition in common.inc from
to
I could simply use
$nodeid = arg(1);
without the additional check condition i.e.This issue has been there for quite some time. I think its worth looking into. It is always recommended and a good practice to use necessary check conditions while writing custom code, in some cases people may miss out such a simple check condition and that would result them in wasting hours behind it.
Comment #8
Souvik Pal CreditAttribution: Souvik Pal as a volunteer and at Innoraft for Drupal India Association commentedEntityMalformedException fix for common.inc.
Comment #9
sroy26 CreditAttribution: sroy26 as a volunteer and at Innoraft commentedYes, I too faced a similar issue and the above solution #8 worked for me. Thanks
Comment #10
mmaranao CreditAttribution: mmaranao commentedI had the similar issue, even updating media and file entity to the latest. The patch didn't apply to my current setup since I don't have it installed in a /docroot folder. So here's the same patch without /docroot.
Comment #11
awaischamp CreditAttribution: awaischamp commentedThanks.. #10 worked for me
Comment #12
Liam MorlandComment #13
bobburns CreditAttribution: bobburns commentedNeeds to be comitted to core - strill throwing this error, and this patch fixes it
Comment #15
Liam MorlandI made a merge request containing the patch in #10.
Comment #16
Koen.Holman CreditAttribution: Koen.Holman at iO commentedWe can confirm this patch works
Comment #17
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedYes, the patch is "working" because it is supressing the problem but not solving it. 99% of the cases where we get this error is when the $entity passed to the
field_attach_update
orfield_get_items
or similar is incomplete / broken. And these issues are caused by custom code / contrib modules which are not checking values passed to these functions (see #7). I think that without the full example code we cannot know if this is real bug, or problem of the custom code / contrib module.Anyway, the patch is making the second condition unreachable (if we pass thru
!empty()
then we cannot reach EntityMalformedException in any case). I think this EntityMalformedException was put there by design so removing it entirely is not a solution. Therefore I am switching this back to NW.Comment #18
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commentedIs not possible this could have something in common with the problem described here? #3166668: PHP7.4 and empty entity_keys for taxonomy term result in notices - e.g. empty
$info
variable?Comment #19
hargurpreet CreditAttribution: hargurpreet commentedI also had a similar issue and tried patch in #10 and it worked for me. Thanks for sharing this patch.
Comment #20
alianov CreditAttribution: alianov as a volunteer and commentedupdating for version 7.94
Comment #21
Liam MorlandNow that #3166668: PHP7.4 and empty entity_keys for taxonomy term result in notices is fixed, does the problem in the present issue still exist or was it fixed by that issue?
Comment #22
danyg CreditAttribution: danyg at Cheppers commentedWithout the updated patch in #20, I still got the following PHP error:
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 8090 of /app/docroot/includes/common.inc).
Comment #25
florisg CreditAttribution: florisg at Youpal Group commentedThis bug has been around for ages, please merge it while we still support Drupal 7
I merely rerolled #20 against 7.98
Comment #26
florisg CreditAttribution: florisg at Youpal Group commentedupdated title to correspond with exact line in v7.98
so people who search with google can find the solution
Comment #27
poker10 CreditAttribution: poker10 at ActivIT s.r.o. commented@florisg The last merge request(s) are failing tests. So it is not possible to use this patch without additional changes - we need to fix the test failure and then we can consider the next steps (see my comment #17). Thanks!
Anyway, thanks for working on this, but I suppose that the new merge request was not needed, as there is an open merge request from @Liam Morland, which is the same and therefore this one should have been rerolled.
Comment #28
apadernoIt seems the issue summary has been lost in one of the previous revisions.
Comment #29
apaderno