Use maxlength defined in label's entity field definition

Created on 6 December 2022, over 1 year ago
Updated 25 March 2023, over 1 year ago

Problem/Motivation

The label fields defined in ReplicateConfigForm use textfield's default maxlength value which is 128.
This cause some issues because for example node label's maxlength is 255. If we replicate entity with long label, we're limited to 128 characters.

Steps to reproduce

Replicate an entity with a label greater than 128 characters.
Try to confirm replication, an html error will appear and prevent submission.

Proposed resolution

Instead of using default textfield's maxlength, use maxlength defined in label's field definition of replicated entity.

Remaining tasks

Test proposed patch.

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland
    +++ b/src/Form/ReplicateConfirmForm.php
    @@ -39,6 +46,13 @@ public function buildForm(array $form, FormStateInterface $form_state, RouteMatc
     
    +    $entityLabelKey = $entity->getEntityType()->getKey('label');
    +    $entityFieldsDefinitions = $this->entityFieldManager->getBaseFieldDefinitions($entity->getEntityType()->id());
    +    $labelMaxLength = 128;
    +    if ($entityFieldsDefinitions[$entityLabelKey] instanceof BaseFieldDefinition) {
    +      $labelMaxLength = $entityFieldsDefinitions[$entityLabelKey]->getSetting('max_length');
    +    }
    

    You have the entity, you can get the field definition from it. This can be simplified to $entity->getFieldDefinition($label_key). no entity field manager necessary.

    The code also needs to be moved inside the existing hasKey() check, some entity types don't have a label key.

  • πŸ‡¨πŸ‡­Switzerland Berdir Switzerland

    Forgot that #3106142: Allow long texts as new labels β†’ changed the default to 255, needs to be rerolled. Could indeed cause a problem if a label is entered that's too long.

Production build 0.69.0 2024