Pimcore\Model\Object\ClassDefinition\Data\Classificationstore::enrichLayoutDefinition PHP Метод

enrichLayoutDefinition() публичный Метод

public enrichLayoutDefinition ( $object )
    public function enrichLayoutDefinition($object)
    {
        $groupCollectionMapping = $this->recursiveGetActiveGroupCollectionMapping($object);
        $this->activeGroupDefinitions = [];
        $activeGroupIds = $this->recursiveGetActiveGroupsIds($object);
        if (!$activeGroupIds) {
            return;
        }
        $filteredGroupIds = [];
        foreach ($activeGroupIds as $groupId => $enabled) {
            if ($enabled) {
                $filteredGroupIds[] = $groupId;
            }
        }
        $condition = "ID in (" . implode(',', $filteredGroupIds) . ")";
        $groupList = new Object\Classificationstore\GroupConfig\Listing();
        $groupList->setCondition($condition);
        $groupList->setOrder(["ASC", "ASC"]);
        $groupList = $groupList->load();
        /** @var  $group Object\Classificationstore\GroupConfig */
        foreach ($groupList as $group) {
            $keyList = [];
            $relation = new Object\Classificationstore\KeyGroupRelation\Listing();
            $relation->setCondition("groupId = " . $relation->quote($group->getId()));
            $relation->setOrderKey(["sorter", "id"]);
            $relation->setOrder(["ASC", "ASC"]);
            $relation = $relation->load();
            /** @var  $key Object\Classificationstore\KeyGroupRelation */
            foreach ($relation as $key) {
                if (!$key->isEnabled()) {
                    continue;
                }
                $definition = \Pimcore\Model\Object\Classificationstore\Service::getFieldDefinitionFromKeyConfig($key);
                $definition->setTooltip($definition->getName() . " - " . $key->getDescription());
                if (method_exists($definition, "__wakeup")) {
                    $definition->__wakeup();
                }
                if ($definition) {
                    $definition->setMandatory($definition->getMandatory() || $key->isMandatory());
                }
                $keyList[] = ["name" => $key->getName(), "id" => $key->getKeyId(), "description" => $key->getDescription(), "definition" => $definition];
            }
            $this->activeGroupDefinitions[$group->getId()] = ["name" => $group->getName(), "id" => $group->getId(), "description" => $group->getDescription(), "keys" => $keyList];
        }
        if ($groupCollectionMapping) {
            $collectionIds = array_values($groupCollectionMapping);
            $relation = new Object\Classificationstore\CollectionGroupRelation\Listing();
            $condition = "colId IN (" . implode(",", $collectionIds) . ")";
            $relation->setCondition($condition);
            $relation = $relation->load();
            $sorting = [];
            /** @var $item Object\Classificationstore\CollectionGroupRelation */
            foreach ($relation as $item) {
                $sorting[$item->getGroupId()] = $item->getSorter();
            }
            usort($this->activeGroupDefinitions, function ($a, $b) use($sorting) {
                $s1 = $sorting[$a["id"]] ? $sorting[$a["id"]] : 0;
                $s2 = $sorting[$b["id"]] ? $sorting[$b["id"]] : 0;
                if ($s1 < $s2) {
                    return 1;
                } elseif ($s2 > $s1) {
                    return -1;
                } else {
                    return 0;
                }
            });
        }
    }