Any way to make one value the default, instead of the ANY selection?
I have a "Ship-to" selector and want to select USA as the default.

Ed.: first requested in #1396686: Undefined Session variable

Comments

RdeBoer’s picture

From the project page:

"The initial selection for each global filter will be 'all', unless the underlying field also appears on the user profile, in which case the value selected there will be taken as the default"

Naturally this isn't going to help anonymous visitors as they won't have a profile.... Also if the global filter is driven by a View, rather than a field, no default other than 'All' can be set.

RdeBoer’s picture

Title: Allow default value to be set for global filters » Allow default value(s) to be set for global filters

If #1412462: Allow Global Filter drop-down to be a multi-select box is going to be implemented, then we should allow multi-select for the default as well.

RdeBoer’s picture

If #1412462: Allow Global Filter drop-down to be a multi-select box is going to be implemented, then we should allow multi-select for the default as well.

RdeBoer’s picture

One way the default could be set is via a PHP snippet.
This would allow a Global Filter of countries to be populated with the country that the visitor is browsing from (using http://drupal.org/project/ip_geoloc for instance).
Or it could set a Global Filter of currencies to the currency belonging to the location (country) the user is browsing from.
Or in an online clothes store it could filter the collection shown by the weather at the visitor's location --- haha, just joking.

RdeBoer’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Assigned: Unassigned » RdeBoer
Status: Active » Fixed

Multi-choice default can now be specified on global filter block configuration page.
Default through PHP code also available.
Checked into Git and available now in 7.x-1.x-dev.
Will be available in 7.x-1.2.

Jarviss’s picture

May you post PHP snippet code to set default value argument as a default.
Don't know how to make it and where to put it!

RdeBoer’s picture

Hi carliton, #6:

First I suggest you use the latest 7.x-1.x-dev, as it has a debug/info facility that you can switch on at the Config >> Global Filter page. This prints out a message (to the admin, uid=1) every time a Global filter value is changed.

To change the default for a View or a field that isn't a textfield you can simply select one or more values from the box: Default value for the field or view selected above on the block configuration page.
If there are not values shown in that box, then your filter is probably a textfield and in this case you need to use the field below it, Alternatively specify a default through PHP code.
Enter something like

  <?php return 'Australia'; ?>

or

  <?php return 100; ?>

Naturally, the value you return must be valid for the type of field. What kind of field are you using?

Finally keep in mind that the Global Filter value is set upon LOGOUT as admin, i.e. the start of the anonymous user session (refresh the screen to see what defaults are set). The Global defaults continue to be active when you next login (as admin or any other user), except where the global filter is a FIELD that also appears on the user profile, in which case that value is taken as the default.

Jarviss’s picture

Thank you! I updated to 7.x-1.2 it is in block settings!

edou00’s picture

Scuse me but I have a little question about this issue.

If I want to put a default content when no global filter is selected, how can I do that ?

In fact I don't want the default value to be one of my global filter term, I just want to put a default content when no value is selected...

Sorry for my english... fucking french people haha :p

edou00’s picture

Ok I found an answer myself.

By the way, I set a default value named " Other ", deleted the '-all-' option and enabled the content to be selected with two globals filters values.

RdeBoer’s picture

Cool !

RdeBoer’s picture

Status: Fixed » Closed (fixed)
edou00’s picture

Sorry but I still have a problem with default value.
When i'm login out, the message is " data session cleared " and the value I had selected by default is not kept, so it turn the global filter to -all- that I don't want...

And I don't know why but the message printed out normally only for admin is printed for logout users.
I think my global filter is completly bugger, I tried to uninstall it and reconfigure it but nothing changed.

Thks u ...

RdeBoer’s picture

Status: Closed (fixed) » Closed (works as designed)

Hi edou00,

I don't think your Global Filter is buggered.

That message happens upon logout only and then there is one more message upon the next click to show the default settings for the anonymous user -- but any messages appear only when the debug messages are switched on, of course.

Anyway, the default for authenticated users is set when they log IN, according to their user profile.
When they log out, then they become anonymous users and then get the global default (as set by the administrator). The default they had when they were logged in is NOT meant to carry over to the anonymous user -- I do not intend to implement that for now.

Does that clear things up?

Rik

edou00’s picture

We are totally OK and I understood everything.

But my problem is that the global default value for anonymous users doesn't work and I don't know why. It continue to tell me " data session cleared " on every pages and the default value is not set automaticly...

Best regards

RdeBoer’s picture

All global filter information is kept in the user's session and if something on your system clears that all the time then Global Filter won't work. It's normal for the session to be cleared ONCE, upon logout, but at the next click a new session should automatically be created, namely for the now anoymous user.This does not seem to happen on your system, or it does but gets erased by something.
In short: don't know....

edou00’s picture

I will seek on this way.
Thx u :)

HendrikM’s picture

My problem is that I use the proximity widget (with Geofield), and that there need to be two values: one for the distance, one for the place. Trying to specify a default value for users that just entered the site, I would like to set defaults like "20km" from "Berlin".
How can this be done with PHP? If I return a string nothing happens, if I return an array nothing happens...

Thanks in advance!

HendrikM’s picture

[Sorry, I sent the last comment twice]