Problem/Motivation

Since https://www.drupal.org/project/auto_entitylabel/issues/3076302 (from version 3.3, 3.2 does not have this issue)

      $placeholder = strtr('%AutoEntityLabel: @entityId%', ['@entityId' => $entity->uuid()]);

has been introduced.

https://git.drupalcode.org/project/auto_entitylabel/-/commit/131ce06e628...

If you have a custom entity with a label limited to fewer than 55 characters, saving such an entity may result in a WSOD. This issue occurs because the label field (e.g., "name") in the {your_entity}_field_data and {your_entity}_field_reference tables is defined with a length shorter than 55 characters. Consequently, placeholder values like %AutoEntityLabel: 9935f91e-aca2-44b4-9f03-c205449efcaf% (which is 55 characters long) cannot be temporarily saved, leading to the error.

Example of custom entity label field with less than 55 characters:


    $fields['name'] = BaseFieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setSettings([
        'max_length' => 50,
        'text_processing' => 0,
      ])
      ->setDefaultValue('')
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'string',
        'weight' => -4,
      ])
      ->setDisplayOptions('form', [
        'type' => 'string_textfield',
        'weight' => -4,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE)
      ->setRequired(TRUE);

If you update the lenght of name field table like below, everything start working just fine, but maybe it would be nice to show some error in interface or in the reports, that given entity is not eligable for auto entity label.

Example of custom entity label field lenght changed to 55 characters:

function {your_module}_update_10001() {
  $schema = \Drupal::service('database')->schema();

  // Define the tables and field.
  $tables = [
    '{your_entity}_field_data',
    '{your_entity}_field_revision',
  ];
  $field = 'name';

  foreach ($tables as $table) {
    // Check if the table and field exist.
    if ($schema->fieldExists($table, $field)) {
      $schema->changeField($table, $field, $field, [
        'type' => 'varchar',
        'length' => 55, // New length.
        'not null' => FALSE,
      ]);
      \Drupal::logger('your_module')->info("Field length updated successfully in $table.");
    }
  }
}

Steps to reproduce

Proposed resolution

N/A

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Comments

zanvidmar created an issue. See original summary.

zanvidmar’s picture

Issue summary: View changes
zanvidmar’s picture

Issue summary: View changes
zanvidmar’s picture

Issue summary: View changes
zanvidmar’s picture

Title: Entity label must be at leat 55 long to support placeholder » Entity label must be at least 55 long to support placeholder