Comments

Title:Add general entity supportAdd generic entity support

Marked #1337408: Not compatible with 'Field Collection' as a duplicate of this issue.

Marked #1352270: Support for Field Collections as a duplicate of this issue.

Priority:Normal» Major

Bumping this up to major, as it's collecting a lot of duplicates. Here's another: #1469412: serial field does not work in user table

waiting for this feature where i can assign serial number to user

Assigned:Unassigned» drvdt

Why only for node?
This is a great module that needs for many entities. Please improve it.
Is any body know an other same module?
Many thanks,

Assigned:drvdt» Unassigned

@drvdt: Please do not assign the ticket to yourself unless you plan on working on it.

As the current maintainer, I do not have the time to work on this right now. I only needed it for nodes, but yes, this needs to be generalized. Someone else will have to provide a patch, or pay someone to work on it. Once it's sufficiently tested, I'll commit it.

Colan-- Any broad suggestions or pointers on how to best generalize it?

This is really broad, but search for "node" or "nid" in the code, and then replace with "entity" or "entity_id" respectively. ;) You may need to store the entity type and the entity ID in each table as opposed to just the node ID, but I haven't looked at it that closely in a while. Also, take a look at the field API.

The code isn't that dense, so it shouldn't be too hard to take a look and see what needs doing. Play with it, and see what happens. Using other field modules (that have generic entity support) as examples would be extremely beneficial here.

Did any body try #9?

+1 for this feature, I think in order to get it working for all entities, we need to identify the entity type and find the base table using entity_get_info(), it shouldn't be too hard :)

I did. But I am a total newbie to php, so am afraid i did not make any progress. But would certainly love to have this feature.

Thanks
Jaya

@j4, What you did?tried on entities?, please post it here we will test

I did precisely what was offered as a tip in #9, but it threw up all kinds of errors. Sorry i did not document the errors!

Jaya

I suggest go through the entity API to see how an entity behaves on entity_create,entity_save,entity_update,entity_delete,I am not coder, so I cannot code, I can understand a bit on entity_hooks.

Will report back if i succeed..thanks

J

I'm interested in using the serial field with the field collection module.

I'd be willing to attempt to convert the module to work with entities if nobody else is working on it?

@lukus: It's open for you to assign to yourself, and start working on it. Thanks! Looking forward to your patch. :)

Assigned:Unassigned» lukus

@colan - I'm going to give this a go, I'll report back later today with any update.

Assigned:lukus» Unassigned

@colan

Okay I've started working on this. I've looked over the code, and have produced an overview of functionality. I think I understand what's going on.

It doesn't seem like a huge job - as much of the code already works with the Field API. The main issue occurs when a serial field is applied to an entity with pre-existing content; so I'm going to try to provide a generalised function that takes the place of _serial_init_old_nodes() to generate sids for any entity with pre-existing content.

One other point I've considered;
Field collection entities are generally used with a 'host entity'. Bearing this in mind, eventually I think we might need to be able to choose whether serials are allocated locally or globally. I think this could possibly be done via field UI settings.

ie.

  • locally: sid is unique to each new instance of a field collection (e.g. '1... n' for each host node/entity).
  • globally: sid spans all instances of a field collection bundle (e.g. '1... n' across all host node/entity).

For now I'm going to just work on the latter case, as that's what I currently require.

Does is sound like I'm going in the right direction?

Assigned:Unassigned» lukus

Here's my patch.

I've tested it with nodes, field collections, users and taxonomy vocabularies - both empty and pre-populated bundles

It's functional, but there's still one thing left to do:

  • if an entity's machine_name is changed the table name isn't updated automatically - e.g. a taxonomy vocabulary. Need to find the relevant hook for this.

I'd strongly recommend not using this on any production site yet - it's very much alpha. If someone could review the code for me, and try it out on a test site, I'd be most appreciative.

I'm going to look over it again tomorrow morning and test it more thoroughly.

Status:Active» Needs review

First of all, thanks so much for taking this on.

if an entity's machine_name is changed the table name isn't updated automatically - e.g. a taxonomy vocabulary. Need to find the relevant hook for this.

How about hook_field_attach_rename_bundle?

The basics of what you've got make sense to me.

There are several coding standards violations, but I'm assuming that these will get cleaned up when you're done. It seems like you're not done because some lines are commented out - these need to disappear in the final version. Also, we need to figure out if that drupal_goto() should stay or go. I'm not sure myself.

I'm not in a good position to test this right now so let's wait and see if anyone else can test and/or comment on the above.

Cheers Colan,

I'll work on the generic rename function later today, and I'll also clean up the code so it passes review standards. Will add a new patch once it's done.

Hi

I've refactored the code to meet drupal.og coding conventions and I've also added the new generic hook to deal with renaming entity machine names / serial table names.

Could someone please review?

@lukus nice work

also it would be nice if we have the following
1.a specific number range for each entity type
2.assigning the number range for specific period
3.after expiration of the specific period the assigned number range cannot be used
4.allow prefix to number range ex:AA-12345 or AA/12345
5.allow suffix to the number range 1234/2012
6.Lock:if the same type of entity is being created by another user ? so the serial number shouldn't be assigned unless saved
to achieve the above we need a configuration settings for creating number ranges
hope some one will patch

@kaizerking

Thanks for the feedback. Can you confirm whether the patch functions as expected?

Re. the feature additions, I'd recommend adding a new issue/s and to mark them as 'feature requests'.

I am getting this error when i am trying to create serial field on user accounts
http://localhost/xxxxxx/#overlay=admin/config/people/accounts/fields

There was a problem creating field test: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'name'
How ever Serial number is created when i create user. the number is not wrong indexing
before creating the user i have total 4 user including user 1
after enabiling serial module i have created one user. but the user number is generated as 2

@kaizerking

Thanks for for trying out the patch - much appreciated.

With the User entity, user '0' (anonymous) has no element for the name key by default and this is causing problems in the _serial_init_old_entities() function. For this specific case I think the count needs to begin from the first non-anonymous user.

I'll refine the code and release a new patch later today.

Here's the new patch. I've added an exception for the anonymous user - the anonymous user isn't given a serial.

@kaizerking - could you please apply the new patch and delete your serial field (and recreate it). Should be okay now.

Nice,patch @ #31 worked for me, thanks

Thanks kaizerking.

Can anyone else provide any feedback?

With patch #31 I still have this error:
Notice: Undefined property: stdClass::$nid in serial_field_insert() (line 83 of /home/xxxxx/domains/xxxxx.xx/public_html/sites/all/modules/serial/serial.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nid' cannot be null: INSERT INTO {serial_user_field_lidnr_} (nid) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => ) in _serial_generate_value() (line 155 of /home/xxxxxxx/domains/xxxxx.xx/public_html/sites/all/modules/serial/serial.inc).

I implement the patch from #31 and on another website I insert the serial field into an account, I got this error:
Fatal error: Call to undefined function _serial_init_old_nodes() in /home/xxxxx/domains/xxxxxx.xx/public_html/sites/all/modules/serial/serial.module on line 37

Applied the patch and got the same error while trying to make a new user account with a serial field:

Notice: Undefined property: stdClass::$nid in serial_field_insert() (line 80 of /xxx/sites/all/modules/serial/serial.module).
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'nid' cannot be null: INSERT INTO {serial_user_field_usernumber} (nid) VALUES (:db_insert_placeholder_0); Array ( [:db_insert_placeholder_0] => ) in _serial_generate_value() (line 155 of /xxx/sites/all/modules/serial/serial.inc).

Any ideas? Thanks in advance.

Hi .. I'll be working on this later today.

Just to confirm, the error occurs on creation of a new user account?

Yes. And after the error, a new user is not created. Looking forward to an update, thanks in advance!

No new results yet?

There's an hardcoded $entity->nid, that obviously isn't set on a user object.

Should work if you use entity_extract_ids to get the entity id instead.

function serial_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
    module_load_include('inc', 'serial');
    $ids = entity_extract_ids($entity_type, $entity);
    $sid = _serial_generate_value($ids[0], $instance['bundle'], $field['field_name']);
    $items = array(array('value' => $sid));
    $entity->$field['field_name'] = $items;
}

Is there progress? is this rolled in the .dev?

Marked https://drupal.org/node/1552280 Profile Serial field - Undefined property: Profile::$nid as duplicate of this.

Very interested in progress on this issue. I need a "member number" field on the user entity, and it's not working right now. How can I help?