Drupal 9 image field migration

The issue related to the custom website with custom field for phone. It has spaces. One of the solution is to remove spaces on presave and process the old entries in DB removing the spaces.
But sometimes it better not to touch thing that works.
The task was to provide search by phone filter in views. There are no default methods in views to search with removed spaces. In this case I've found a solution to alter the query.
So for example the phone fields value is "+354 566 32 56" and we need to find it by searching "6632" string.
This code will help you with it:

/**
 * Implements hook_views_query_alter().
 *
 * @param ViewExecutable $view
 * @param Sql $query
 */
function custommodule_views_query_alter(ViewExecutable $view, Sql $query) {
  if ($view->id() == 'commerce_orders' && $view->current_display == 'orders') {
    // Traverse through the 'where' part of the query.
    foreach ($query->where as &$condition_group) {
      foreach ($condition_group['conditions'] as &$condition) {
        // Replace whitespaces from phone field.
        if ($condition['operator'] == 'formula' && !empty(strpos($condition['field'], 'field_phone_number'))) {
          $condition['field'] = preg_replace(['/CONCAT_WS/','/[)]/'], ['REPLACE(CONCAT_WS', "), ' ', '')"], $condition['field'] );
        }
      }
    }
  }
}

Коментувати

Вміст цього поля є приватним і не буде доступний широкому загалу.
  • Не дозволено жодних HTML теґів.
 oooooo   oooooo     oooo               ooooooooooooo                ooooooooo             
`888. `888. .8' 8' 888 `8 d"""""""8'
`888. .8888. .8' oooo ooo 888 oooo ooo .8' .oooooooo
`888 .8'`888. .8' `88. .8' 888 `88. .8' .8' 888' `88b
`888.8' `888.8' `88..8' 888 `88..8' .8' 888 888
`888' `888' `888' 888 `888' .8' `88bod8P'
`8' `8' `8' o888o `8' .8' `8oooooo.
d" YD
"Y88888P'
Уведіть код, зображений у стилі Ascii-Арт.