Endpoint form incorrectly saves empty page options as a string

Created on 17 February 2024, 9 months ago
Updated 2 March 2024, 9 months ago

Wring some tests for search_web_components and came across a schema validation error when trying to create a new endpoint. Because the testing process has config validation enabled it is refusing to save a new endpoint because 'items_per_page_options' is a string but an array is expected. This makes sense since that field is converted from a string to an array in the submit but the submit lacks handling to convert an empty string to an empty array.

    // Save the items per page options as array.
    $items_per_page_options = $form_state->getValue('items_per_page_options');
    if (!empty($items_per_page_options)) {
      $items_per_page_options = explode(',', $items_per_page_options);
      $items_per_page_options = array_map('trim', $items_per_page_options);
      $items_per_page_options = array_map('intval', $items_per_page_options);
      $form_state->setValue('items_per_page_options', $items_per_page_options);
    }

Simple fix is to add an else and set an empty array.

    else {
      $form_state->setValue('items_per_page_options', []);
    }
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ctrladel North Carolina, USA

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024