2

I am facing a real problem and i can't manage to solve it.

I have some checkboxes in user profile based on a vocabulary. I want to display all articles that have this tags in a view . If user wants to see all articles he should choose on a select list what he want to display. So i want to make a default for that page and if user wants something else to display based on a select option.

Ex: user X has checked in profile page options : management. then he goes in news view and see all articles with tag management. If he change his mind and want to see other categories this should be done from a select.

I have done the first part that with default articles (i make a contextual field with default get ID from logged in user ->relationship from user and display content that have that terms-> this is a user entity view that displays related articles) when i put the exposed filter and select another value i get nothing. I think that view searches for that value in user checkboxes preferences in user profile.

What can i do to achive my goal? Thank you

4
  • I have similar problem, but I am solving it via code only, without contextual filters
    – Codium
    Nov 23 '13 at 22:25
  • can you share it with me please? i worked at this for days...
    – Val Valli
    Nov 23 '13 at 22:27
  • Give me an hour, working on it. Basically I need to store in user entity some values from exposed filters and use these values in filters, every time, when user view page with exposed filters block again.
    – Codium
    Nov 23 '13 at 22:35
  • i dont't know if you understand. to make sure i write again. I want to get the preferences from user profile and this should be the default values for displain the views. And if the user want to see more or another category just to select from an exposed form filter. thanks for help. i really appreciate.
    – Val Valli
    Nov 23 '13 at 22:57
1

Probably I misunderstood your problem, but I put my solution anyway.

OK I have a view with entities of content type Foo and exposed filters as block, which appears on all pages. I am storing filter values in user entity (same fields as in Foo - taxonomy term reference fields).

When URL has not exposed filters parameters (exposed filters form hasn't submitted) I try to set filters default values from user entity fields:

    /**
     * Implements hook_form_FORM_ID_alter
     */
    function mymod_form_views_exposed_form_alter(&$form, &$form_state, $form_id) {
     if (! _mymod_isFormSubmit()) {
     //exposed filters form hasn't submitted so I am using values from user entity
     global $user;
     $wrapper = entity_metadata_wrapper('user', $user);
     foreach(_mymod_getFiltersMapping() as $filterName => $fieldName ) {
      $tids = array();
      foreach($wrapper->{$fieldName}->value() as $term) {
        $tids[] = $term->tid;
     }
     $form_state['input'][$filterName] = empty($tids) ? 'All' : reset($tids);
    }
  }
}

It isn't working for me yet, I am getting always random values, maybe because usage of Better Exposed Filters form.

8
  • Ok I managed to solve it (answer updated), thanks to drupal.org/node/635242 Maybe it can help you in some way.
    – Codium
    Nov 23 '13 at 23:58
  • from your description that is what i want to do. i have a question. I have many checkbox fields with many options in user profile. i want for a certain view a certain field of values. It's this working for this case?
    – Val Valli
    Nov 24 '13 at 0:12
  • @ValValli if I understood you well, you need certain exposed filters form id, which is stored in $form['#id']. You just need mapping: filter form field name to user entity field name, which in my case do _mymod_getFiltersMapping()
    – Codium
    Nov 24 '13 at 12:27
  • @ValValli let mi know if it works for you.
    – Codium
    Nov 24 '13 at 13:19
  • may be a noob question but i have to write this in a module? no changes needed? other than hook module name?
    – Val Valli
    Nov 24 '13 at 16:41

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.