Comments

that0n3guy’s picture

Oh sorry, thats a big git-oops of a patch... here is a better one.

johnv’s picture

Status: Patch (to be ported) » Needs review

Correcting status.

John Morahan’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
FileSize
5.63 KB

I added a second widget which uses the fancy tagging UI that autocomplete_deluxe provides for taxonomy reference fields.

mrfelton’s picture

Using patches from #1 and #3. Works well, thanks!

John Morahan’s picture

FileSize
10.55 KB

Entity Reference doesn't create new entities when the tags you enter don't exist, but Autocomplete Deluxe's tagging UI makes it look like it should.

So here's a patch to do that...

John Morahan’s picture

FileSize
10.5 KB

Whoops - some cruft left over from a previous attempt.

IWasBornToWin’s picture

If I want to use this with entity reference do i need to apply each individual patch?

John Morahan’s picture

Just the last one.

IWasBornToWin’s picture

Just applied the patch, changed my widget to autocomplete deluxe the field using entity reference as got this error;

Fatal error: Call to undefined function entityreference_get_handler() in /sites/all/modules/acdx_references/acdx_entityreference/acdx_entityreference.module on line 97

I will look and see if I can find the problem.

John Morahan’s picture

Status: Needs review » Needs work

Hmm apparently the function was renamed to entityreference_get_selection_handler and now requires an $instance parameter too.

IWasBornToWin’s picture

I appreciate your fast replies. Based on your last comment is there something I need to do on my end?

For what it's worth, the main module of automcomplete deluxe isn't currently dropping down on my site with any fields. I installed it a long time ago and it worked. I just re-installed it today.

I'm trying to locate what changed in my site which would stop it from dropping down or looking for any of my data when I start typing. Not sure if that has anything to do with my error or not.

IWasBornToWin’s picture

I got this message when trying to save a taxonomy term in a term reference field using regular autocomplete deluxe module. Wonder what it would even have to do with this module?

Fatal error: Cannot access empty property in /sites/all/modules/acdx_references/acdx_entityreference/acdx_entityreference.module on line 191

John Morahan’s picture

Status: Needs work » Needs review
FileSize
10.62 KB
IWasBornToWin’s picture

works great...thank you!

IWasBornToWin’s picture

When I try to add more values than allowed I get a message--field_cardinality.

Is this from this module? The average user probably has no idea that it's a message claiming they're trying to add too many values.

IWasBornToWin’s picture

The drop down button does nothing unless the field has focus and you type at least one letter. This triggers the dropdown list and then the button will work, no other time.

John Morahan’s picture

FileSize
10.8 KB

The field_cardinality error is due to the widget not implementing hook_field_widget_error().

The drop down doing nothing is, IIRC, because entityreference itself does not give us any information unless we pass something in. The original issue proposes solving this by patching ER in #1295032: Compatability with Autocomplete Deluxe for References. I don't think this is the right solution, but I don't have a better one right now.

IWasBornToWin’s picture

I've applied your latest patch. I may be wrong but it seems this is now more like a filter, not a drop down. At this point, the button could be hidden. The only way you can get the drop down to work is, as we discussed above, by clicking on and typing at least one letter. When you type "a" the only thing in the list are terms with "a". You can't scroll the entire list (since it's only scrollable when you type in a letter). I do not remember this being the case before all the patches? Although, it could just be my memory.

John Morahan’s picture

FileSize
12.35 KB

Try this.

John Morahan’s picture

FileSize
12.35 KB

Or alternatively without the 10-item limit... (of course you would need to be careful to avoid using this with a large vocabulary)

JohnnyX’s picture

I'll do some tests with patch #19. I hope it works for me with og 7.2...

JohnnyX’s picture

Patch #19 works for me so far. If all works fine it could/ should be commited...

JohnnyX’s picture

Status: Needs review » Reviewed & tested by the community

Seems to work fine!

daniorama’s picture

The description of this module should be changed as well as include a link to this module in entity_reference and autocomplete_deluxe modules' sites as soon as the patch is finally applied to the code.

pichot’s picture

The autocomplete functionality is working well. But I'm encountering this error if I add too many tags:

field_activity_alumni cannot be longer than 128 characters but is currently 175 characters long.

I dpm and that form item is set to #maxlength (Integer) 1024

The field is an Entity Reference to a Profile2 profile entity using the Autocomplete Deluxe (tags) widget.

Thoughts?

pichot’s picture

Forget it. I found the relevant issue in Autocomplete Deluxe. Appears to be fixed in dev.

http://drupal.org/node/1263928

JohnnyX’s picture

Could be commited?

Matthew Davidson’s picture

FileSize
12.3 KB

Ooh, like very much. Should stop people (like me) using taxonomy terms instead of a more appropriate entity type just for the cool widgets.

In my testing, the wrapper div around each item returned by the autocomplete callback was rendered as HTML-escaped text. I expect something's changed somewhere down the stack recently. Here's a variant on #19 without the wrapper div.

+1 to committing.

Fidelix’s picture

Status: Reviewed & tested by the community » Needs work

When saving the field settings:

Notice: Undefined index: create_bundle in acdx_entityreference_field_widget_settings_form() (line 85 de /mysite/sites/all/modules/contrib/acdx_references/b/acdx_entityreference/acdx_entityreference.module).

mojiro’s picture

FileSize
5.9 KB

Have you noticed something similar ?

Submitted data are being cropped left & right by two chars...
I checked the browser post data, and are correct.

It's probably a problem of my installation but I do not know where to check for the moment.

mojiro’s picture

I found this patch for autocomplete_deluxe http://drupal.org/node/1754164#comment-6434506

mojiro’s picture

At line:

// Get an array of matching entities.
$entity_labels = $handler->getReferencableEntities($string, $instance['widget']['settings']['match_operator'], 10);

it is being specified the number of results. Couldn't be better, the number of results to be retrieved from the view that is being used to bring the results?

marblegravy’s picture

I found the patches at #19 or #28 to both be fine with the current release version of Autocomplete Deluxe, but they both break any autocomplete widgets on the page when used in conjunction with the current dev branch of Autocomplete Deluxe (I was using 7.x-2.0-beta2+9-dev)

I suspect it has to do with the autogrow stuff that was added here -> http://drupalcode.org/project/autocomplete_deluxe.git/commit/90d95d3 but not knowing enough about how this works, I don't think I can help any more than that other than to include a screenshot of what was going wrong:
https://docs.google.com/open?id=0BzEg1h_E2DyzX1d3Ukk0YU9FZ3c

What I just noticed on the Autocomplete Deluxe commit notes however was this:

* No longer supports lists and therefore also denying terms. Use the chosen module instead.

As I need to deny terms for taxonomy fields using (preferably) the same widget, I gave Chosen a go and it appears to be working great with Entity Reference.

Matthew Davidson’s picture

mojiro: I would have thought so too, but a quick look at the code suggests that's how entityreference_autocomplete_callback() in entityreference.module works too. Not 100% sure. Either way, I think it's something to raise as a separate issue after this has been committed.

Matthew Davidson’s picture

Status: Needs work » Needs review
FileSize
12.4 KB

Here's a new patch updated for current dev versions of entityreference and autocomplete_deluxe. It fixes the PHP notice at #29 above, as well as a critical issue I had with creating nodes titled "" (that's two double-quotes) and worse, due to picking the wrong submitted value during _acdx_entityreference_autocomplete_tags_validate(). I'm not sure about the possible autogrow issue in #33; I'm getting larger fields with all autocomplete_deluxe widgets, not just our ones, so maybe it's their issue. I'll look into it later, but I just wanted to get this posted for people to test.

This also I think makes #1823260: Release new beta3-version, due to data-corruption in #1754164 a blocker for putting this into a stable release but I'd like to see it committed ASAP if it passes muster, and will happily put my hand up to become a co-maintainer if that will help make it happen. I use entity references all over the place, and do not feel comfortable deploying patched modules on live sites.

Matthew Davidson’s picture

Okay, whose idea was it to chase a moving target? Oh. Mine.

Updated to cope with recent changes to entityreference (#1821060: Return values from getReferencableEntities() keyed by bundle).

johnv’s picture

@Matthew, how about releasing this as a separate module? Ofcourse, after consulting sepgil.

HydroBlast’s picture

Component: Code » User interface
Assigned: Unassigned » HydroBlast
FileSize
1.53 KB

36 patch works.
acdx_entityreference.module
Based on it was a new patch.
There were no set minimum length.

Matthew Davidson’s picture

Here's a new patch that incorporates HydroBlast's autocomplete minimum length and also some changes to make autocreation of new entities work when the entityreference field is attached to an entity that has it's create/edit form embedded in another entity's form, eg. field collections.

John Morahan had a really cunning mechanism for creating new entities in a hook_field_attach_presave() implementation, after the form has been fully validated. This is the Right Way to do it, but doesn't work in the above case. I spent several days tearing my hair out, trying to do something similarly cunning, but couldn't find a way to make it work, so I ended up just doing the entity creation during element validation, which is a bit Wrong, but works in all cases I can come up with. Suggestions for better approaches welcome.

As for the suggestion to make acdx_entityreference a separate project, that makes a lot of sense, except insofar as I'm a really lazy module maintainer. However if sepgil or one of the above contributors want to be co-maintainers I'm happy to kick it off.

rerooting’s picture

Just tested out #39, seems to work ok, however for whatever reason, deleting a reference is not working. Upon deleting a reference and saving the node, when I go back to edit it, the reference is still there.

It should be noted I'm using this with OG 2.x. I will try this again with a normal entityreference field and see if this isn't being caused by the OG behavior somehow.

super_romeo’s picture

Thanks for patch!

But it not respect RealName module, then select user entity reference...

mansspams’s picture

@Matthew Davidson, @HydroBlast

  1. If default minimum length of 0 is used, there is ajax error on each focus. You don't have permission to access /MYSITE/acdx_entityreference/autocomplete/field_geographic_indication/node/recipe/ /10 on this server.. Notice space in URL.
  2. Commas or quotes does not work properly yet. Maybe better approach would be encoding strings?
  3. How about http://drupal.org/project/entity_autocomplete? Maybe this module could make this effort simpler?

@super_romeo Please open new issue about this.

bennos’s picture

tested patch
https://drupal.org/node/1295034#comment-7104800

it works on a vanilla install. A lot us thing needs to be adjusted (Example:when via entityreference a user is searched), but this get's on the todo list when we have a starting point.

Made a crosspost in autocomplete deluxe module. there was a feature request for support of entityreference.

brentratliff’s picture

I'm able to install both 36 and 39 but there is no autocomplete. Just a select list arrow and the 'This term " will be added' dialog. I'm trying it on a field collection field...... Disregard - needed updated EntityReference.

brentratliff’s picture

I have this working but I don't see any difference from core autocomplete with the exception of using jQuery to do the heavy lifting. Am I missing something? I've tried single and multiple values.

brentratliff’s picture

Issue summary: View changes

added link to other patch

zilla’s picture

whatever happened to this? it would still be great to see this come to life, particularly because chosen does not work with mobile interfaces (defaults to a mega-scrolling-list with entity reference)

sinasalek’s picture

Issue summary: View changes

I applied the patch against the latest devsnapshot and upgraded autocomplete deluxe to it latest devsnapshot and now it works well.
Note that to support free tagging, a new field in field settings "Create new entities" should be set
Another tip is that use should have create permissions for the entity, otherwise new entities will not be created.
However it's not a proper way because for taxonomies for example that have only administer permissions users should have full admin access to taxonomies to be able to create terms via autocomplete field which is not practical.
It don't think that this module should do any access check when creating new entities , if use has access to a field with free tagging, it means that he can create new entities via that field.
Also for creating part entityreference_autocreate module can also be used

sinasalek’s picture

FileSize
1.11 KB

The module creates empty terms, here is the patch to fix it

nithinkolekar’s picture

Is this patch only for terms or any entity like users, nodes, profiles etc?

sinasalek’s picture

As far as i can tell, it's generic

nithinkolekar’s picture

tested the patch with acdx dev for nodes using entity reference. For hiding nid and also to show remove(x) button in autocomplete element widget should be set to Autocomplete Deluxe (tags). One drawback with this setup it will show "The term xxx will be added" although entity is not of type taxonomy and also creating new entities is disabled.

nithinkolekar’s picture

still need to be cleaned when view is set as source for entityreference. It showing span elements like

<span class="views-field views-field-title"> <span class="field-content">node title 1</span> </span>

temporary workaround is to disable

"Provide default field wrapper elements" in inline field settings.
"Add default classes" in field's style settings.

update:
node id is visible in parentheses when entity is in editing mode.

digitgopher’s picture

#39 works for me. Here is a patch that adds to that the option to configure the 'The term xxx will be added' text, for when that text doesn't make sense.

Issues:

  1. Should other configuration options from autocomplete_deluxe be exposed?
  2. Why does this come with two widgets? Is the first one really needed?
  3. +1 to #52. Might also have to disable 'Link this field to the original piece of content.
  4. Did not test the patch for the other module.
  5. Did not test #48.
  6. This probably should be its own project.

Needs a more thorough review!

Would be great to see this finally happen!

manu manu’s picture

Status: Needs review » Needs work

Hi there, thanks for working on this.

When testing #53, adding new references will crash if "Create new entities" setting is set to "Don't create".

EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7848 of /vagrant/www/includes/common.inc). Backtrace:

entity_extract_ids('taxonomy_term', Object) focal_point.module:276
focal_point_field_attach_presave('taxonomy_term', Object) 
call_user_func_array('focal_point_field_attach_presave', Array) module.inc:895
module_invoke_all('field_attach_presave', 'taxonomy_term', Object) field.attach.inc:922
field_attach_presave('taxonomy_term', Object) taxonomy.module:639
taxonomy_term_save(Object) entity.module:286
entity_save('taxonomy_term', Object) acdx_entityreference.module:278
_acdx_entityreference_create('taxonomy_term', '', 'Crash') acdx_entityreference.module:239
_acdx_entityreference_autocomplete_tags_validate(Array, Array, Array) form.inc:1465
[...]

Focal Point is triggering the error, but every module implementing hook_field_attach_presave() would do so when extracting ids.

The problem is that _acdx_entityreference_autocomplete_tags_validate() is not checking $field_instance['widget']['settings']['create_bundle'] and is creating an entity with no bundle.

Aside of this, if no entities can be created, _acdx_entityreference_autocomplete_tags_validate() should set a form error when no matching entities are found.

Will post a patch as soon as I can.

edodusi’s picture

Hi, I tried #53 and it's working good, now we're gonna use it in a production website.
I think this should really be a stand-alone project, there's no need to keep it bundled with acdx_references.
Also, I did not get the issue reported in #54 setting "Create new entities" to "Don't create".

+1 for me

millionleaves’s picture

#53 worked for me too. Not allowing the creation of new entities so #54 not applicable in my case.

Thanks.

Dajka’s picture

#53 works perfectly! Thanks a lot for this. Also didn't get the issue in #54.

+1 for stand-alone project

odrzutowiec’s picture

#53 works for me thanks!

sinasalek’s picture

seren10pity13’s picture

#53 works well, thanks !

Just had a problem with single quote appearing like this : &#039;

I solved it with htmlspecialchars_decode :

function acdx_entityreference_autocomplete_callback($field_name, $entity_type, $bundle_name, $string = '') {
	[...]
	// Loop through the entities and convert them into autocomplete output.
	foreach ($referencable as $referencable_bundle => $entity_labels) {
		foreach ($entity_labels as $entity_id => $label) {
			$key = "$label ($entity_id)";
			// Names containing commas or quotes must be wrapped in quotes.
			if (strpos($key, ',') !== FALSE || strpos($key, '"') !== FALSE) {
				$key = '"' . str_replace('"', '""', $key) . '"';
			}
-			$matches[$key] = check_plain($label);
+			$matches[$key] = htmlspecialchars_decode(check_plain($label, ENT_QUOTES));
		}
	}

	drupal_json_output($matches);
}