Comments

itamar’s picture

Status: Active » Needs review
StatusFileSize
new4.85 KB

Patch alters entityreference_options_list to accept entity_type and entity arguments.

damien tournoud’s picture

That makes sense.

-  protected function __construct($field, $instance) {
+  protected function __construct($field, $instance, $entity_type, $entity) {

Let's make those optional too, to make sure people understand that they might not be available.

itamar’s picture

The $entity_type and $entity arguments in the constructor actually are optional, because the constructor is invoked using getInstance() which has default values for them;

+ public static function getInstance($field, $instance = NULL, $entity_type = NULL, $entity = NULL) { 
damien tournoud’s picture

I know, but let's make those optional too, to make sure people understand that they might not be available :)

itamar’s picture

StatusFileSize
new4.87 KB

Amending the previous patch; Setting default values in EntityReference_SelectionHandler_Generic::_construct().

amitaibu’s picture

damien tournoud’s picture

-function entityreference_options_list($field, $instance = NULL) {
-  return entityreference_get_selection_handler($field, $instance)->getReferencableEntities();
+function entityreference_options_list($field, $instance = NULL, $entity_type = NULL, $entity = NULL) {
+  return entityreference_get_selection_handler($field, $instance, $entity_type, $entity)->getReferencableEntities();

Thinking about this more, shouldn't we just add $entity_type and $entity as (optional) parameters to the ->getReferencableEntities()? Amitai, any thoughts?

amitaibu’s picture

> shouldn't we just add $entity_type and $entity as (optional) parameters to the ->getReferencableEntities()?

Indeed, at the beginning I thought about this option, however, I was thinking it is possible that one would call also validateReferencableEntities() needing the entity. Maybe also on entityFieldQueryAlter().
So I think that the proposed solution is more future proof to feature requests.

damien tournoud’s picture

Ok, in that case, we need to fix or remove the caching in entityreference_get_selection_handler(). I just removed it in the attached patch and added some more context where we have it.

We still need to figure out how to pass the entity context to entityreference_autocomplete_callback().

amitaibu’s picture

> we need to fix or remove the caching in entityreference_get_selection_handler()

Damz, what do you think about this caching? (attached interdiff)

Status: Needs review » Needs work

The last submitted patch, interdiff.patch, failed testing.

damien tournoud’s picture

Status: Needs work » Needs review

Damz, what do you think about this caching? (attached interdiff)

I started writing something like that, then decided that it was not worth it. We can decide later, can we focus on the autocomplete callback?

amitaibu’s picture

Patch (based on #9 -- without objet cache) adds optional $entity to autocomplete.

Status: Needs review » Needs work

The last submitted patch, interdiff.patch, failed testing.

damien tournoud’s picture

Status: Needs work » Needs review

#13 looks good to me on visual inspection. Let's move forward with it and tag a rc2.

damien tournoud’s picture

Status: Needs review » Fixed
StatusFileSize
new11.84 KB

I ended up committing the following patch with some minor fixes.

amitaibu’s picture

Status: Fixed » Needs work
+++ b/entityreference.moduleundefined
@@ -680,25 +673,36 @@ function entityreference_field_widget_form(&$form, &$form_state, $field, $instan
+    unset($entity->nid);

Is this a debug leftover?

amitaibu’s picture

Status: Needs work » Fixed
damien tournoud’s picture

It was, I quickly tested what happens with unsaved entities. I caught it in time :)

Status: Fixed » Closed (fixed)

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