NerdsAndCompany\Schematic\Models\Field::getSource PHP Метод

getSource() приватный Метод

Gets a source by the attribute indexFrom, and returns it with attribute $indexTo.
private getSource ( string $fieldType, string $source, string $indexFrom, string $indexTo ) : string
$fieldType string
$source string
$indexFrom string
$indexTo string
Результат string
    private function getSource($fieldType, $source, $indexFrom, $indexTo)
    {
        if ($source == 'singles' || $source == '*') {
            return $source;
        }
        /** @var BaseElementModel $sourceObject */
        $sourceObject = null;
        if (strpos($source, ':') > -1) {
            list($sourceType, $sourceFrom) = explode(':', $source);
            switch ($sourceType) {
                case 'section':
                    $service = Craft::app()->sections;
                    $method = 'getSectionBy';
                    break;
                case 'group':
                    $service = $fieldType == 'Users' ? Craft::app()->userGroups : Craft::app()->categories;
                    $method = 'getGroupBy';
                    break;
                case 'folder':
                    $service = Craft::app()->schematic_assetSources;
                    $method = 'getSourceTypeBy';
                    break;
                case 'taggroup':
                    $service = Craft::app()->tags;
                    $method = 'getTagGroupBy';
                    break;
            }
        } elseif ($source !== 'singles') {
            //Backwards compatibility
            $sourceType = 'section';
            $sourceFrom = $source;
            $service = Craft::app()->sections;
            $method = 'getSectionBy';
        }
        if (isset($service) && isset($method) && isset($sourceFrom)) {
            $method = $method . $indexFrom;
            $sourceObject = $service->{$method}($sourceFrom);
        }
        if ($sourceObject && isset($sourceType)) {
            return $sourceType . ':' . $sourceObject->{$indexTo};
        }
        return '';
    }