Simplify ListItemBase::validateAllowedValues()

Created on 23 November 2023, 7 months ago
Updated 30 December 2023, 6 months ago

Problem/Motivation

It's takes a lot of time for me to understand this part of the code.
Can we decrease complexity for better code readability?

  public static function validateAllowedValues($element, FormStateInterface $form_state) {
    $items = array_filter(array_map(function ($item) use ($element) {
      $current_element = $element['table'][$item];
      if ($current_element['item']['key']['#value'] !== NULL && $current_element['item']['label']['#value']) {
        return $current_element['item']['key']['#value'] . '|' . $current_element['item']['label']['#value'];
      }
      elseif ($current_element['item']['key']['#value']) {
        return $current_element['item']['key']['#value'];
      }
      elseif ($current_element['item']['label']['#value']) {
        return $current_element['item']['label']['#value'];
      }

      return NULL;
    }, Element::children($element['table'])), function ($item) {
      return $item;
    });

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

  • Discus code complexity.

API changes

Data model changes

Release notes snippet

โœจ Feature request
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Optionsย  โ†’

Last updated about 1 month ago

No maintainer
Created by

๐Ÿ‡ท๐Ÿ‡บRussia zniki.ru

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024