Score:0

How can I use $argument, in default value PHP, for a contextual filter?

sa flag

I'm using a entity reference field on some content types. The field references taxonomy terms. Then I'm using a view to filter the available options. I'm passing the content type to that view using this token - [node:content-type:machine-name].

Essentially the field is used on different content types but the value is the same on each content type.

So the field is called product type. Content type "tin_labels" would have the value set to "Tin labels". A content type "Bags" would have the value set to bags for example.

For the contextual filter, I added the field "Taxonomy term: Name". I've added this PHP for providing the default argument in PHP code:

$content_type = $argument;
if ($content_type = 'tin_labels') {
  $term = 'Tin Labels';
  return $term;
}

elseif ($content_type = '3_5g_mylar_bag_design' || $content_type = '7g_mylar_bag_design') {
  $term = 'Mylar Bag Labels';
  return $term;
}

else {
  return;
}

I'm using no validation and currently get all values.

I'm pretty sure I'm not using the correct variable when setting $content_type. I tried to dpm($argument) but got nothing. Can't find any documentation that explains the structure of that value.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.