It seems like the Barcode module is hardcoded to handle nodes instead of other types of modules. Since fields can be attached to many different entities(users,terms, etc) the module could be changed to handle other entities.

I found this issue because a user filed an issue #1428742: Entityform Tokens Behavior with my module Entityforms when trying to use Barcode with an Entityform.

It seems the only function that assumes entities are nodes is _barcode_sanitize.

I will attach a patch....

Comments

tedbow’s picture

Status: Active » Needs review
FileSize
1.84 KB

Attached a patch. not positive about this part
$item['value'] = token_replace($item['value'], array('entity' => $entity), array('clear' => 1));

Not sure if 'entity' is the right key.

This patch all makes this module dependent on entity and entity_token(part of entity).

rhclayto’s picture

I tried it with the patch, it continues to generate a bar code in the results page of entityform with core tokens like [current-page:url] or [current-date:short], but it can't seem to get tokens such as [entityform:field_sometext] & [entityform:field-sometext] (this is a text field attached to the entityform type).

This functionality is very desirable.

tedbow’s picture

Attached another patch. This time using $entity_type as the key in the $data array instead of the string 'entity'. I think this is right.

I would probablyttest this not only with an Entityform but also with the same fields attached to the user account. It technically should work with any entity. Using User might help you avoid any problems introduced by Entityforms module since it is very new.

Let us know if user works and not entityforms then I will know there is a problem with my module.

Thanks

rhclayto’s picture

The patch in #3 works! Entityform field tokens working with Barcode module to create a bar code from user input. Many thanks. Hope this gets included in Barcode.

tedbow’s picture

Glad the patch works. Hope it gets included too. I learned a bit about entity_token at least.

rhclayto’s picture

Status: Needs review » Reviewed & tested by the community
MM10’s picture

Would this now work with line items in the Commerce module?
SKU integration with line items

tedbow’s picture

Potentially the patch should allow the Barcode field to be attached to any entity. But it would need to be tested.

oenie’s picture

I was trying this our myself with the Profile2 module, which uses entities.
I discovered the bug before i found this bug report.
It works for Profile2 fields, referencing other specific fields within a Profile2 entity.

Even referencing other Profile2 entity types for the same user, like:

[profile2:user:profile-main:field-my-name]
resolves nicely to getting the field-my-name value from a profile-main entity associated with the user.

That would be a works for me. What do we need to get this patch included in the builds ?
It's over a year ago, and i still run into this very same problem.

bhosmer’s picture

Category: bug » feature
Status: Reviewed & tested by the community » Needs work

I'm working on using this with computed field to generate random 13-digit numbers to supply a UPC on user registration.

The problem I am encountering is the form validation for the default value is validating the actual length of the text for the place-holder token, instead of the values for the token itself.

I'm going to dive a little more and see if I can determine a solution to this.

bhosmer’s picture

After diving deeper today, there are multiple validations happening. It seems the plugin validations don't actually do anything.

I wound up just using a token along with the great Ted Bowman's patch and choosing "codabar" for my code type.

bhosmer’s picture

Status: Needs work » Reviewed & tested by the community

Resetting to RTBC.

  • skyredwang committed d307676 on 7.x-2.x
    Issue #1434178, by tedbow: Support Entities.
    
skyredwang’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Fixed

I have committed this patch to 7.x-2.x-dev http://cgit.drupalcode.org/barcode/commit/?id=d307676

Status: Fixed » Closed (fixed)

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