Port Drupal 7 maximum length field validation

Created on 28 July 2019, almost 6 years ago
Updated 30 April 2025, 1 day ago

        // @todo: Port this feature to Drupal 8.
        $extra_max_info = '<div>' . t('This can not be less than the longest value in the database. The minimum values are:') . '</div>';
        $extra_max_items = [];
        foreach (_name_translations() as $key => $title) {
          $extra_max_items[] = t('@title is @size', [
            '@title' => $title,
            '@size' => $form['max_length'][$key]['#min'],
          ]);
        }
        $item_list = [
          '#theme' => 'item_list',
          '#items' => $extra_max_items,
        ];
        $extra_max_info .= drupal_render($item_list);
      if ($has_data) {
      $min_length = $settings['max_length'][$key];
        if ($field['storage']['type'] == 'field_sql_storage') {
          try {
            $table = 'field_data_' . $field['field_name'];
            $column = $field['storage']['details']['sql'][FIELD_LOAD_CURRENT]
            [$table][$key];
            $min_length = db_query("SELECT MAX(CHAR_LENGTH({$column})) AS len FROM {$table}")->fetchField();
            if ($min_length < 1) {
              $min_length = 1;
            }
          }
          catch (Exception $e) {
          }
        }
    }
πŸ“Œ Task
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia alan d.

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.

  • πŸ‡ΊπŸ‡ΈUnited States bluegeek9

    I am not sure this needs to be ported to 8.x-1.x.

    Is this correct, 'not ... less than the longest value' ?

    This can not be less than the longest value in the database.

Production build 0.71.5 2024