PHP Fatal error: Cannot use object of type stdClass as array in relation_select/relation_select.module on line 528, referer: http://local.drupal7.com/node/2/edit
Reproduce:
Clean install
enable relation select (and dependencies)
create a relation type
add a relation_select field on a node type.
Create a node.
Create a second node with a relation to the first node. Click preview. WSOD. (Save is good, but edit and click preview to see the wsod again...)
Looking into it.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | relation_select-fatal-error-on-node-preview-1762946-5.patch | 3.51 KB | davidburns |
| #4 | relation_select-fatal-error-on-node-preview-1762946-4.patch | 3.51 KB | steveoliver |
Comments
Comment #1
vordude commentedYup.
$items[$delta] when previewing is actually the relation object.
Otherwise it's
Comment #2
steveoliver commentedThanks, vordude. I spent a while tracing through a Preview page, and see the issue, but am not quite sure where to pinpoint the root cause or identify a fix yet. Are you seeing anything?
Comment #3
davidburnsI'm bumping this to major status, because Preview is core functionality and this completely breaks the ability to preview content.
Comment #4
steveoliver commentedOK, so this works for me, but may not get at the root of the problem. However, I may just not understand why it makes sense to have $items[$delta] change from minimal array to full object between Edit and Preview displays... My guess would be that the former are defaults while the latter are saved values, but that doesn't fully make sense...
What's essentially going on is $element['#entity_id'] is set to the id of the entity to which the field is attached, to make sure that it is not relating to itself. The problem was that we seemed to be confusing this "origin" entity id with the id of the relation. How we get the ids of both entities is what the code comments will point out needs cleanup.
Comment #5
davidburnsApplied patch and confirmed it does allow previewing.
Comment #6
davidburnspatch actually throws a couple php errors on new nodes. In the first if statement check for
if (isset($form_state['node']->nid)) {instead of justif (isset($form_state['node'])) {. That seems to resolve that issue.Comment #7
steveoliver commentedI see, that makes sense. Do we wanna get it all cleaned up, or just commit it?
Comment #8
davidburnsI would commit this now since it does resolve the conflict w/ core functionality. I have to move onto other issues on larger project so this fix is as far as I need it to go for now.
Comment #9
steveoliver commentedCommitted to 7.x-1.x in 0809776. Thanks, @vordude and @davexoxide.
Comment #10
steveoliver commentedComment #12
steveoliver commentedRelated: #1803408: Content Creation with Relate Fields: Undefined index: entity_id in _relation_select_field_widget_form().