Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
RdeBoerFrom 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.
Comment #2
RdeBoerIf #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.
Comment #3
RdeBoerIf #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.
Comment #4
RdeBoerOne 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.
Comment #5
RdeBoerMulti-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.
Comment #6
Jarviss CreditAttribution: Jarviss commentedMay 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!
Comment #7
RdeBoerHi 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
or
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.
Comment #8
Jarviss CreditAttribution: Jarviss commentedThank you! I updated to 7.x-1.2 it is in block settings!
Comment #9
edou00 CreditAttribution: edou00 commentedScuse 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
Comment #10
edou00 CreditAttribution: edou00 commentedOk 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.
Comment #11
RdeBoerCool !
Comment #12
RdeBoerComment #13
edou00 CreditAttribution: edou00 commentedSorry 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 ...
Comment #14
RdeBoerHi 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
Comment #15
edou00 CreditAttribution: edou00 commentedWe 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
Comment #16
RdeBoerAll 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....
Comment #17
edou00 CreditAttribution: edou00 commentedI will seek on this way.
Thx u :)
Comment #18
HendrikM CreditAttribution: HendrikM commentedMy 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!
Comment #19
HendrikM CreditAttribution: HendrikM commented[Sorry, I sent the last comment twice]