While creating the Bundles for Neologism module, I was trying to name the install fields in a way they could be re-used, since there seemed to be a lot of similar instances. But I figured out that one bundle can not have multiple instances of the same field, since the following error shows up :

FieldException: Attempt to create an instance of field neologism_text on bundle property that already has an instance of that field. in field_create_instance() (line 488 of /Applications/MAMP/htdocs/gsoc/modules/field/field.crud.inc).

Here, I tried to create two instances of the installed field "neologism_text" in the bundle "property".

Am I missing out on some attribute in the instances which could prevent this clash?

For now, I installed separate fields for each instance that I would am using and everything works fine.

Comments

cygri’s picture

Hm, I'm trying to understand. Why would there be two instances of "neologism_text" on "property"? What does "neologism_text" even mean here? Shouldn't you have fields like "neologism_title", "neologism_comment", "neologism_superclasses" and so on?

mayankkandpal’s picture

The field instances are called property_comment, property_title etc.
But we need to install the fields first and then create their instances.

So if I create neologism_text, I thought I should be able to use it to create two instances required for the property bundle as in, say, property_title and property_comment. But it doesnt seem to work that way. So now I have created separate fields for each instance.

cygri’s picture

I'm not sure how this works, but I think the idea is that you create a neologism_comment field, and then you have field instances class_comment and property_comment. So you can re-use a single "comment" field in several bundles.

mayankkandpal’s picture

Yes, it will work this way, I tried it out.

mayankkandpal’s picture

StatusFileSize
new17.19 KB

Patch for creating bundles for Vocabulary, Class and Property. Now we can remove the 6.x branch as discussed on #1166054: Clean up releases of Neologism on drupal.org

Remaining Issues :

1. Node reference type fields not created yet. It is unclear whether I should use the References module (http://drupal.org/project/references) or the Relation module (http://drupal.org/project/Relation). Probably, we could discuss over their merits and demerits over here.

2. Bundles not grouped yet.

3. Fields left to be add :

Vocabulary:
add js for dynamically generating default Namespace URI
add text box for custom Namespace URI

Class:
node reference fields

Property:
node reference fields

4. not yet added display settings

mayankkandpal’s picture

Category: support » task
Priority: Minor » Major
mayankkandpal’s picture

StatusFileSize
new7.82 KB

Patch for adding display settings to the three bundles.
Apply this patch after the above #5: Support patch.

Anonymous’s picture

I spoke with scor over Skype. We both agree that you should use References right now. References will be deprecated at some point, but are in much better shape currently. Also, since we're currently using nodes, the Node Reference module in References project fits.

scor’s picture

@mayank unless there is a good reason to do otherwise, you should try to build on the same patch instead of posting separate patches which depend on each other... it's less confusing that way and easier to review (even if it makes the patch bigger).

in #5

+    1 => array(

should just be

+     array(

array keys don't matter in this context, PHP will add internally then when needed.

mayankkandpal’s picture

@Lin
Thanks, References it is then !

@scor
Will keep these things in mind in future. Thanks :)

mayankkandpal’s picture

I am facing an issue with the user_reference field, and have asked the References module developers for support #1171236: Problem while using the user_reference field in my bundle.

mayankkandpal’s picture

StatusFileSize
new27.38 KB

Patch for creating user_reference and node_reference fields. Minor changes to display settings and UI.

Does not depend on previous patches, apply to 7.x-2.x

mayankkandpal’s picture

However, the issue with the user_reference field stated in comment #11 (http://drupal.org/comment/reply/1165740#comment-4526388) still remains, since none of the Maintainers of References has replied yet.

mayankkandpal’s picture

StatusFileSize
new32.01 KB

Patch.
Added Javascript and modified Entity fields.
Apply to 7.x-2.x

Unfortunately the problem with user_reference field has'nt been solved yet since nobody replied on Drupal stack-exchange, Drupal support or the References issue queue.

mayankkandpal’s picture

Ok finally figured out the user_reference issue.

Did the following for a working user_reference field:

    dd(field_info_field("vocabulary_authors"));
    dd(field_info_instance("node", "vocabulary_authors", "vocabulary"));

and pasted all the missing fields into field and instance definitions. Couldnt figure out a better way !

Working snippet for future reference :

Field definition

    'vocabulary_authors' => array(
      'field_name' => 'vocabulary_authors',
      'type'        => 'user_reference',
      'settings' => array(
        'referenceable_roles' => array('2'=>'2','3'=>'3'),
        'referenceable_status' => array('1'=>'1','0'=>'0'),
      ),
      'default_widget' => 'user_reference_autocomplete', 
      'default_formatter' => 'user_reference_default',
      'cardinality' => FIELD_CARDINALITY_UNLIMITED,      
    ),

Instance definition

   'vocabulary_authors' => array(
      'field_name'  => 'vocabulary_authors',
      'label'       => $t(' Authors'),
      'bundle' => 'vocabulary',
      'entity_type' => 'node',
      'description' => '',
      'required'    => 0,
      'widget' => array(
        'weight' => -2, 
        'type'    => 'user_reference_autocomplete',
        'module' => 'user_reference',
        'active' => 1,
        'settings' => array(
         'autocomplete_match' => 'starts_with',
        ),
      ),
      'display' => array(
         'default' => 
         array (
           'label' => 'above',
           'format' => 'default',
         ),
         'teaser' => 
         array (
           'label'=>'above',
           'format' => 'default',
         ),
      ),
      
    ),  

mayankkandpal’s picture

Status: Active » Closed (fixed)
mayankkandpal’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Closed (fixed) » Fixed

version changed to 7.x

Status: Fixed » Closed (fixed)

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