protected function _unsetEmptyFields(EntityInterface $entity)
    {
        $translations = (array)$entity->get('_translations');
        foreach ($translations as $locale => $translation) {
            $fields = $translation->extract($this->_config['fields'], false);
            foreach ($fields as $field => $value) {
                if (strlen($value) === 0) {
                    $translation->unsetProperty($field);
                }
            }

            $translation = $translation->extract($this->_config['fields']);

            // If now, the current locale property is empty,
            // unset it completely.
            if (empty(array_filter($translation))) {
                unset($entity->get('_translations')[$locale]);
            }
        }

        // If now, the whole _translations property is empty,
        // unset it completely and return
        if (empty($entity->get('_translations'))) {
            $entity->unsetProperty('_translations');
        }
    }
protected function _unsetEmptyFields(EntityInterface $entity)
    {
        $translations = (array)$entity->get('_translations');
        foreach ($translations as $locale => $translation) {
            $fields = $translation->extract($this->_config['fields'], false);
            foreach ($fields as $field => $value) {
                if (strlen($value) === 0) {
                    $translation->unsetProperty($field);
                }
            }

            $translation = $translation->extract($this->_config['fields']);

            // If now, the current locale property is empty,
            // unset it completely.
            if (empty(array_filter($translation))) {
                unset($entity->get('_translations')[$locale]);
            }
        }

        // If now, the whole _translations property is empty,
        // unset it completely and return
        if (empty($entity->get('_translations'))) {
            $entity->unsetProperty('_translations');
        }
    }
protected function _unsetEmptyFields ( EntityInterface $ entity ) { $ translations = ( array ) $ entity -> get ( '_translations' ) ; foreach ( $ translations as $ locale => $ translation ) { $ fields = $ translation -> extract ( $ this -> _config [ 'fields' ] , false ) ; foreach ( $ fields as $ field => $ value ) { if ( strlen ( $ value ) === 0 ) { $ translation -> unsetProperty ( $ field ) ; } } $ translation = $ translation -> extract ( $ this -> _config [ 'fields' ] ) ; // If now, the current locale property is empty, // unset it completely. if ( empty ( array_filter ( $ translation ) ) ) { unset ( $ entity -> get ( '_translations' ) [ $ locale ] ) ; } } // If now, the whole _translations property is empty, // unset it completely and return if ( empty ( $ entity -> get ( '_translations' ) ) ) { $ entity -> unsetProperty ( '_translations' ) ; } }
Unset empty translations to avoid persistence.

Should only be called if $this->_config['allowEmptyTranslations'] is false.

@param \Cake\Datasource\EntityInterface $entity The entity to check for empty translations fields inside.
@return void
Unset empty translations to avoid persistence .