Pimcore\Model\Object\Classificationstore::getLocalizedKeyValue PHP Method

getLocalizedKeyValue() public method

public getLocalizedKeyValue ( $groupId, $keyId, string $language = "default", boolean | false $ignoreFallbackLanguage = false, $ignoreDefaultLanguage = false ) : null
$groupId
$keyId
$language string
$ignoreFallbackLanguage boolean | false
return null
    public function getLocalizedKeyValue($groupId, $keyId, $language = "default", $ignoreFallbackLanguage = false, $ignoreDefaultLanguage = false)
    {
        $oid = $this->object->getId();
        $keyConfig = Model\Object\Classificationstore\DefinitionCache::get($keyId);
        if ($keyConfig->getType() == "calculatedValue") {
            $data = new Model\Object\Data\CalculatedValue($this->getFieldname());
            $childDef = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
            $data->setContextualData("classificationstore", $this->getFieldname(), null, $language, $groupId, $keyId, $childDef);
            $data = Model\Object\Service::getCalculatedFieldValueForEditMode($this->getObject(), [], $data);
            return $data;
        }
        $fieldDefinition = Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
        $language = $this->getLanguage($language);
        $data = null;
        if (array_key_exists($groupId, $this->items) && array_key_exists($keyId, $this->items[$groupId]) && array_key_exists($language, $this->items[$groupId][$keyId])) {
            $data = $this->items[$groupId][$keyId][$language];
        }
        // check for fallback value
        if ($fieldDefinition->isEmpty($data) && !$ignoreFallbackLanguage && self::doGetFallbackValues()) {
            $data = $this->getFallbackValue($groupId, $keyId, $language, $fieldDefinition);
        }
        if ($fieldDefinition->isEmpty($data) && !$ignoreDefaultLanguage && $language != "default") {
            $data = $this->items[$groupId][$keyId]["default"];
        }
        // check for inherited value
        $doGetInheritedValues = AbstractObject::doGetInheritedValues();
        if ($fieldDefinition->isEmpty($data) && $doGetInheritedValues) {
            $object = $this->getObject();
            $class = $object->getClass();
            $allowInherit = $class->getAllowInherit();
            if ($allowInherit) {
                if ($object->getParent() instanceof AbstractObject) {
                    $parent = $object->getParent();
                    while ($parent && $parent->getType() == "folder") {
                        $parent = $parent->getParent();
                    }
                    if ($parent && ($parent->getType() == "object" || $parent->getType() == "variant")) {
                        if ($parent->getClassId() == $object->getClassId()) {
                            $method = "getLocalizedfields";
                            if (method_exists($parent, $method)) {
                                $getter = "get" . ucfirst($this->fieldname);
                                $classificationStore = $parent->{$getter}();
                                if ($classificationStore instanceof Classificationstore) {
                                    if ($classificationStore->object->getId() != $this->object->getId()) {
                                        $data = $classificationStore->getLocalizedKeyValue($groupId, $keyId, $language, false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if ($fieldDefinition && method_exists($fieldDefinition, "preGetData")) {
            $data = $fieldDefinition->preGetData($this, ["data" => $data, "language" => $language, "name" => $groupId . "-" . $keyId]);
        }
        return $data;
    }