6
6
6yp9T2014-11-24 15:28:26
Drupal
6yp9T, 2014-11-24 15:28:26

How to change filter element text in drupal 7 views exposed filter?

There are Views, the elements of the dictionary are displayed, the exposed filter is made in the form of a select, it is filtered by another dictionary:
1 - The name field from the term is displayed in the text of the filter element, how can I make it display another field, for example, description?
2 - How to make sure that the list of filter elements includes terms whose selection does not give an empty result?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
box1024, 2014-12-04
@6yp9T

Exposed filters is the usual form. That is, you can use hook_form_alter in your module to get and change the value of any form element.
Here is an example of a taxonomy field in an exposed form structure:
At a glance - in your case it should work like this:
Iterate through all the #option elements in the desired form field. For each of them:

  1. We check for the presence of elements marked with the term - for example, through taxonomy_select_nodes($tid). $tid is the key in the array.
  2. If there are more than zero such nodes, we get the term object via taxonomy_term_load($tid)
  3. We replace option with the value we need (for example, description)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question