Override localized field


#1

Hello !

I can not create an overlay for my localized field.
I’m creating a model that goes with my class, and I’d like to change the method of my localized field to get a value that will be dynamically created, but that does not work …

/**
 * Class ProduitFini
 * @package Website\Model
 */
class ProduitFini extends \Pimcore\Model\Object\ProduitFini
{

/**
* Get DenominationLegale - Dénomination SAP
* @return string
*/
public function getDenominationLegale ($language = null) {
    return "toto";

//    	$data = $this->getLocalizedfields()->getLocalizedValue("DenominationLegale", $language);
//    	$preValue = $this->preGetValue("DenominationLegale"); 
//    	if($preValue !== null && !\Pimcore::inAdmin()) { 
//    		return $preValue;
//    	}
//    	 return $data;
}

}

An idea ?

Thanks :slight_smile:


#2

do you use class map overrides for that? https://pimcore.com/docs/5.x/Development_Documentation/Extending_Pimcore/Overriding_Models.html#page_Configure-an-Override


#3

Yes I followed this procedure as always. I never had a problem with “classic fields” (textfield, number …). As against the overload of a localized field I do not understand how to make it work.

class MyClass extends \Pimcore\Model\DataObject\MyClass {

    public function getName () {
        return "toto"; // OK
    }

    public function getDescription ($language = NULL) {
        return "toto"; // KO
    }
}