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.

Comments

vordude’s picture

Yup.

$items[$delta] when previewing is actually the relation object.

Otherwise it's

(Array, 1 element)
0 (Array, 3 elements)
endpoints (Array, 1 element)
    1 (String, 6 characters ) node:1
entity_id (Integer) 3
relation_id (String, 1 characters ) 2
steveoliver’s picture

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

davidburns’s picture

Priority: Normal » Major

I'm bumping this to major status, because Preview is core functionality and this completely breaks the ability to preview content.

steveoliver’s picture

Status: Active » Needs review
StatusFileSize
new3.51 KB

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

davidburns’s picture

Status: Needs review » Reviewed & tested by the community

Applied patch and confirmed it does allow previewing.

davidburns’s picture

patch actually throws a couple php errors on new nodes. In the first if statement check for if (isset($form_state['node']->nid)) { instead of just if (isset($form_state['node'])) { . That seems to resolve that issue.

steveoliver’s picture

I see, that makes sense. Do we wanna get it all cleaned up, or just commit it?

davidburns’s picture

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

steveoliver’s picture

Committed to 7.x-1.x in 0809776. Thanks, @vordude and @davexoxide.

steveoliver’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.