My custom entity type has an entityreference field in it. In the submit handler, we check if there are any changes to any of the fields in the entity, so we can update a list of changed fields accordingly.

In function _entityreference_autocomplete_validate(), entityreference.module:716, the value set into the $value variable is the output from preg_match, which is a string. Being a numeric id, the data type should be an integer.

This difference causes the fields to never match in my custom checker, since one has an integer target_id and the other has a string.

Here's a part of my debug log from the submit handler:

Checking changes to field
 CHANGED:
  current entity:
  a:1:{s:3:"und";a:1:{i:0;a:1:{s:9:"target_id";i:11930;}}}
  form submission:
  a:1:{s:3:"und";a:1:{i:0;a:1:{s:9:"target_id";s:5:"11930";}}}

This is easy to fix with a simple cast to integer on two lines in the module, if this is considered a bug. Patch attached.

Comments

firebird’s picture

firebird’s picture

Status: Active » Needs review
damien tournoud’s picture

Fascinating. How are you getting an integer here in the first place, when the database layer fetches everything from the database as strings?

firebird’s picture

Might have something to do with using Mongo as field storage?

damien tournoud’s picture

Status: Needs review » Closed (works as designed)

Internally, Drupal always manipulate string representations of number stored in the database. Because it doesn't matter either way, I'm not going to fix this.