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.
When both private message and message are enabled and a message (block) views created and assigned to user/* errors are thrown on visiting user/*....
Warning: array_flip() [function.array-flip.html]: Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of /var/www/dev/recruiter/includes/entity.inc).
Recoverable fatal error: Object of class Message could not be converted to string in DatabaseStatementBase->execute() (line 2108 of /var/www/dev/recruiter/includes/database/database.inc).
Comments
Comment #1
ronald_istos CreditAttribution: ronald_istos commentedCame across this error myself. The problem pops up when you have the two modules activated because of a namespace collision that makes Drupal think that Private Message's entity load function is a hook to call when Message loads an entity as well :-)
Private message has an entity load function as
privatemsg_message_load
while Message has
message_load
.This namespace affinity makes privatemsg_message_load fire whenever a Message entity loads with ensuing hilarity.
Now the problem is really Private Message's - one should avoid function names that can cause this problems. A larger issue is whether Drupal core should check these things - or maybe Coder.
Will post in Private Message with a short term patch - long term solution is to change the function name.
Comment #2
jbrown CreditAttribution: jbrown commentedtagging
Comment #3
davidcsonka CreditAttribution: davidcsonka commentedDid you ever post in the PrivateMsg issues queue? Can you list the issue link here so I can check on it?
Comment #4
berdyshev CreditAttribution: berdyshev commentedI have debbuged this problem and find the place where it fails.
Handler for views (message_handler_field_message_render) calls
message_load()
function inincludes/views/message_handler_field_message_render.inc:75
. This will call theattachLoad()
method of theDrupalDefaultEntityController
class. In this method there is such code (includes/entity.inc:332
):where
$this->entityInfo['load hook']
is equal tomessage_load
. So, theprivatemsg_message_load()
function will be called.As solution,
privatemsg_message_load()
function should be renamed to something likeprivatemsg_msg_load()
. But this will cause changes in privatemsg's API and I don't sure if this is possible.But I have attached patch which is applying this renaming to privatemsg module.
Comment #6
berdyshev CreditAttribution: berdyshev commentedComment #7
berdyshev CreditAttribution: berdyshev commented#4: privatesmg_1355342_renaming-private_message_load-and-private_message_load_muliple-4.patch queued for re-testing.
Comment #8
berdyshev CreditAttribution: berdyshev commentedand here it's the patch for the latest dev version of the 2.x branch
Comment #9
berdyshev CreditAttribution: berdyshev commentedchanged version
Comment #11
berdyshev CreditAttribution: berdyshev commentedrenaming applied to the test files.
Comment #13
BerdirThis doesn't make sense. I see the problem, but things aren't abbreviated like that in Drupal and there is much more that is called privatemsg_message, like all of our hooks, the privatemsg_message entity and more.
There is a much simpler solution for this problem. Add a check to that function that looks if the argument is an object and if so, do nothing.
Comment #14
berdyshev CreditAttribution: berdyshev commentedOh, sorry, I was trying to fix this issue globally and missed this simple solution.
Patch attached.
Comment #15
BerdirYeah, that's much more sane :)
Let's format that comment according to the guidelines (first character upper case, no longer than 80 characters, end with a "." and I'm happy to commit this change.
See http://drupal.org/node/1354#inline
Comment #16
berdyshev CreditAttribution: berdyshev commentedThanks for review. revised patch attached.
Comment #17
omar CreditAttribution: omar commented#14: privatemsg_1355342_fixing-conflict-with-message-module_14.patch queued for re-testing.
Comment #18
Michsk CreditAttribution: Michsk commentedThis does not fix it. The following error keeps appearing http://drupal.org/node/1659228
Comment #19
Michsk CreditAttribution: Michsk commentedDon't we also need something for
privatemsg_message_load_multiple()
. Since the Message module also usesmessage_load_multiple(array_keys($check_mids);
.Comment #20
BerdirNo, there is no such hook. Commited the patch, fix looks valid to me. If you still experience this issue, please reopen with a detailed error report (backtrace).
Comment #22
ajmartin CreditAttribution: ajmartin commentedWill this patch be committed to version 7.x-1.3, or is the 2.x-dev stable enough for a production site?
Comment #23
BerdirIt has been commited to 7.x-1.x-dev. Fixed releases are never updated.
Comment #24
ajmartin CreditAttribution: ajmartin commentedGreat. Thanks for clarifying. I assume it will be part of 7.x-1.4 when that's released.
Comment #25
snehi CreditAttribution: snehi commented#16 works for me
Thanks for the patch :)
Comment #26
Anonymous (not verified) CreditAttribution: Anonymous commentedThank you for this patch. #16 worked for me, too!
Comment #27
maximpodorov CreditAttribution: maximpodorov commented@Berdir
Please make a new stable release (7.x-1.4) with this fix. We need it badly. :)
Comment #28
kalistos CreditAttribution: kalistos commentedYes, please, make new stable release for 7.x-1.x.
A lot of people are faced with this problem #1851478-13: Object of class Message could not be converted to string in DatabaseStatementBase (Private Message integration)
Comment #29
Connoropolous CreditAttribution: Connoropolous commentedThanks so much for this. #16 worked like a charm.
Comment #30
Anonymous (not verified) CreditAttribution: Anonymous commentedWe ran into this problem as well with commerce sp paypal module since it relies on the message module. in the process of testing with 7.x-1.4 version of private message.
And to clarify: the problem is caused by private message inadvertently implementing the core hook_TYPE_load (see entity.inc around line 350). core entity supports 2 hooks:
- hook_entity_load
- hook_TYPE_load
and unfortunately the message module defines an entity of type "message"
Seems best practise is to never use _load as the end of a function name.