Here I am, once again, still trying to upgrade the DiscussThis! module from D6 to D7, and making heavier weather than I had expected. I've got to the point where the DiscussThis module creates what is essentially a copy of the D6 comment module's comment entry form, however when I press "Submit", DiscussThis calls comment_form_validate(), at which point I get a catastrophic error as follows:
EntityMalformedException: Missing bundle property on entity of type comment. in entity_extract_ids() (line 7665 of /Users/joelguesclin/Sites/acquia-drupal/includes/common.inc).
Now I'm completely lost, since I have no idea of how Entities work. I presume that there is something missing from my comment form, but what?
Any pointers would be welcome.
By joel_guesclin on
Comments
Since you haven't shown us
Since you haven't shown us any code, unless a psychic comes along, it's not likely we can help.
Contact me to contract me for D7 -> D10/11 migrations.
Trouble is, I'm not sure which code
The problem is, I didn't write the module so I'm a bit lost in exactly how it works. Roughly, what is supposed to happen is this:
1) The user who wants to start a discussion on an article clicks on the "DiscussThis" link, which causes a "comment" form to be displayed in a separate page. When the user presses the "Submit" button, the module creates a new Forum topic with links to the original node displayed in the body of the topic, and adds the comment as the first comment under the topic.
Unfortunately I don't know any psychics, so here is the code which as far as I can see actually builds the form that gets filled in:
I presume that pressing submit causes this function to be called, though I am not sure how:
As far as I can work out, it is during comment_form_validate() that the error is generated
There are a couple of issues
There are a couple of issues in your code. First, the relevant code is here:
Your comment is being initialized with this line of code:
I have no idea what the original developer was doing, but this is most definitely the wrong way to be doing it. They are initializing the comment object as a copy of the $user object. The problem with this is that a comment is not a user, it's a comment - completely different entities. This could even potentially open some security holes, because if you have fields with the same name on both entities, you could expose private information when saving the comment this way.
To initialize an entity, you should use the following:
So you will use something like:
To initialize an entity, you should use the following:
However, I have not checked to see if the entity type and bundle type of comments are actually 'comment' as I've used in the example above, so if that fails, you should use entity_get_info() to get all info types, and dig through the returned value to find the entity name for comments, as well as the bundle name.
Contact me to contract me for D7 -> D10/11 migrations.
No luck there
The code you suggested didn't work I'm afraid because "create" is not a method of the class. I tried this:
It worked, inasmuch as it didn't give me an error, but it didn't solve the problem.
You're right, it appears that
You're right, it appears that no create() method exists for the comment class. You can read more about programmatically creating comments here: http://drupal.org/node/1030676
Contact me to contract me for D7 -> D10/11 migrations.