3

I am trying to pass an contextual filter to a views content pane from a field in my node and have followed the procedure described in this question without success. I see that the OP of that question eventually resorted to a PHP contextual filter as well.

The only difference is that I am using Panelizer rather than Panels. My field is called field_organization_contact_recor. My view works if I test it with legal values for that field in the views UI and gives the correct results in the preview.

I have chosen "from context" and checked that I am passing the correct field in the "Argument input" settings for the views pane. I checked by using firebug to check the field name of the selected option was correct. I get "no results" for my view.

I have also tried setting it up as "Input on pane config". If I do that and pass in a hard-coded value in the pane settings I also get the correct view results in my panels page. On that settings popup there is a prompt "You may use keywords for substitutions." What is the required format of these keywords to pass a field value? I have tried the format shown on the list of built-in contexts on the contexts tab "%node:field_organization_contact_recor". This format doesn't work in my case.

Additional info: This field is CiviCRM contact reference field. Perhaps there is a particular hook that this field type doesn't implement?

  • These "keywords for substitution" are CTools context keywords, processed by ctools_context_keyword_substitute( ). There is a big list of them after creating a Panel variant: in the panel's content section, unfold "Substitutions". – tanius Mar 15 '16 at 21:24
10

I found a straightforward solution for this in a comment in the issue queues:

Basically there is a Display Mode on each content type for Tokens that can be used to control exactly what is rendered by tokens that are used.

To enable it per content type, do the following:

  • In the actual Content Type itself, got to the "Manage Display" tab.
  • Scroll down to the end of the field listing and click the "Custom Display Settings" link.
  • Enable (Check) and Save the Token option to enable the Token Display mode.
  • Go to that display mode (Grey display mode tabs near the top) and any field settings you do here effect what the tokens render (which is the same ones Panels uses).
  • Thanks. Your answer is partially the same as mine. Your steps provide a better explanation of step 1 in my solution. I also needed a custom field formatter to get the raw value of my field available in the token display mode. – lolcode Jan 17 '14 at 22:05
1

I have found that the format shown on the contexts tab (in Panelizer) which displays as "%node:field_organization_contact_recor" is indeed correct. The reason that it didn't work in my case is that the default value that gets passed by this token is the fully formatted value passed through the field's default formatter. My view needed the un-themed/un-formatted raw value of the field. For now I have implemented a workaround using this method of:

  1. Setting up a custom Token display mode
  2. Writing a field formatter that outputs the raw value and using it in this display mode.

This is a good solution until we DO want to use the fully themed/formatted value as a token somewhere else on the site. I could not find a better solution despite all the interesting reading in these two relevant threads: Field Tokens and Entity tokens duplicates field tokens created by token module

  • For fields with simple contents (for example EntityReference, containing integers), writing a custom field formatter is not necessary to get the raw value. Just select "Format: Entity id" for the field in the Token display mode page and it will work. – tanius Mar 15 '16 at 18:02
  • Also, some "keywords for substitution" do not require setting up the Token display mode at all: %node:nid for the node ID works without it. – tanius Mar 15 '16 at 18:05
0

For the "Input on pane config" field, here is a solution without the Token display mode. In your case, set the parameter to:

%node:field-organization-contact-recor:cid

Explanation: CTools context keywords can be chained like Drupal [tokens]. At least the versions with dashes for underscores, but apparently not the versions with underscores. In your case %node:field-organization-contact-recor refers to a CiviCRM Contact Record, which apparently has its raw ID stored in a cid field. So we use that for chaining.

I could chain entity reference fields referring to nodes with %node:field-name:nid successfully and assume the above will be the equivalent for your case, but I did not test it in CiviCRM.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.