I've got a pretty serious rewrite. I'm putting this into a new issue because I don't want to derail an existing issue. Patch forthcoming.

This is a follow-up form #1630820: entity_field_value is completely broken

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

merlinofchaos’s picture

Status: Active » Needs review
FileSize
13.7 KB

This is a pretty serious rewrite. I had to make use of entity_field_value.inc for a project, and I found it fell very short of the mark of being useful.

This patch is still flawed, but it at least gets it to usability with basic fields: int, text, list, date. It doesn't do anything with file fields right now, and it's completely broken with field_collection. It does seem to work with at least one entityreference field, but that's dependent entirely upon how the entityreference widget is set up. I do believe it should, in fact, mostly work with reference fields in general.

Some of the problems I identified:

1) It used a nearly nonsensical method to set #default_values on the form that it used and it broke on date fields.
2) It used a totally nonsensical method to extract the values from the resulting form, and then made extra copies of them for no apparent effect.
3) The summary provided no information at all.
4) No operators meant limited utility in general. Exact match is fine for checkboxes but that's just about it.

Flaws of note:
1) List support is hardcoded; it seems like there should be a set of hooks that could be used to let field types extend this.
2) Fields mentioned above will be broken.

mcfilms’s picture

What is the best course of action if someone is getting the Undefined index: field_image_fid in ctools_entity_field_value_ctools_access_summary() errors? (As well as similar ones for width, alt, etc.)

I didn't realize entity fields were mostly useless and was using them on my panels page. Now I cannot edit or save my panels page without an error. Is this patch the best fix?

merlinofchaos’s picture

Yes. Dependent upon when I get time to do it, this patch or a future variant of it will get committed.

mcfilms’s picture

After applying this patch I am now prevented from editing my panel page. However I am getting two errors:

Notice: Undefined index: field_image in ctools_entity_field_value_ctools_access_summary() (line 271 of /home/dte/public_html/sites/all/modules/ctools/plugins/access/entity_field_value.inc).

Notice: Trying to get property of non-object in ctools_entity_field_value_ctools_access_summary() (line 300 of /home/dte/public_html/sites/all/modules/ctools/plugins/access/entity_field_value.inc).

mcfilms’s picture

Lines 269 to 304 of entity_field_value.inc look like this:

$entity      = (object)array(
    $entity_info['entity keys']['bundle'] => $bundle_type,
    $field_name => $conf[$field_name],
  );

  $operator = isset($conf['operator']) ? $conf['operator'] : '==';

  $render_array = field_view_field($entity_type, $entity, $field_name);

  // Special support for lists.
  if ($field['module'] == 'list' && count($conf[$field_name][LANGUAGE_NONE]) > 1 && ($operator == '==' || $operator == '!=')) {
    if ($operator == '==') {
      $operator = 'is one of';
    }
    if ($operator == '!=') {
      $operator = 'is not one of';
    }

    $values = array();
    foreach (array_keys($conf[$field_name][LANGUAGE_NONE]) as $index) {
      $values[] = drupal_render($render_array[$index]);
    }
    $value = implode(', ', $values);
  }

  if (!isset($value)) {
    // We don't want the field template or label or anything, just the value.
    $value = drupal_render($render_array[0]);
  }

  $values = array(
    '@identifier' => $context->identifier,
    '@field' => $instance['label'],
    '!value' => $value,
    '@operator' => $operator,
  );

merlinofchaos’s picture

Based on #4, I'm going to guess that this system isn't really compatible with the format used for images.

What exactly are you trying to do in a comparison plugin with images? There's not really much to compare.

andypost’s picture

merlinofchaos’s picture

Please note that I'm using this patch on a site and I'm pretty confident in it; I'd been hoping for more feedback from people, but alas.

Further work on that other patch is probably not going to go anywhere, as this will entirely supercedei t.

maximpodorov’s picture

I'd recommend to have two distinct plugins, since they are of different purposes. For example, you can't compare fields having multiple properties by any operator but equivalence. entity_field_value with the last patch from http://drupal.org/node/1630820 supports such fields. Even field collections can be supported in the future.

mcfilms’s picture

@merlinofchaos - It is entirely possible I was "doing it wrong" when I broke my site. I had a content type made up of images and I was creating a views slideshow based on taxonomy terms. Then I was putting this slideshow in a panel by using a relationship. If you really want to see it I can send you a clone of the site or the database.

Meanwhile, it seems you are both closing in on a fix from two different directions. It'd be nice if we could get the best of both. Any chance of a collaboration?

As I posted in that other thread, I think it would nice nice to see a "Known Issue" warning on the cTools module page stating that there is a current bug with evaluating conditional fields that causes problems with the Relationship module and/or autocomplete Taxonomy fields.

merlinofchaos’s picture

Yes, I absolutely want to collaborate and I think that if there are things that other patch is doing that this one is not, we should get them together and have tea.

Alpinist1974’s picture

@merlinofchaos

Hi,

Re #11, I was just wondering if there are still plans to fix/commit the entity fields/access/selection rules plugin issue? I'd really love to be able to use this in my current project. I've tried all of the patches and nothing seems to work for me. CTools and Panels are superb modules, I just wish they'd play nice with entity.

Thanks!

Matt

maximpodorov’s picture

@Alpinist1974, do you confirm http://drupal.org/node/1630820#comment-7419790 does not work for you?

Alpinist1974’s picture

Confirmed; this patch does NOT work for me. While I can see the saved value of the field in the Description box (could not previously), I now receive this message:

Notice: Undefined index: #parents in field_default_form() (line 49 of C:\wamp\www\lc2030\modules\field\field.form.inc).

Moreover, the behavior is the same: The access test still fails when it should pass, i.e., the field value is present in the user form and seems to be present in the access field, yet access is still not granted.

Thanks,

Matt

merlinofchaos’s picture

Yes, I completely intend to commit the patch in this issue, preferably merged to fix other issues.

If the patch in this issue doesn't work for you, I'll need specifics to address it.

Alpinist1974’s picture

Great, thanks! I provided some details in #14 of this issue. Let me see if I can find anything else that might be useful.

merlinofchaos’s picture

For #14: What type of field is it, and exactly how are you configuring it?

Alpinist1974’s picture

The field is a taxonomy term reference, used in a select list, configured in a Profile2 field.

I have gotten the same results, however, using ordinary text fields and hierarchical select term reference fields, all from within Profile2.

merlinofchaos’s picture

Odd. I'm using this just fine with ordinary text fields. I've never tested it with a term reference. I wonder what the difference is. Well, I'm not using profile2; that could be a difference I suppose, but I shouldn't think it would make a difference.

Alpinist1974’s picture

I double checked the text fields and they still don't work, when passed in as user fields through entity.

Also, this problem doesn't seem to be limited to access--I can't use any of these values either as selection criteria either.

Here are some warnings I get:

Warning: implode() [function.implode]: Invalid arguments passed in field_multiple_value_form() (line 199 of C:\wamp\www\lc2030\modules\field\field.form.inc).

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in field_multiple_value_form() (line 199 of C:\wamp\www\lc2030\modules\field\field.form.inc).

I'm fairly new to CTools/Panels, but I don't think I'm doing anything wrong here. I really love the concept of per page variants, and I'm trying to leverage this in a complex troubleshooting algorithm, that will show/hide page content based on taxonomy terms passed in through a configuration page, in the user's profile. Hence the need to use Profile2 and access and selection rules.

andypost’s picture

Suppose better to split patches:
- current should operate as is + patch #1630820: entity_field_value is completely broken
- new one build on top of that issue with extended operation to compare (just for text fields)

Actually support for different cardinality should live in first one

maximpodorov’s picture

@Alpinist1974, integration between ctools and Profile2 is known to be broken. Could you try http://drupal.org/node/1630820#comment-7419790 in any other case?

Alpinist1974’s picture

@maximpodorov

I am currently using this patch and it doesn't seem to work.

Thanks for the heads up about Profile2 and Panels. Guess I'll check the issue queue there.

Alpinist1974’s picture

@andypost

I tried using the dev version of Profile2 and still no luck. I see you wrote a patch:

https://drupal.org/node/1011370#comment-6884220

Was this committed to dev? If not, do you think it might work here?

Thanks!

jhodgdon’s picture

merlinofchaos pointed me at this issue from
#2022677: Taxonomy term selection rule is not displayed properly in Panels Page

I tested this with a taxonomy term reference, and the Summary is still broken -- see comment #2 on that other issue.

jhodgdon’s picture

Issue summary: View changes

Updated issue summary.

andypost’s picture

So the solution for the issues should care about already configured values, and then I think better to use some glue code to make a equal and extended settings splitter

@Alpinist1974 the profile2 related issue is #1011370: Ctools relationship from user
You need 2 patches to solve your case

ceepeebee’s picture

I had a problem with selection rules on a page variant (test on emptiness of a date field). (ctools 7.x-1.3+4-dev, page manager 7.x-1.3+4-dev both included with Drupal Commons 3.4)
This patch #1 worked for me very well.

I tried patch #58 submitted on #1630820: entity_field_value is completely broken as well. While it did get rid of the errors/notices, it didn't solve my problem, because it doesn't allow the comparisons I needed.

Many thanks to merlinofchaos for making this possible.

How can I help to test this patch thoroughly?
Are there any intentions to merge the patches?

DamienMcKenna’s picture

@ceepeebee: I think we need thorough testing and full documentation on what works & doesn't work for both this and #1630820.

busla’s picture

I guess I should report aswell.

I´m getting these messages when using a taxonomy term field on a node as a selection rule in my panel.

Notice: Undefined index: #parents in field_default_form() (line 49 of /Applications/MAMP/htdocs/mysite/modules/field/field.form.inc). =>

Notice: Undefined index: field_post_category_tid in ctools_entity_field_value_ctools_access_settings() (line 112 of /Applications/MAMP/htdocs/mysite/profiles/myprofile/modules/contrib/ctools/plugins/access/entity_field_value.inc). =>

droath’s picture

I guess I should have checked the issue queue before rewriting the entity_field_value.inc access plugin again. Lesson learned! :)

I took a brief look at the existing patch and from what I can tell I'm using a different approach. So I thought I'll post my patch here as well, as it might help solve some other issues.

maximpodorov’s picture

Why do you ignore the working solution: https://drupal.org/node/1630820#comment-7745811 ? :)

Status: Needs review » Needs work

The last submitted patch, 30: entity_field_value_broken_alternative-1955954-30.patch, failed testing.

The last submitted patch, 1: 1955954-entity-field-value-broken.patch, failed testing.

osopolar’s picture

Coming from #1962124: Visibility rules failing for non textareas fields I wonder what it needs to get visibility rules work for example for entity reference field. Is work on this issue still valid, as #1630820: entity_field_value is completely broken got fixed or do we have to start from zero?

andypost’s picture