dpi / unlimited_number

Provides a widget for number fields for unlimited or limited values.
https://www.drupal.org/project/unlimited_number
GNU General Public License v2.0
0 stars 1 forks source link

Setting #access = FALSE removes the #default_value #8

Open JPustkuchen opened 6 years ago

JPustkuchen commented 6 years ago

When settings #access=FALSE; on an unlimited_number field the default value is not being saved. Instead the value is being reset to null. This isn't the right behaviour but seems to happen because of the compund nature of the widget, like similar issues from other projects here: https://www.drupal.org/project/date/issues/1267434 https://www.drupal.org/project/profile2/issues/1366534

My concrete example: I wanted to hide settings in the rng admin form which the website owners shell never change:

<?php
  $form['event']['rng_registrants_maximum']['widget'][0]['unlimited_number']['#access'] = FALSE;
  $form['event']['rng_registrants_maximum']['widget'][0]['unlimited_number']['#default_value'] = '1';
?>

If #access is not set everything works fine and the default is set and saved. When setting #access=false to hide the field and prevent changing the value, the value is always set to NULL. The correct Drupal FAPI behaviour would be to save the #default_value.

JPustkuchen commented 6 years ago

PS: My current (bad & insecure) workaround is:

<?php
  $form['event']['rng_registrants_maximum']['#attributes']['class'] = array('hidden');
  $form['event']['rng_registrants_minimum']['#attributes']['class'] = array('hidden');
?>