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 image media type, under 'Crop configuration', choose the image field.
  • 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

CommentFileSizeAuthor
#2 3201612-2.patch572 byteserik.erskine

Issue fork crop-3201612

Command icon 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:

  • 8.x-2.x Comparecompare
  • 3201612-crop-entities-not Comparecompare

Comments

erik.erskine created an issue. See original summary.

erik.erskine’s picture

StatusFileSize
new572 bytes

Here'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.

erik.erskine’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 3201612-2.patch, failed testing. View results

nathan tsai’s picture

Note: this issue can be worked around using the filename_transliteration module.