Problem/Motivation
When two images are uploaded whose name differs only by upper/lower case, the second crop entity is not saved.
Steps to reproduce
- Install with standard profile.
- Enable media, crop and focal_point modules.
- Edit the
imagemedia type, under 'Crop configuration', choose theimagefield. - Add a media item of type 'image', with a filename, eg
sea.png. - Repeat step 4 but with a filename that differs only by case, eg
Sea.png
The outcome on MySQL is there is only one row in the crop & crop_field_data tables. No second crop entity is saved.
Using PostgreSQL, this error occurs upon save:
Error: Call to a member function isNew() on null in focal_point_entity_update() (line 79 of modules/contrib/focal_point/focal_point.module).
Proposed resolution
The Crop entity has a uri base field defined:
$fields['uri'] = BaseFieldDefinition::create('uri')
->setLabel(t('URI'))
->setDescription(t('The URI of the image crop belongs to.'))
->setRevisionable(TRUE)
->setTranslatable(TRUE)
->setSetting('max_length', 255);
Adding setSetting('case_sensitive', TRUE) makes this match the corresponding uri property on the file entity. The error doesn't occur and both crops are saved.
Remaining tasks
- Write patch.
- Tests.
- Upgrade hook.
User interface changes
None.
API changes
None.
Data model changes
The uri column definition changes from:
varchar(255) DEFAULT NULL
to
varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3201612-2.patch | 572 bytes | erik.erskine |
Issue fork crop-3201612
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
erik.erskine commentedHere's a patch that adds
setSetting('case_sensitive', TRUE)to the property definition.Please note this is only suitable for applying before installing the module. There's no upgrade hook in here. Hence the test fail.
Comment #3
erik.erskine commentedComment #5
nathan tsai commentedNote: this issue can be worked around using the filename_transliteration module.