- Issue created by @simohell
- ๐บ๐ธUnited States dan612 Portland, Maine
I believe this issue can be recreated with any Text (plain) input field, regardless of profile/installation method. After some digging around, I think the problem lies in the validation surrounding the StringItem field type.
We have a subform being created for max_length but there is no restriction on the highest allowed value for that input. Could we simply provide a #max on the subform element? For instance:
/** * {@inheritdoc} */ public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) { $element = []; $element['max_length'] = [ '#type' => 'number', '#title' => $this->t('Maximum length'), '#default_value' => $this->getSetting('max_length'), '#required' => TRUE, '#description' => $this->t('The maximum length of the field in characters.'), '#min' => 1, '#max' => 255, // adding this line '#disabled' => $has_data, ]; return $element; }
This leads me to another question...what is the correct max to set here? My inclination is to set a cap of 255, however, I don't think such a restriction exists for the varchar data type. Looking at the MySQL reference manual:
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. See Section 10.4.7, โLimits on Table Column Count and Row Sizeโ.
Now, this changes based on the character set in use. In the example screenshots we can see:
Column length too big for 'field_test_value' (max=16383)
The 16,383 comes from the fact that the database is using utfmb4 character encoding which requires 4 bytes per character (65,535 / 4 = 16,383.75 - can't support three-quarters of a character so drop the .75).
If I set this locally to 16,383 I am still met with the error. The highest value I can input for a max appears to be 16,339. If I set it to more than that I get an error. Why this value? Not sure...seems too arbitrary.
Additionally, it looks like the storage can specify if ASCII or not - if these characters were limited to ASCII then the max would be much greater as each character only requires 1 byte instead of 4. So if I change this to TRUE, I can then enter a value up to 65,358.
Right now the questions I have outnumber the solutions ๐
- Where is the Ajax validation coming from on the subform input?
- Why is the Ajax validation bypassed on second save?
- What is an appropriate max value to set?
This should also be something that is testable in the StringItemTest...once we know what to set it at ๐.