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.
Hello.
I am trying to setup a default value according to drupal API (http://take.ms/sSbow) in case if the form is empty (before use filled any data) and not successful.
In hook_form_alter() I already added the code via $form['#info']['filter-field_geoaddress_proximity']['label'] = t('Distance');
and it works well. Hovewer if I try like these
$form['#info']['filter-field_geoaddress_proximity']['value']['#default_value'] = 21;
$form['field_geoaddress_proximity']['widget'][0]['value']['#default_value'] = 21;
nothing happens.
This my debug info:
Array
(
[operator] => field_geoaddress_proximity_op
[value] => 2ield_geoaddress_proximity
[label] => Drupal\Core\StringTranslation\TranslatableMarkup Object
(
[string:protected] => Distance
[translatedMarkup:protected] =>
[options:protected] => Array
(
)
[stringTranslation:protected] =>
[arguments:protected] => Array
(
)
)
[description] =>
)
Could somebody help me? Doesn't matter it is in hook_form_alter() or any other hook.
P.S.: I use "Exposed form in block: Yes".
Thank you in advance.
Comments
Comment #2
Ruslan PiskarovComment #3
Ruslan PiskarovComment #4
Ruslan PiskarovComment #5
mikeker CreditAttribution: mikeker as a volunteer commentedUsually default values are set by selecting one (or more) options in the "Configure filter criterion" dialog. See my reply to your Drupal Answers post.
If that fixes the issue, feel free to close this issue. Otherwise I'll leave it open for a month for replies.
Comment #6
Ruslan PiskarovThank you @mikeker.
I will try in coming days.
Actually in my case. it isn't fixed value, a lot of PHP logic. So I am interested how to update values in block (form) programmatically using "Better Exposed Filters".
Comment #7
mikeker CreditAttribution: mikeker as a volunteer commented@Ruslan P, you'll need to implement
hook_views_pre_execute
if you have to use logic to come up with your default values. You can change the default value in the form viahook_form_alter
but that won't change the values in the results until the form is submitted.Comment #8
Ruslan PiskarovHello @mikeker,
thank you for the answer.
Actually, I tried use
hook_views_pre_execute
like the following code and nothing heppens.Also the following code works for me, but only in case with "Exposed form in block: No".
Or in another word:
if I setup Exposed form in block: No", works anything.
if I setup Exposed form in block: Yes", works only view's result, however then fields in the block are empty.
Sccreensnap: http://take.ms/Wuf57.
Comment #9
mikeker CreditAttribution: mikeker as a volunteer commentedInteresting that it works as a regular exposed form, but not as an exposed block...
Have you tried this without BEF? Do you get the same results? If so, I suspect this is a core Views issue and you'll likely get faster (and more knowledgeable!) replies from the core issue queue.
Sorry, I don't have the time at the moment to investigate this any further.
Comment #10
Ruslan PiskarovHello @mikeker,
> Have you tried this without BEF?
No. I will. A good idea. Thank you. Will leave a comment after the investigation.
> I don't have the time at the moment to investigate this any further.
Don't worry about it ))
Comment #11
Ruslan Piskarov@mikeker,
I am confirming. The same result then I use "Exposed form style:Basic". So I will investigate more and find/create drupal core issue.
Thank you very much.
Comment #12
mikeker CreditAttribution: mikeker as a volunteer commented@Ruslan P, please post any core issues you find here as I'd like to track them. Thanks!