Pimcore\Model\Object\Classificationstore::setLocalizedKeyValue PHP Méthode

setLocalizedKeyValue() public méthode

public setLocalizedKeyValue ( $groupId, $keyId, $value, null $language = null )
$groupId
$keyId
$value
$language null
    public function setLocalizedKeyValue($groupId, $keyId, $value, $language = null)
    {
        if (!$groupId) {
            throw new \Exception("groupId not valid");
        }
        if (!$keyId) {
            throw new \Exception("keyId not valid");
        }
        $language = $this->getLanguage($language);
        // treat value "0" nonempty
        $nonEmpty = (is_string($value) || is_numeric($value)) && strlen($value) > 0;
        if ($nonEmpty || $value) {
            $this->items[$groupId][$keyId][$language] = $value;
        } elseif (isset($this->items[$groupId][$keyId][$language])) {
            unset($this->items[$groupId][$keyId][$language]);
            if (empty($this->items[$groupId][$keyId])) {
                unset($this->items[$groupId][$keyId]);
                if (empty($this->items[$groupId])) {
                    unset($this->items[$groupId]);
                }
            }
        }
        return $this;
    }

Usage Example

 /**
  * @see Model\Object\ClassDefinition\Data::getDataFromEditmode
  * @param string $containerData
  * @param null|Model\Object\AbstractObject $object
  * @param mixed $params
  * @return string
  */
 public function getDataFromEditmode($containerData, $object = null, $params = [])
 {
     $classificationStore = $this->getDataFromObjectParam($object);
     if (!$classificationStore instanceof Object\Classificationstore) {
         $classificationStore = new Object\Classificationstore();
     }
     $data = $containerData["data"];
     $activeGroups = $containerData["activeGroups"];
     $groupCollectionMapping = $containerData["groupCollectionMapping"];
     $correctedMapping = [];
     foreach ($groupCollectionMapping as $groupId => $collectionId) {
         if ($activeGroups[$groupId]) {
             $correctedMapping[$groupId] = $collectionId;
         }
     }
     $classificationStore->setGroupCollectionMappings($correctedMapping);
     if (is_array($data)) {
         foreach ($data as $language => $groups) {
             foreach ($groups as $groupId => $keys) {
                 foreach ($keys as $keyId => $value) {
                     $keyConfig = $this->getKeyConfiguration($keyId);
                     $dataDefinition = Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($keyConfig);
                     $dataFromEditMode = $dataDefinition->getDataFromEditmode($value);
                     $activeGroups[$groupId] = true;
                     $classificationStore->setLocalizedKeyValue($groupId, $keyId, $dataFromEditMode, $language);
                 }
             }
         }
     }
     $activeGroupIds = array_keys($activeGroups);
     $classificationStore->setActiveGroups($activeGroups);
     // cleanup
     $existingGroupIds = $classificationStore->getGroupIdsWithData();
     if (is_array($existingGroupIds)) {
         foreach ($existingGroupIds as $existingGroupId) {
             if (!in_array($existingGroupId, $activeGroupIds)) {
                 $classificationStore->removeGroupData($existingGroupId);
             }
         }
     }
     return $classificationStore;
 }
All Usage Examples Of Pimcore\Model\Object\Classificationstore::setLocalizedKeyValue