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.
I created this D8-focused issue to avoid confusion between D7 and D8 patches for the issue described in #1934972: Allow open range (from without to or to without from).
Comment | File | Size | Author |
---|---|---|---|
#18 | range-allow-open-range-2885516-18-D8.patch | 5.99 KB | msielski |
#14 | range-allow-open-range-2885516-14-D8.patch | 5.23 KB | Aron Novak |
#5 | range-allow-open-range-2885516-5-D8.patch | 10.58 KB | jdleonard |
#2 | 2885516-range-disable-both-values-required.patch | 2.49 KB | jdleonard |
Comments
Comment #2
jdleonardI don't have time to provide a RTBC patch right now, but I attach a sledgehammer approach for all Range fields that disables the constraint validator that ensures that both the "from" and "to" value exist. This patch doesn't do anything else (e.g. adjust formatting logic). Obviously, this patch is not suitable to be committed as-is, but perhaps it will help someone else, who, like me, just needs to let folks optionally omit either the "from" or "to" sub-field.
Comment #3
jdleonardI thought #2 was a good quick fix, but my flawed testing using an Inline Entity Form (I hit the "Update [entity-label]" button, but not the "Save" button) obscured the fact that the field definition requires that both "from" and "to" exist, resulting in empty "from"/"to" turning into zeros. A bunch of other changes are necessary to make this work, including a hook_update_N() implementation to update existing database tables.
Comment #4
Taran2LAnd updates to views, new tests, new configuration options... this feature is not that easy
Comment #5
jdleonardHere's a more complete patch, which I have tested lightly. The following still needs to be done:
For now, this can be used with existing fields by manually editing the relevant field/revision database tables to allow null values for the from/to columns.
Setting to "needs review" for feedback. Thanks!
Comment #6
droprocker CreditAttribution: droprocker commentedI get an error if I try to patch with composer:
Using Drupal 8.5.0 and Range Module 1.x-dev.
Comment #7
jdleonard@der_wilko: It looks like you're applying the wrong patch. Try https://www.drupal.org/files/issues/range-allow-open-range-2885516-5-D8....
Comment #8
droprocker CreditAttribution: droprocker commented@jdleonard: Thanks. The patch is now successfully applied. But I'm not quite sure what to do with this information
Could you explain, what to do!? Because right now I still get the error "Both range values (FROM and TO) are required." For new an existing fields.
Thanks in advance...
Comment #9
jdleonard@der_wilko You'll need to use a database management tool (e.g. phpMyAdmin or Sequel Pro) to edit the structure of the field data and field revision tables for the relevant range field. Specifically, you'll need to change the structure of these tables' "from" and "to" columns to allow NULL values.
Comment #10
markdcI need this feature, but I get the error "This value should be of the correct primitive type." Steps to reproduce:
Comment #11
asak CreditAttribution: asak commentedThis patch applies and works, but it's not enough to allow open range values to be saved. The constraints that come with the module need to be overridden to complete the functionality. I duplicated the RangeBothValuesRequiredConstraint and RangeFromGreaterToConstraint classes and implemented hook_validation_constraint_alter() to complete the functionality.
Comment #12
droprocker CreditAttribution: droprocker commentedPatch doesn't apply anymore on 8.x-1.2. But issue seems to be solved. Can anyone confirm? This issue is not mentioned in the Changelog of 1.2.
Comment #13
Taran2Lhi @der_wilko, this issue has not been solved as of yet, as it requires significant work in order to make it right, including Views integration, new formatter settings, tests updates, etc
Patch provided in #2 just removes the validation, and does not touch any other part of the module. Patch from #5 does a better job, but still there are much more to do.
This feature is changing the core behavior of the module and having ~1500 active installs that may break does not allow me to commit it as is.
If someone needs this, then please vote for it, contribute and I will pick it up.
Comment #14
Aron NovakI re-rolled the patch in #5, so it can be applied to the latest dev, it has the same limitations that are explained in https://www.drupal.org/project/range/issues/2885516#comment-12145660
Comment #15
Aron NovakFor the record, you need to execute 4 SQL commands to change one field to work with the patch (only for existing fields), for example:
Comment #16
droprocker CreditAttribution: droprocker commentedPatch in #14 applies to 1.3. But the patch renders NULL values as zero instead of just not showing them at all. It's a big difference if I say the range is "up to 2" or "0 to 2".
The patch in #5 included this behaviour perfectly.
Comment #17
a.milkovskyI propose next solution:
Comment #18
msielskiI updated patch #14 to address the "value should be of correct primitive type" error we were receiving. I used a solution similar to https://www.drupal.org/project/drupal/issues/2220381#comment-12771574, adding a massageFormValues to the widget to unset empty values. You'll still manually need to update existing DB fields to remove their NOT NULL constraints.