src/Utility/Search.php
protected function normalize(SavedSearch $entity, array $saved, array $latest) : SavedSearch
    {
        // Backward compatibility: search content must always contain 'saved' and 'latest' keys.
        $saved = isset($saved['saved']) ? $saved['saved'] : $saved;
        $latest = isset($latest['latest']) ?
            $latest['latest'] :
            (isset($latest['saved']) ? $latest['saved'] : $latest);

        // Backward compatibility: always prefix search criteria, display columns and sort by fields with table name.
        $filterFunc = function ($data) {
            if (array_key_exists('criteria', $data)) {
                foreach ($data['criteria'] as $field => $option) {
                    unset($data['criteria'][$field]);
                    $data['criteria'][$this->table->aliasField($field)] = $option;
                }
            }

            if (array_key_exists('display_columns', $data)) {
                $data['display_columns'] = array_values($data['display_columns']);
                foreach ($data['display_columns'] as &$field) {
                    $field = $this->table->aliasField($field);
                }
            }

            if (array_key_exists('sort_by_field', $data)) {
                $data['sort_by_field'] = $this->table->aliasField($data['sort_by_field']);
            }

            return $data;
        };

        $saved = $filterFunc($saved);
        $latest = $filterFunc($latest);

        $entity->set('user_id', $this->user['id']);
        $entity->set('model', $this->table->getRegistryAlias());
        $entity->set('content', ['saved' => $saved, 'latest' => $latest]);

        return $entity;
    }
protected function normalize(SavedSearch $entity, array $saved, array $latest) : SavedSearch
    {
        // Backward compatibility: search content must always contain 'saved' and 'latest' keys.
        $saved = isset($saved['saved']) ? $saved['saved'] : $saved;
        $latest = isset($latest['latest']) ?
            $latest['latest'] :
            (isset($latest['saved']) ? $latest['saved'] : $latest);

        // Backward compatibility: always prefix search criteria, display columns and sort by fields with table name.
        $filterFunc = function ($data) {
            if (array_key_exists('criteria', $data)) {
                foreach ($data['criteria'] as $field => $option) {
                    unset($data['criteria'][$field]);
                    $data['criteria'][$this->table->aliasField($field)] = $option;
                }
            }

            if (array_key_exists('display_columns', $data)) {
                $data['display_columns'] = array_values($data['display_columns']);
                foreach ($data['display_columns'] as &$field) {
                    $field = $this->table->aliasField($field);
                }
            }

            if (array_key_exists('sort_by_field', $data)) {
                $data['sort_by_field'] = $this->table->aliasField($data['sort_by_field']);
            }

            return $data;
        };

        $saved = $filterFunc($saved);
        $latest = $filterFunc($latest);

        $entity->set('user_id', $this->user['id']);
        $entity->set('model', $this->table->getRegistryAlias());
        $entity->set('content', ['saved' => $saved, 'latest' => $latest]);

        return $entity;
    }
protected function normalize ( SavedSearch $ entity , array $ saved , array $ latest ) : SavedSearch { // Backward compatibility: search content must always contain 'saved' and 'latest' keys. $ saved = isset ( $ saved [ 'saved' ] ) ? $ saved [ 'saved' ] : $ saved ; $ latest = isset ( $ latest [ 'latest' ] ) ? $ latest [ 'latest' ] : ( isset ( $ latest [ 'saved' ] ) ? $ latest [ 'saved' ] : $ latest ) ; // Backward compatibility: always prefix search criteria, display columns and sort by fields with table name. $ filterFunc = function ( $ data ) { if ( array_key_exists ( 'criteria' , $ data ) ) { foreach ( $ data [ 'criteria' ] as $ field => $ option ) { unset ( $ data [ 'criteria' ] [ $ field ] ) ; $ data [ 'criteria' ] [ $ this -> table -> aliasField ( $ field ) ] = $ option ; } } if ( array_key_exists ( 'display_columns' , $ data ) ) { $ data [ 'display_columns' ] = array_values ( $ data [ 'display_columns' ] ) ; foreach ( $ data [ 'display_columns' ] as & $ field ) { $ field = $ this -> table -> aliasField ( $ field ) ; } } if ( array_key_exists ( 'sort_by_field' , $ data ) ) { $ data [ 'sort_by_field' ] = $ this -> table -> aliasField ( $ data [ 'sort_by_field' ] ) ; } return $ data ; } ; $ saved = $ filterFunc ( $ saved ) ; $ latest = $ filterFunc ( $ latest ) ; $ entity -> set ( 'user_id' , $ this -> user [ 'id' ] ) ; $ entity -> set ( 'model' , $ this -> table -> getRegistryAlias ( ) ) ; $ entity -> set ( 'content' , [ 'saved' => $ saved , 'latest' => $ latest ] ) ; return $ entity ; }
Normalize search.

@param \Search\Model\Entity\SavedSearch $entity Search entity
@param mixed[] $saved Saved search data
@param mixed[] $latest Latest search data
@return \Search\Model\Entity\SavedSearch
Normalize search .