Pimcore\Model\Element\Service::fixAllowedTypes PHP Method

fixAllowedTypes() public static method

public static fixAllowedTypes ( $data, $type )
    public static function fixAllowedTypes($data, $type)
    {
        // this is the new method with Ext.form.MultiSelect
        if (is_string($data) && !empty($data) || \Pimcore\Tool\Admin::isExtJS6() && is_array($data) && count($data)) {
            if (!\Pimcore\Tool\Admin::isExtJS6()) {
                $parts = explode(",", $data);
                $data = [];
                foreach ($parts as $elementType) {
                    $data[] = [$type => $elementType];
                }
            } else {
                $first = reset($data);
                if (!is_array($first)) {
                    $parts = $data;
                    $data = [];
                    foreach ($parts as $elementType) {
                        $data[] = [$type => $elementType];
                    }
                } else {
                    $newList = [];
                    foreach ($data as $key => $item) {
                        if ($item) {
                            if (is_array($item)) {
                                foreach ($item as $itemKey => $itemValue) {
                                    if ($itemValue) {
                                        $newList[$key][$itemKey] = $itemValue;
                                    }
                                }
                            } elseif ($item) {
                                $newList[$key] = $item;
                            }
                        }
                    }
                    $data = $newList;
                }
            }
        }
        return $data ? $data : [];
    }

Usage Example

Example #1
0
 /**
  * @param array $assetTypes
  * @return $this
  */
 public function setAssetTypes($assetTypes)
 {
     $this->assetTypes = Element\Service::fixAllowedTypes($assetTypes, "assetTypes");
     return $this;
 }
All Usage Examples Of Pimcore\Model\Element\Service::fixAllowedTypes