Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate and remove NullableField #317

Open
emteknetnz opened this issue Sep 30, 2024 · 0 comments
Open

Deprecate and remove NullableField #317

emteknetnz opened this issue Sep 30, 2024 · 0 comments

Comments

@emteknetnz
Copy link
Member

emteknetnz commented Sep 30, 2024

NullableField is a fairly obscure field that doesn't appear to work

By default, DBString will set an option $this->options['nullifyEmpty'] = true; which means convert empty strings to null before saving in the database

If 'nullifyEmpty' is set to false, what is supposed to happen is the DBVarchar/DBText field is wrapped by NullableField which adds a checkbox to the field. This is supposed to show to the CMS user if the field is null or not, and if they uncheck the field then it's supposed to save the value as a blank string rather than as null

There are many things wrong with this field:

  • Unchecking the field makes no difference, blank values are still saved as null
  • The CSS for the field is broken and it's misaligned
  • How a value is stored in database should not be a concern for content editors

We should simply remove this class

Note that we should keep the 'nullifyEmpty' option as that looks like it still works and allows users to programmatically set blank string as a database value

I used the following to test it

namespace SilverStripe\ORM\FieldType;

class DBNullableVarchar extends DBVarchar
{
    public function __construct(?string $name = null, int $size = 255, array $options = [])
    {
        $options['nullifyEmpty'] = false;
        parent::__construct($name, $size, $options);
    }
}
use SilverStripe\CMS\Model\SiteTree;

class Page extends SiteTree
{
    private static $db = [
        'NullableSomething' => 'NullableVarchar',
    ];
    // ...
}
SilverStripe\Core\Injector\Injector:
  NullableVarchar:
    class: DBNullableVarchar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant