I created 2 features which use a common CCK field (e.g. field_xyz_images - a multiple imagefield, but I think this is unimportant for my problem).
But the widget settings (e.g. the label) were different, when I created both features.
After installing both features on a fresh site there is only one label version for both content types. And visiting features admin pages shows 'overridden' for the CCK fields of the 2nd feature.

Also the different order of elements in "Manage fields" section of the 2nd content type is ignored and the order of the 1st content type is used, when I visit node add/edit form.

Any solutions available?
Is this a known bug?

CommentFileSizeAuthor
#9 features_content_wrong_weight.patch596 bytesDavid Stosik

Comments

john.karahalis’s picture

We can confirm this behavior.

If one CCK field is used by two different content types, any Features using that field will be listed as "Overridden" immediately after being enabled. We also noticed a problem with help text. If a field was originally used in two different places with two different help texts, only one help text will be used in both places after the field is wrapped into a Feature.

By the way, great work with the module (and with Managing News, and Open Atrium, and all the other amazing stuff you do :-)).

m_z’s picture

I can provide some simple code (for the maintainers of the Features module) to switch between different cases when adding a CCK field via Features module.
The code is a modification of different code that I found at Drupal.org. I used the code for my own "CCK-definitions-in-code"-import module, but Features module is much better!!!
Maybe this can be a starting point to solve this issue:

/**
 * Create a new field or add an existing field for an existing content type.
 *
 * @param $content_type
 *   Required. Existing content type (text id).
 * @param $field_name
 *   Required. A field name using only alpha-numeric and underscores.
 * @param $field_widget_type
 *   Required. A special name that uniquely identifies both the field type and
 *   widget type. Each option item on the first page of the 'Add Field' form.
 * @param $label
 *   Required. Label of the CCK field.
 * @param $properties
 *   Optional. An array of additional properties for the field.
 */
function myfunc_create_or_add_existing_field($content_type, $field_name, $field_widget_type, $label, $properties = array()) {
  module_load_include('inc', 'content', 'includes/content.admin');
  module_load_include('inc', 'content', 'includes/content.crud');

  $content_fields = content_fields();
  $content_types = content_types($content_type);
  if (!isset($content_types['fields'][$field_name])) {
    // Not existing CCK field in content type.
    if (!isset($content_fields[$field_name])) {
      // Create new CCK field.
      myfunc_create_field($content_type, $field_name, $field_widget_type, $label, $properties); // FEATURES must put its own function here!!!!
    }
    else {
      // Add existing CCK field to content type.
      myfunc_add_existing_field($content_type, $field_name, $field_widget_type, $label); // FEATURES must put its own function here!!!! - AND this is the place which seems to be missing in FEATURES at the moment, because here only a new 'content_node_field_instance' entry (= a new widget for another content type) will be created.
    }
  }
  else {
    // Already existing CCK field in content type.
    // NOTHING happens here in my use case, but maybe this is the place for a FEATURES callback to update an existing CCK field!!!
  }
}
hadsie’s picture

I'm running into this same issue. It looks like the field settings are being written properly to the feature. They're all set as the should be when i check defaults.inc. For some reason they just aren't getting re-imported into the system properly.

Also, for the field order issue, I submitted a patch for it here that seems to be working for me so far: #693944: Add strongarm integration in features.content.inc for 'content_extra_weights_[typename]' variable

m_z’s picture

Does anybody know how CCK fields are "imported" by Features module?
Do they a) live in code (at runtime) or is there b) a physical import into the database.
I don't have the time to dive into Features module's code, but I think that b) is the right answer.
Then the next question would be: Does Features module use some API functions of Content (CCK) module or are there own CCK import functions in Features module.

To solve this issue we must find the place where the switch (see #2) must be included...
(and maybe we need some additional code to handle the case "Add existing CCK field to content type.")

yhahn’s picture

Title: Usage of same CCK field in different features (with different widget settings) causes problems » Same CCK field in different features (with different widget settings) causes problems
Category: bug » task

I won't be looking deeply into this anytime soon but I can certainly answer these questions if someone wants to explore the issue further and jot some notes down (or work a patch to fix it).

CCK fields are indeed imported into the DB as they are not true exportables. Features uses the CCK API functions (OTOH content_field_instance_create() and content_field_instante_update()) in includes/features.content.inc.

m_z’s picture

Thanks yhahn!

In my own approach I use drupal_execute() to create my CCK fields from my CCK field settings code (it differs a little bit from what you get by using CCK export functionality).

Going this way I get the wanted behaviour that there is no difference between the creation of a CCK field manually (via UI) and the creation of a CCK field with my own import logic.
Especially the case "existing CCK field for a new content type" (which is causing the trouble in Features module) works well with my approach.

Do we have a CCK expert here who is familar with CCK API functions? I don't have the time to become such a CCK expert right now...

Like said before: I like Features module and I am interestend in a working CCK import inside Features module.

joachim’s picture

Category: task » bug

I'm seeing a problem with the same field on different types -- if one type is then removed, parts of CCK still think the field is using the multivalued storage system, and subsequent node save operations fail.

m_z’s picture

Where is our CCK guru to solve this issue?

A starting point for some research could be 'Manage fields' form at content type settings (admin UI): http://drupalcontrib.org/api/function/content_field_overview_form/6
I think that comparing the 'manual way' of CCK field creation (or update) via admin UI with the 'automated way' in Features module is the key to find a solution.

The relevant function inside Features module should be: http://drupalcontrib.org/api/function/content_features_rebuild/6
Right?

And this is the code that I used as basis for my own CCK import functionality (which is working fine, but I like Features module UI...)
http://drupalcontrib.org/api/drupal/contributions--install_profile_api--...
There is a content_field_edit_form_submit (http://drupalcontrib.org/api/function/content_field_edit_form_submit/6) call at the end of install_create_field function which is not included in content_features_rebuild function inside Features module (see above). Could this be the reason???

Enough for today. Maybe someone helps me, diving into this issue...

David Stosik’s picture

Version: 6.x-1.0-beta5 » 6.x-1.0-beta6
Status: Active » Needs review
StatusFileSize
new596 bytes

Hello,
I think I spotted a possible origin for this issue.
See function content_field_instance_create() in content.crud.inc ?

If a prior instance of the field is already existing, then this function sets $field['widget']['weight'] (and label and description) to the value inside $form_values, or, if it is not set, to the value of the previous instance. Hence, the first imported field instance gets the right weight, but the following instances of the same field get the first's weight instead of their own weight.

What I suggest is, in features.content.inc, before calling content_field_instance_create(), set the weight, label and description at the field level, because content_field_instance_create() will use them as the $form_values.

Please find my suggested patch attached.

Regards,
David

sdelbosc’s picture

Just to track the issue...

jonskulski’s picture

subscribing.

m_z’s picture

@David:
Thank you for your patch.
I will test it in the next days and report back here...

D.H.’s picture

Thanks for the patch. I used an image field on two cck types and changed the order and also the label names and it seems to work properly.

m_z’s picture

Status: Needs review » Reviewed & tested by the community

For me it seems to work properly, too. Changed status to rtbc.

@David: Thanks again.

jonhattan’s picture

thanks. It works here also.

---
and drush make is awsome :)

projects[features][patch][] = "http://drupal.org/files/issues/features_content_wrong_weight.patch"
yhahn’s picture

Status: Reviewed & tested by the community » Fixed

Thanks: http://drupal.org/cvs?commit=370120

Update your makefiles : )

Status: Fixed » Closed (fixed)

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