I've not tried to include conditional fields in a feature before, so forgive me if I have this wrong.
I included the conditional field component for a content type and it appeared to be created and then imported into another site correctly (it shows as a component in the feature in the other site).

However, when I check the 'manage dependencies' tab of the content type in the site the feature was imported into, I see no dependencies.

Am I doing something wrong or is this a bug?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Shadlington’s picture

The conditional_fields.inc file in the feature contains only the following function:

function jobs_conditional_fields_default_fields() {
  $items = array();

  return $items;
}
Shadlington’s picture

Category: support » bug

I thought maybe I was doing this wrong but now I'm pretty certain this is a bug.
No matter what I do, the generated feature doesn't contain anything other than the code in my previous post.

dalguete’s picture

Hi guys

I made two patches for this bug. Hopefully this will help you too. Feedback appreciated.

Frippuz’s picture

It seems like GIT is having problems reading the patches by dalguete. I remade them using git diff.
All creds to dalguete for the coding.

willvincent’s picture

Here's an older p0 format of the patch in #4 that can be applied with a drush make.

willvincent’s picture

Forgot to mention (though it was probably implied) the patch from #4 works for me.

Shadlington’s picture

Patch #4 works for me too!

willvincent’s picture

Status: Active » Reviewed & tested by the community

Marking RTBC

JordanMagnuson’s picture

I'm new to this whole patching business, and I'm having trouble getting these to apply... is there something I'm doing wrong?

  1. Create text file in my conditional_fields module directory, rename to "conditional_fields_features.patch".
  2. Paste in patch code from #4.
  3. Git bash conditional_fields module directory -> $ git apply -v conditional_fields_features.patch

I'm getting "trailing whitespace" messages, then "fatal: corrupt patch at line 43."

I'm sure I'm missing something obvious.

Shadlington’s picture

Probably best to just download the patch file rather than using C&P

mrfelton’s picture

Patch in ¢ works for me too. Thanks.

mrfelton’s picture

Patch in #4 works for me too. Thanks.

acrollet’s picture

works for me as well, export and revert - any chance of getting this into a release?

thanks much!

geek-merlin’s picture

Priority: Normal » Major

daring to mark critical. hey, it's features suppport!

3rdLOF’s picture

Not for me:

In one install the error does not appear, on the other, both create and recreate generate this:

Warning: Invalid argument supplied for foreach() in conditional_fields_features_export_options() (line 14 of /Users/quiky/Sites/sepul/sites/all/modules/contrib/conditional_fields/includes/conditional_fields.features.inc).

emattias’s picture

The changes in #3 causes the conditional_fields_features_rebuild to not work since it depends on the old structure of the $dependancies before #3 which makes reverting of conditional fields settings not work, since it's not able to delete settings before inserting the settings from the features export.

Heres a patch that includes dalguete changes from #3 and also makes conditional_fields_features_rebuild work when the patches in #3 are applied.

I haven't deepdived into this new features implementation. All I did was make the rebuild work with the new structure introduced in #3. From my testing this seams to fix reverting of conditional fields settings.

emattias’s picture

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

Status: Needs review » Reviewed & tested by the community

Great work! Patch works nicely.

I've tested:

  1. Created 2 conditional fields
  2. Added those settings to a feature
  3. Changed a conditional field setting
  4. Verified that the feature is overridden
  5. Reverted the view
  6. Settings is back to normal

Please commit this patch to the module.

rogical’s picture

this module is very useful, but seems update with a bit late.

I suggest someone can take a role of co-maintainer.

mariano.barcia’s picture

[edit] well I guess not, I'll try how it works with features in D6

Hi! Would this last patch in #16 work in v6.x-2.0?
Thanks

BarisW’s picture

No Mariano, this is a patch for D7.

tim.plunkett’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.35 KB

This module followed the documentation properly, unfortunately the docs were incorrect: #1402262: features.api.php mentions 'features_source' key, but the actual key in use is 'feature_source'

Updated the patch.

tim.plunkett’s picture

Switched to using features_var_export, it pretty-prints the arrays better.

ShaneOnABike’s picture

I can confirm that this patch works although when I tried to apply it it complained and I had to modify teh file. Could you regenerate your patch to be just above the conditional_fields directory rather then where you did. It makes it harder to apply for those non-GIT geeks. :P

tim.plunkett’s picture

@ShaneOnABike try patch -p1 < conditional_fields-1275284-23.patch

rlmumford’s picture

Here's the patch in the right directory. Can confirm that it does the trick. Thanks tim.plunkett!

rlmumford’s picture

Whoops! Uploaded the wrong one..

BarisW’s picture

One minor addition in conditional_fields_features_export_options()

I changed
$dependencies = conditional_fields_load_dependencies();

into

if (!$dependencies = conditional_fields_load_dependencies()) {
  return;
}

Because I got a PHP notice that '$dependencies was not an array' when I want to create a feature and I didn't create any conditional fields yet.

ShaneOnABike’s picture

@tim.plunkett That worked great :)

alberto56’s picture

Status: Needs review » Needs work
FileSize
89.32 KB

Hi, thanks for the patch.

I am getting the following error when running automated tests (see also enclosed image):

Undefined index ... in conditional_fields.features.inc

To reproduce, simply export any conditional fields into a feature, and add an associated .test file and run it.

Cheers,

Albert.

TravisCarden’s picture

The patch in #27 worked for me, with the caveat that when I migrated changes I was unable to revert the conditional fields components from Drush—I had to do it from the UI, for some reason.

leewillis77’s picture

The patch in #27 doesn't work for me. I'm exporting a feature, and then activating the feature as part of an install profile. During site installation I get a number of warnings of the form:

Notice: Undefined index: field_resource_type in conditional_fields_features_rebuild() (line 105 of /home/webserver/testinstall3/sites/all/modules/conditional_fields/includes/conditional_fields.features.inc)

and no conditional fields are on the system when I view the content type and hit Manage Dependencies. Could it be that its trying to set up the conditional fields before creating the fields?

jantoine’s picture

The error reported in #32 is happening because Features is trying to create the conditional fields before the fields have been created. If features provides a way to control the order of execution, conditional fields should not be run until after fields have run. A work around is simply to revert the feature once installed. I have verified this using the patch in #27.

tim.plunkett’s picture

Hm, conditional_fields could implement hook_module_implements_alter() to ensure it runs after field.module.

leewillis77’s picture

Following Tim's suggestion, the updated attached patch includes #27, and in addition implements hook_module_implements_alter() to force conditional fields' implementation of hook_features_api to run last.

This works for me as part of an install profile without requiring the feature to be reverted post install to take effect.

kalis1’s picture

Just a note to say that the patch in #35 works well. Thank you !

tim.plunkett’s picture

+++ b/conditional_fields.moduleundefined
@@ -1719,6 +1721,18 @@ function conditional_fields_dependency_description($dependee_name, $dependent_na
+  if ( 'features_api' == $hook && isset ( $implementations['conditional_fields'] ) ) {
+    unset ( $implementations['conditional_fields'] );

No spaces after parentheses. Also, this should follow the example given in http://api.drupal.org/api/drupal/modules%21system%21system.api.php/funct... and use $group, not just assign ''.

leewillis77’s picture

Status: Needs work » Needs review
FileSize
5.11 KB

Fair comments. Updated patch attached.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community

Awesome!

drupalycious’s picture

The patch doesn't work for me,

it might be a different issue.

When I want to create a feature, I have the following error message:
Notice: Undefined index: in conditional_fields_features_export_options() (line 18 of my-drupal-site-directory/sites/all/modules/conditional_fields/includes/conditional_fields.features.inc).

I applied the patch in #38 and during the patch I got:

|diff --git a/includes/conditional_fields.features.inc b/includes/conditional_fields.features.inc
|index c3ad326..ae9a912 100644
|--- a/includes/conditional_fields.features.inc
|+++ b/includes/conditional_fields.features.inc
--------------------------
File to patch: conditional_fields.features.inc
patching file conditional_fields.features.inc
patch unexpectedly ends in middle of line
Hunk #3 succeeded at 90 with fuzz 1.

and then in the website, the error message in the create features section became:

Warning: Invalid argument supplied for foreach() in conditional_fields_features_export_options() (line 14 of my-drupal-site-directory/sites/all/modules/conditional_fields/includes/conditional_fields.features.inc)

tim.plunkett’s picture

#40 did you apply that to the latest dev? It applied cleanly for me.

drupalycious’s picture

Yes, I applied it to the latest dev.

tim.plunkett’s picture

git clone --branch 7.x-3.x http://git.drupal.org/project/conditional_fields.git
cd conditional_fields
curl http://drupal.org/files/conditional_fields-1275284-38.patch | git apply

leewillis77’s picture

#40 - looks like the patch file you have is incomplete - can you re-download and try again?

"patch unexpectedly ends in middle of line"

jantoine’s picture

The patch in #38 is good, please commit!

drupalycious’s picture

@tim.plunkett and @ leewillis77

you were right I didn't applied the patch correctly, I copied the patch and used -p0.
I am still learning...

The patch is good for me too.

Thank you

hlykos’s picture

Patch works great

peterpoe’s picture

Status: Reviewed & tested by the community » Fixed

Just committed, thanks dalguete, emattias, tim.plunkett, leewillis77 + all testers.

Status: Fixed » Closed (fixed)

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