I need to position some items based on a field value e.g. checkbox is enabled

How can I filter one content types with a specific taxonomy term and with these checkbox enabled?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mike.davis’s picture

Issue summary: View changes
FileSize
5.76 KB

Hi @hass,

I have recently had the need to also add a condition based upon a field name value., here is a patch that has worked for me.

This currently just provides a list of fields that are available in the site and a text field for the value to match against. This currently only works for node data, but it probably wouldn't be a big change to make it work with taxonomy as well.

Thanks
Mike

mike.davis’s picture

Status: Active » Reviewed & tested by the community

Forgot to mark it for review.

mike.davis’s picture

Status: Reviewed & tested by the community » Needs review

arh ... wrong status .. sorry :)

rvilar’s picture

It works for me.

Agileware’s picture

Updated patch to #1 which fixes a problem where Entity Reference field values were not being compared.

axe312’s picture

Patch is working very well with list fields. Haven't testet it yet with entity reference fields.

Leksat’s picture

I did not look at the code, but can confirm that #5 patch works well with common fields.

kreatIL’s picture

Patch #5 works for me. In my use case I'm checking against a multi-value entity reference field which references taxonomy terms. Therefore I had to add a new line after line 24:

if ($variables['content_field_name']=="my_field_name") $field_value = $node_wrapper->my_field_name[0]->name->value();

in order to retrieve the name value of delta#0 for that field.

I'm sure there would be a more flexible solution for that, but in my special use case it works perfectly.

mstrelan’s picture

Patch #5 does not work for multi-value fields, eg select lists. Also updated if statements to use Drupal coding standards and use of drupal_map_assoc() instead of array_combine().

rv0’s picture

Thanks for this patch, works very well!!

cdmo’s picture

Status: Needs review » Reviewed & tested by the community

#9 worked for me on a select list. I applied the patch to 7.x-1.2

Thanks!

BarisW’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/plugins/menu_position.content_field_value.inc
    @@ -0,0 +1,113 @@
    +    $field_values = $node_wrapper->{$variables['content_field_name']}->value(array('identifier' => 'TRUE'));
    

    What is this 'identifier' => 'TRUE'? I've never seen it. What's its use?

  2. +++ b/plugins/menu_position.content_field_value.inc
    @@ -0,0 +1,113 @@
    +  $fields_name = array('' => '- please select -') + $fields_name;
    

    This should be
    '#empty_option' => t('- Please select -'),

    on the select. Mind the t().

Other than that, the patch looks good. Please re-roll against dev.

focal55’s picture

New patch re-rolled against 7.x-2.x that addresses BarisW's second point.

BarisW’s picture

Thanks all, but the patch in #13 is missing the newly added file from #9.
If someone can combine these changes into one patch, that would be nice.

skylord’s picture

Status: Needs work » Needs review
FileSize
6.82 KB

#9 with fix from #13

skylord’s picture

#13 was buggy as i see now. :-) So, here's fixed patch which one also addresses #12