Download & Extend

entity_field_value is completely broken

Project:Chaos tool suite (ctools)
Version:7.x-1.x-dev
Component:Code
Category:bug report
Priority:major
Assigned:Unassigned
Status:needs review

Issue Summary

This function is completely broken. Try add a condition on any field, and on saving you will get errors and notices everywhere.

I tried to fix it, but code is very complex, and i dont want to break it much more! Hope somebody can fix it soon, as lots of cases are not handled (conditions on taxonomy terms, etc)

Comments

#1

Status:active» needs review

Patch for making code work with taxonomy fields, and a PHP 5.4 notice/error

AttachmentSizeStatusTest resultOperations
ctools.patch2.92 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch ctools_0.patch. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#2

Status:needs review» needs work

The last submitted patch, ctools.patch, failed testing.

#3

Marked as duplicate #1435426: Notices thrown when using visibility rules on hidden fields

Also related issue #1520036: Notices thrown when taxonomy used for selection criteria

Both issues are depends on assumption that field contains only one storage column named 'value' but this wrong.
I think both issues should take a same approach for storing config and checking values in loop

#4

Status:needs work» needs review

This fix worked for us. Doesn't address the taxonomy issue, but it should pass the testbot.

AttachmentSizeStatusTest resultOperations
ctools-1630820-4-fix-php-notices.patch754 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 51 pass(es).View details | Re-test

#5

I'm having the same error but no joy with the patch.

I'd created some content types and was trying to set the selection rule on a panel as follows

Panels > Manage Pages > Edit Node Template > Add Variant with Selection Rules checked > Selecting Node type of my custom content. My selection rules on the summary page just say

This panel will be selected if value equals summary equals format equals

The main error i get is:

Notice: Undefined offset: 0 in ctools_entity_field_value_ctools_access_summary() (line 223 of /Library/WebServer/Documents/drupal/sites/all/modules/ctools/plugins/access/entity_field_value.inc).
Notice: Undefined offset: 1 in ctools_entity_field_value_ctools_access_summary() (line 223 of /Library/WebServer/Documents/drupal/sites/all/modules/ctools/plugins/access/entity_field_value.inc).
Notice: Undefined offset: 2 in ctools_entity_field_value_ctools_access_summary() (line 223 of /Library/WebServer/Documents/drupal/sites/all/modules/ctools/plugins/access/entity_field_value.inc).
Notice: Undefined offset: 0 in ctools_entity_field_value_ctools_access_summary() (line 223 of /Library/WebServer/Documents/drupal/sites/all/modules/ctools/plugins/access/entity_field_value.inc).
Notice: Undefined offset: 1 in ctools_entity_field_value_ctools_access_summary() (line 223 of /Library/WebServer/Documents/drupal/sites/all/modules/ctools/plugins/access/entity_field_value.inc).
Notice: Undefined offset: 2 in ctools_entity_field_value_ctools_access_summary() (line 223 of /Library/WebServer/Documents/drupal/sites/all/modules/ctools/plugins/access/entity_field_value.inc).

#6

Using Chaos Tools version 7.x-1.1, cannot set selection rules based on taxonomy field.

Notice: Undefined offset: 0 in ctools_entity_field_value_ctools_access_summary() (line 220 of /sites/all/modules/ctools/plugins/access/entity_field_value.inc).

<?php
 
foreach ($value_keys as $key => $value) {
   
$values[$value] = $elements[$key]['#markup'];
  }
?>

Here's some debug info:

<?php
print_r
($value_keys);

/*
Array
(
    [0] => @tid_value
)
*/
?>

<?php
print_r
($values);

/*
Array
(
    [@tid_value] => 7
)
*/
?>

<?php
print_r
($elements);

/*
Array
(
)
*/
?>

#7

If we're manually setting $display['type'] = 'list_default'; then we *must* always call list_field_formatter_view(). I'm trying to scratch my head why this is even running code through the list formatter by default. Why not just output the raw values in the summary??

#8

Personally I think until we're able to figure out how to get this to work showing field 'nice' values, then it should just stay simple and output the raw field values. Revised patch converts the summary to output the raw field values.

AttachmentSizeStatusTest resultOperations
1630820-field-value-access-summary-borked.patch3.24 KBIdlePASSED: [[SimpleTest]]: [MySQL] 60 pass(es).View details | Re-test

#9

Revised that doesn't fatal error. With the attached patch for taxonomy term fields I get a summary of 'tid equals 4, 5'

AttachmentSizeStatusTest resultOperations
1630820-field-value-access-summary-borked.patch3.25 KBIdlePASSED: [[SimpleTest]]: [MySQL] 67 pass(es).View details | Re-test

#10

After patch applied I get summary "tid equals ", and a warning in the next step:

Warning: implode() [function.implode]: Invalid arguments passed in ctools_entity_field_value_ctools_access_summary() (in line 205 of /sites/all/modules/ctools/plugins/access/entity_field_value.inc).

<?php
 
foreach ($field['columns'] as $column => $attributes) {
   
$string .= " @{$column} equals @{$column}_value";
   
$keys['@' . $column] = $column;
   
// Display the field values raw separated by commas.
   
$values["@{$column}_value"] = implode(', ', $conf[$field_name . '_' . $column]); // line 205
  
}
?>

$conf variable

Array
(
    [field_program] => Array
        (
            [und] => Array
                (
                    [0] => Array
                        (
                            [tid] => 7
                        )

                )

        )

    [field_program_tid] => 7
)

$field_name . '_' . $column evaluated value
field_program_tid

Passing a scalar value into implode() while array is expected. This could be made to work if checked for scalar value I suppose:

<?php
$value
=!is_array($conf[$field_name . '_' . $column]) ? array($conf[$field_name . '_' . $column]) : $conf[$field_name . '_' . $column];
$values["@{$column}_value"] = implode(', ', $value);
?>

#11

Custom node layout is still not showing, in addition, your patch throws number of notices now:

• Notice: Undefined index: taxonomy_term in zgrp_process_page() (line 58 from /themes/zgrp/template.php).
• Notice: Trying to get property of non-object in zgrp_process_page() (line 58 from /themes/zgrp/template.php).
• Notice: Undefined index: value in _ctools_entity_field_value_ctools_access_get_conf_field_values() (line 177 from /sites/all/modules/ctools/plugins/access/entity_field_value.inc).
• Notice: Undefined index: value in ctools_entity_field_value_ctools_access_check() (line 160 from /sites/all/modules/ctools/plugins/access/entity_field_value.inc).
• Notice: Undefined index: value in _ctools_entity_field_value_ctools_access_get_conf_field_values() (line 177 from /sites/all/modules/ctools/plugins/access/entity_field_value.inc).
• Notice: Undefined index: value in ctools_entity_field_value_ctools_access_check() (line 160 from /sites/all/modules/ctools/plugins/access/entity_field_value.inc).

#12

Anyone can fix this ? Please help. Need this in my project right now.
Cheers

#13

Priority:normal» major
Status:needs review» needs work

The more selection rules you add to the node template the list of error messages becomes bigger.

#14

I applied the patch in #9 and got the same output as #10.
Still experiencing the problem.

#15

This issue should be fixed after #1601062: Field access plugin ignoring selected value
Because currently ctools_entity_field_value_ctools_access_settings_submit() wrongly saves data for field and totally broken for compound fields.

The only question here is how to store values without breaking current config values, suppose hook_update_n() does not solve this problem.

The value that used to display summary stored in [field_name]_[column_name] see attached screenshot
ctools_access.jpg

For compound fields (link module for example) see second screenshot
ctools_access2.jpg

AttachmentSizeStatusTest resultOperations
ctools_access.jpg26.7 KBIgnoredNoneNone
ctools_access2.jpg55.61 KBIgnoredNoneNone

#16

This is very big bug I don't believe that maintenaners allow this kind of bugs

#17

Also perhaps this bug with tools produced another bug in views new feature. Groupde Filters.

http://drupal.org/node/1778378

#18

Title:ctools_entity_field_value_ctools_access_summary completely broken» entity_field_value is completely broken

It's not just the summary the whole thing seems to throw warnings and not really work.

#19

I have the same issue with taxonomy fields, I have the Notices, although the visibility rule works correctly.
I get 18 Notices like this one, when I am in the content tab, in pages->edit node_view in every variant I created:

Notice: Undefined offset: 0 en ctools_entity_field_value_ctools_access_summary() (línea 232 de /home/virtualmin/**********/public_html/nuevaweb/sites/all/modules/ctools/plugins/access/entity_field_value.inc).

#20

Also we could fix #1601062: Field access plugin ignoring selected value first
Because this Really completely broken

#21

Hello,
i run into this problem by upgrading from 7.x-1.1 to 7.x-1.2, so upgrading crashes my whole site.
In 7.x-1.1 all works fine for months.
I would change the version of this thread from 7.x-1.x-dev to 7.x-1.2.

#22

Status:needs work» needs review

#9: 1630820-field-value-access-summary-borked.patch queued for re-testing.

#23

The error "Undefined index: module in ctools_entity_field_value_ctools_access_summary" in the current stable version is caused by a condition on a field that is marked as "Hidden" in the node type display settings:

The error is caused because of the following lines in entity_field_value.inc:

  $display         = field_get_display($instance, $view_mode, $entity);
  $display['type'] = 'list_default';
  $function        = $display['module'] . '_field_formatter_view';

When the field is hidden in the display settings, $display['module'] does not exist. The code should check for that.

#24

Here's a right access check - we should not have False positives on NULLs

AttachmentSizeStatusTest resultOperations
1630820-ctools-access-24.patch1.87 KBIdlePASSED: [[SimpleTest]]: [MySQL] 67 pass(es).View details | Re-test

#25

Next steps:
1) Re-make settings form, probably we need incorporate #1601062-2: Field access plugin ignoring selected value
2) Provide upgrade old settings
3) Fix admin summary

#26

#24 isn't working

#27

@kaizerking what's not working? please explain your case!

#28

Here is the issue where I am getting notices, I have applied patch #24 and also the profile2 ctools patch

notices on page manager

#29

#24 did not work for me. I still have these notice error messages

Notice: Undefined index: module in ctools_entity_field_value_ctools_access_summary() Line 225 in sites\all\modules\ctools\plugins\access\entity_field_value.inc).

#30

Notice from #29 happens if the field is hidden on the entity and thus doesn't use a formatter.
Attached an updated patch that fixes this notice.

AttachmentSizeStatusTest resultOperations
1630820-ctools-access-30.patch3.24 KBIdlePASSED: [[SimpleTest]]: [MySQL] 67 pass(es).View details | Re-test

#31

#30 works! Great! Thanks a lot!

#32

I suspect I have a related problem. See #1876640: errors and not working selection rule when using negative check on a 'link'field for details. Might be a duplicate, not sure if the cause is exactly the same.
The patch from #30 doesn't solve the problem for me. It least not completely, still get errors in the backend but not on evaluation. So It probably has another (or secondary) cause.

#33

Combining the patch from #30 with the patch from #1780280: Notice on node view page variant seems to remove all notices for me. The selection rules I have tested so far seem to be working also.

Updated patch attached.

AttachmentSizeStatusTest resultOperations
1630820-ctools-access-33.patch3.28 KBIdlePASSED: [[SimpleTest]]: [MySQL] 67 pass(es).View details | Re-test

#34

Marked #1876640: errors and not working selection rule when using negative check on a 'link'field as a duplicate of this issue.
It really is a duplicate. Patch from #33 fixes it completely.

#35

Status:needs review» reviewed & tested by the community

Great to see access-summary fixed! Now it's ready to be commited

PS: Marked as duplicate #1780280: Notice on node view page variant as this hunk included

#36

Status:reviewed & tested by the community» fixed

Committed and pushed.

#37

The issue needs follow up to fix taxonomy fields when they have autocomplete/multiple values

#38

This patch solves the problem of saving and displaying values entered in the entity field form. Numbers, term references, entity references are tested (both singular and multiple (fixed) values). The remaining issue is multiple (unlimited) value form with 'Add more' button.

AttachmentSizeStatusTest resultOperations
entity-field-value-1630820-38.patch5.62 KBIdlePASSED: [[SimpleTest]]: [MySQL] 68 pass(es).View details | Re-test

#39

Status:fixed» needs review

#40

+++ b/plugins/access/entity_field_value.incundefined
@@ -103,8 +103,13 @@ function ctools_entity_field_value_ctools_access_settings($form, &$form_state, $
+        if (is_numeric($delta)) {

@@ -131,8 +136,33 @@ function ctools_entity_field_value_ctools_access_settings_submit($form, &$form_s
+  if (!is_array($items)) {

@@ -224,15 +266,58 @@ function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugi
+      if (is_array($elements)) {

Suppose if we carefully massage the values in onSubmit so $conf values could be plain array $delta => $value and no matter how many values are stored.
The only thing to care a Compound fields.

Take care that some widgets accept "multiple values" but some not. This leads to the confusion we have.
Probably better check the field cardinality.

+++ b/plugins/access/entity_field_value.incundefined
@@ -224,15 +266,58 @@ function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugi
+    // Choose simple formatter for well known cases.
+    switch ($display['module']) {
+      case 'list':
+        $display['type'] = 'list_default';
+        break;
+
+      case 'taxonomy':
+        $display['type'] = 'taxonomy_term_reference_plain';
+        break;
+
+      case 'entityreference':
+        $display['type'] = 'entityreference_label';
+        break;
+
+      default :
+        // Use field instance formatter setting.
+        break;

Awesome! The way of tokens/substitution does not help here...

+++ b/plugins/access/entity_field_value.incundefined
@@ -224,15 +266,58 @@ function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugi
+      if (count($field['columns']) > 1) {
+        // Add some sort of handling for compound fields

Needs @todo here

#41

A small change in this patch: do not output unprintable garbage generated by field formatter.

AttachmentSizeStatusTest resultOperations
entity-field-value-1630820-41.patch6.11 KBIdlePASSED: [[SimpleTest]]: [MySQL] 68 pass(es).View details | Re-test

#42

+++ b/plugins/access/entity_field_value.incundefined
@@ -103,8 +103,13 @@ function ctools_entity_field_value_ctools_access_settings($form, &$form_state, $
+        if (is_numeric($delta)) {
+          if (is_array($conf_value)) {
+            $form['settings'][$field_name][LANGUAGE_NONE][$delta]['value']['#default_value'] = $conf_value['value'];
+          }
+          else {
+            $form['settings'][$field_name][LANGUAGE_NONE]['#default_value'][] = $conf_value;

This part is primary required

+++ b/plugins/access/entity_field_value.incundefined
@@ -131,8 +136,35 @@ function ctools_entity_field_value_ctools_access_settings_submit($form, &$form_s
+    $form_state['input']['settings'][$field_name][$langcode] =
+      _ctools_entity_field_value_filter_items($field, $form_state['input']['settings'][$field_name][$langcode]);
     $form_state['values']['settings'][$column] = $form_state['input']['settings'][$field_name][$langcode];
   }
+  if (isset($form_state['input']['settings'][$field['field_name']][$langcode])) {
+    $form_state['input']['settings'][$field['field_name']][$langcode] =
+      _ctools_entity_field_value_filter_items($field, $form_state['input']['settings'][$field['field_name']][$langcode]);
+    $form_state['values']['settings'][$field['field_name']][$langcode] = $form_state['input']['settings'][$field['field_name']][$langcode];

This part needs to be simplified. No reason to bother 'input' here

+++ b/plugins/access/entity_field_value.incundefined
@@ -131,8 +136,35 @@ function ctools_entity_field_value_ctools_access_settings_submit($form, &$form_s
+function _ctools_entity_field_value_filter_items($field, $items) {

awesome function but needs php-doc about @params and @return

+++ b/plugins/access/entity_field_value.incundefined
@@ -224,15 +269,60 @@ function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugi
+      if (count($field['columns']) > 1) {
+        // Add some sort of handling for compound fields
+      }
+      else {
+        $keyed_elements["@{$column}_value"] = $elements;
+      }

Please change condition to exclude empty statement

#43

The next try. Autocomplete widgets still don't work. Compound fields (with multiple sql columns) seem to work. The full plugin file is attached also.

AttachmentSizeStatusTest resultOperations
entity-field-value-1630820-43.patch11.01 KBIdlePASSED: [[SimpleTest]]: [MySQL] 68 pass(es).View details | Re-test
entity_field_value.inc_.txt13.37 KBIgnoredNoneNone

#44

If a field does not have a value stored at all yet for a particular entity, checking against the '- None -' value (_none) fails.

#45

I'm not convinced about this approach. But, I have taken the follow patch from #43, and added to it some provisions to handle the case where no value is saved for a field.

AttachmentSizeStatusTest resultOperations
entity-field-value-1630820-45.patch13.1 KBIdlePASSED: [[SimpleTest]]: [MySQL] 68 pass(es).View details | Re-test

#46

Probably best to provide interdiffs for reviewers.

#47

Comparing with '_none' or other magic constants is not the right way. I'll provide the improved patch soon (with solves autocomplete fields issue also). BTW, the real fun is permitting to configure the field comparison against file field or field collection field. :)

#48

EclipseGc++
Having interdiffs is much better way to get proper reviews!!!

Suppose it's clear that there's no way to save BC for broken data but after #33 we have in 7.x-dev there's a probability that some sites have working config. So the follow-up code that introduces support for "Compound fields" is really great and better to have it commited before next ctools' stable release.

@mrfelton please explain the difference in your approach. The issue is really needed and annoying same time...

+++ b/plugins/access/entity_field_value.incundefined
@@ -103,8 +103,13 @@ function ctools_entity_field_value_ctools_access_settings($form, &$form_state, $
+            $form['settings'][$field_name][LANGUAGE_NONE][$delta]['value']['#default_value'] = $conf_value['value'];
...
+            $form['settings'][$field_name][LANGUAGE_NONE]['#default_value'][] = $conf_value;

@@ -211,7 +244,19 @@ function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugi
+              $entity->{$field_name}[LANGUAGE_NONE][] = array($column => $conf_value);
...
+              $entity->{$field_name}[LANGUAGE_NONE][] = array($column => $conf_value['value']);
...
+          $entity->{$field_name}[LANGUAGE_NONE][] = array($column => $conf[$conf_key]);

@@ -224,15 +269,60 @@ function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugi
+      field_default_prepare_view($entity_type, $entity_group, $field, $instance_group, LANGUAGE_NONE, $item_group, $display);
+      $elements = $function($entity_type, $entity, $field, $instance, LANGUAGE_NONE, $item_group[0], $display);

Another funny part for localization...

+++ b/plugins/access/entity_field_value.incundefined
@@ -131,8 +136,35 @@ function ctools_entity_field_value_ctools_access_settings_submit($form, &$form_s
+      _ctools_entity_field_value_filter_items($field, $form_state['input']['settings'][$field_name][$langcode]);

using $form_state['values'] are solves the problem

#49

I didn't want to derail the patch that's in here (though if people like what I've done it will derail things anyway). However, I was pretty pressed for time and I just wanted to make this work. So without further ado, I posted a patch here: #1955954: entity_field_value.inc is mostly useless.

#50

Okay I'm seeking advice. I was having the same errors as above. I tried the patch in #45 and I still had errors. Then I followed the thread in #49 and applied that patch. The errors continued.

So I did two things that I thought would help. I installed the current dev version and used the patch in #45 and I uninstalled the relationship module (because it uses entity fields).

Now I simply get an error:

Error
Error message

Notice: Trying to get property of non-object in ctools_entity_field_value_ctools_access_check() (line 207 of /home/dte/public_html/sites/all/modules/ctools/plugins/access/entity_field_value.inc).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7663 of /home/dte/public_html/includes/common.inc).

The website encountered an unexpected error. Please try again later.

So what would your next move be here? I suppose I could roll back a few days, but then I would loose the Views I built.

Any ideas?

AttachmentSizeStatusTest resultOperations
Screen shot 2013-05-14 at 5.26.15 PM.png54 KBIgnoredNoneNone

#51

Could you try #43?

#52

@maximpodorov -- Sorry, late last night I made the call to just roll back the database, delete the Relationship module and rebuild my Views. However if you want I can email you the broken database.

I wonder if it would make sense to have a "known issues" notice on the cTools project page.

With a full version 1.3 release and no mention of any trouble, "module monkeys" (okay, site builders) like me can land them selves in some devastatingly hot water.

Of course CTools is needed now for Views, but it would nice nice to see a "Known Issue" warning stating that there is a current bug with evaluating conditional fields that causes problems with the Relationship module and autocomplete Taxonomy fields. See (this thread).

Had I read that I would have tread a bit more carefully.

#53

Here is the revised patch. It contains the fix of the problem described in #50. Other small improvements are there. Please test and review.

AttachmentSizeStatusTest resultOperations
entity-field-value-1630820-53.patch12.83 KBIdlePASSED: [[SimpleTest]]: [MySQL] 121 pass(es).View details | Re-test