Pimcore\Model\Document\Tag\Areablock::setOptions PHP Method

setOptions() public method

public setOptions ( array $options ) : void
$options array
return void
    public function setOptions($options)
    {
        // we need to set this here otherwise custom areaDir's won't work
        $this->options = $options;
        // read available types
        $areaConfigs = $this->getBrickConfigs();
        $availableAreas = ["name" => [], "index" => []];
        if (isset($options["sorting"]) && is_array($options["sorting"]) && count($options["sorting"])) {
            $availableAreasSort = $options["sorting"];
        } else {
            if (isset($options["allowed"]) && is_array($options["allowed"]) && count($options["allowed"])) {
                $availableAreasSort = $options["allowed"];
            } else {
                $availableAreasSort = false;
            }
        }
        if (!isset($options["allowed"]) || !is_array($options["allowed"])) {
            $options["allowed"] = [];
        }
        foreach ($areaConfigs as $areaName => $areaConfig) {
            // don't show disabled bricks
            if (!isset($options['dontCheckEnabled']) || !$options['dontCheckEnabled']) {
                if (!$this->isBrickEnabled($areaName)) {
                    continue;
                }
            }
            if (empty($options["allowed"]) || in_array($areaName, $options["allowed"])) {
                $n = (string) $areaConfig->name;
                $d = (string) $areaConfig->description;
                $icon = (string) $areaConfig->icon;
                if ($this->view->editmode) {
                    if (empty($icon)) {
                        $path = $this->getPathForBrick($areaName);
                        $iconPath = $path . "/icon.png";
                        if (file_exists($iconPath)) {
                            $icon = str_replace(PIMCORE_DOCUMENT_ROOT, "", $iconPath);
                        }
                    }
                    if ($this->view) {
                        $n = $this->view->translateAdmin((string) $areaConfig->name);
                        $d = $this->view->translateAdmin((string) $areaConfig->description);
                    }
                }
                $sortIndex = false;
                $sortKey = "name";
                //allowed and sorting is not set || areaName is not in allowed
                if ($availableAreasSort) {
                    $sortIndex = array_search($areaName, $availableAreasSort);
                    $sortKey = $sortIndex === false ? $sortKey : "index";
                }
                $availableAreas[$sortKey][] = ["name" => $n, "description" => $d, "type" => $areaName, "icon" => $icon, "sortIndex" => $sortIndex];
            }
        }
        if (count($availableAreas["name"])) {
            // sort with translated names
            usort($availableAreas["name"], function ($a, $b) {
                if ($a["name"] == $b["name"]) {
                    return 0;
                }
                return $a["name"] < $b["name"] ? -1 : 1;
            });
        }
        if (count($availableAreas["index"])) {
            // sort by allowed brick config order
            usort($availableAreas["index"], function ($a, $b) {
                return $a["sortIndex"] - $b["sortIndex"];
            });
        }
        $availableAreas = array_merge($availableAreas["index"], $availableAreas["name"]);
        $options["types"] = $availableAreas;
        if (isset($options["group"]) && is_array($options["group"])) {
            $groupingareas = [];
            foreach ($availableAreas as $area) {
                $groupingareas[$area["type"]] = $area["type"];
            }
            $groups = [];
            foreach ($options["group"] as $name => $areas) {
                $n = $name;
                if ($this->view && $this->editmode) {
                    $n = $this->view->translateAdmin($name);
                }
                $groups[$n] = $areas;
                foreach ($areas as $area) {
                    unset($groupingareas[$area]);
                }
            }
            if (count($groupingareas) > 0) {
                $uncatAreas = [];
                foreach ($groupingareas as $area) {
                    $uncatAreas[] = $area;
                }
                $n = "Uncategorized";
                if ($this->view && $this->editmode) {
                    $n = $this->view->translateAdmin($n);
                }
                $groups[$n] = $uncatAreas;
            }
            $options["group"] = $groups;
        }
        if (empty($options["limit"])) {
            $options["limit"] = 1000000;
        }
        $this->options = $options;
        return $this;
    }