@param string  $type
@param mixed[] $config
@param mixed[] $parentConfig

@return string
9448
protected function prepareLabel($type, array $config, array $parentConfig)
    {
        return $label = isset($config['label'])
            ? $config['label']
            : 'lug.'.$this->buildResource($parentConfig)->getName().'.'.$type.'.'.$config['name'];
    }
1103380
public function when(string $type, array $config = []): self
    {
        if (! isset($this->data['on'][$type])) {
            $this->data['on'][$type] = [];
        }

        $this->data['on'][$type] = \array_merge($this->data['on'][$type], $config);

        return $this;
    }
1255368
public static function queryByTypeParentTypeModelId( $type, $parentType, $modelId ) {

		return self::find()->where( 'type=:type AND parentType=:ptype AND modelId=:mid', [ ':type' => $type, ':parentType' => $parentType, ':mid' => $modelId ] );
	}
369725
public static function queryByParentType( $parentType, $config = [] ) {

		$type	= isset( $config[ 'type' ] ) ? $config[ 'type' ] : self::TYPE_COMMENT;
		$status	= isset( $config[ 'status' ] ) ? $config[ 'status' ] : self::STATUS_APPROVED;

		return self::find()->where( [ 'parentType' => $parentType, 'type' => $type, 'status' => $status ] );
	}
464373
public function createWithParent( $parent, $config = [] ) {

		$modelClass	= static::$modelClass;

		$parentId	= $config[ 'parentId' ];
		$parentType	= $config[ 'parentType' ];
		$type		= isset( $config[ 'type' ] ) ? $config[ 'type' ] : $parent->type;
		$order		= isset( $config[ 'order' ] ) ? $config[ 'order' ] : 0;

		$file = null;

		switch( $parent->type ) {

			case 'image': {

				$file = $this->fileService->saveImage( $parent );
			}
			// TODO: Add case to save cross-browser compatible videos
			default: {

				$file = $this->fileService->saveFile( $parent );
			}
		}

		$model = new $modelClass;

		$model->modelId		= $file->id;
		$model->parentId	= $parentId;
		$model->parentType	= $parentType;

		$model->type	= $type;
		$model->order	= $order;
		$model->active	= true;

		return parent::create( $model );
	}
901808
protected function buildBatch(array $config, array $parentConfig)
    {
        return $this->batchBuilder->build($this->prepareConfig($config, $parentConfig));
    }
811552
public static function findByParent( $parentId, $parentType, $config = [] ) {

		return self::queryByParent( $parentId, $parentType, $config )->all();
	}
104962
static public function createObject($type, array $config = [])
	{
		if (is_string($type)) {
			return static::container()->get($type, $config);
		} elseif (is_array($type) && isset($type['class'])) {
			$class = $type['class'];
			unset($type['class']);
			if ($config) $type = array_merge($type, $config); 
			return static::container()->get($class, $type);
		} elseif (is_callable($type, false)) {
			return call_user_func($type, $config);
		} elseif (is_object($type)) {
			return $type;
		} elseif (is_array($type)) {
			throw new InvalidConfigException('object configuration must be an array containing a "class" element.');
		} else {
			throw new InvalidConfigException("Unsupported configuration type: " . gettype($type));
		}
	}
316114
private function addParentFilter(ConfigInterface $config, ModelInterface $parentModel)
    {
        $environment     = $this->getEnvironment();
        $definition      = $environment->getDataDefinition();
        $basicDefinition = $definition->getBasicDefinition();

        if (!$basicDefinition->getParentDataProvider()) {
            return;
        }

        if ($basicDefinition->getParentDataProvider() !== $parentModel->getProviderName()) {
            throw new \RuntimeException(
                \sprintf(
                    'Parent provider mismatch: %s vs. %s',
                    $basicDefinition->getParentDataProvider(),
                    $parentModel->getProviderName()
                )
            );
        }

        // Apply parent filtering, do this only for root elements.
        if ($parentCondition = $definition->getModelRelationshipDefinition()->getChildCondition(
            $basicDefinition->getParentDataProvider(),
            $basicDefinition->getRootDataProvider()
        )) {
            $baseFilter = $config->getFilter();
            $filter     = $parentCondition->getFilter($parentModel);

            if ($baseFilter) {
                $filter = \array_merge($baseFilter, $filter);
            }

            $config->setFilter($filter);
        }
    }
135892
public function belongsTo( $parent, $parentType ) {

		return $this->parentId == $parent->id && $this->parentType == $parentType;
	}
1328135
public static function config($config = null) {
		$defaults = ['scope' => null];

		if (is_array($config)) {
			foreach ($config as $i => $item) {
				$config[$i] += $defaults;
			}
		}
		return parent::config($config);
	}
268821
public function generate(Config $config)
    {
        $parts = array();
        if ($config->parent) {
            $parent = $config->parent->isRepresentant() ? $config->parent->parent : $config->parent;
            $parts[] = $this->generate($parent);
        }

        $parts[] = $this->getPrefix($config);

        return implode('_', array_filter($parts));
    }
605719
public function getImageListAjaxAction($parentId, $parentType)
    {
        $this->checkAuth($this->getAdminResources()->getResource($parentType, static::MODULE_RIGHT), array(), AccessManager::UPDATE);
        $this->checkXmlHttpRequest();
        $args = array('imageType' => $parentType, 'parentId' => $parentId);

        return $this->render('includes/image-upload-list-ajax', $args);
    }
306353
private function getParentSettings($type, $context = null)
    {
        $context = $this->normalizeContext($context);

        $methods = array(
            'source' => 'getSources',
            'worker' => 'getWorkers',
            'target' => 'getTargets',
        );

        if (!array_key_exists($type, $methods) || $context->getParent() === null) {
            return array();
        }

        $settings = array_merge(
            $this->getParentComponentSettings($context->getParent(), $methods[$type]),
            $this->getParentSettings($type, $context->getParent())
        );

        return $settings;
    }
1148547
public function getFollowersIdList( $parentId, $config = [] ) {

	$type = $config[ 'type' ] ?? IFollower::TYPE_FOLLOW;

        return self::findList( [  'column' => 'modelId', 'conditions' => [ 'type' => $type, 'active' => true, 'parentId' => $parentId ] ] );
    }
299718
public function generate(Config $config)
    {
        $parts = array();
        if ($config->parent) {
            $parts[] = str_replace(
                array('{id}', '.{_format}'),
                array(sprintf('{%sId}', $this->getPrefix($config->parent)), ''),
                $this->generate($config->parent)
            );
        }
        $parts[] = $this->getPrefix($config);

        $prefix = implode('/', array_filter($parts));
        $pattern = $this->getPattern($config);

        if (isset($pattern[0]) && '/' !== $pattern[0] && '.' !== $pattern[0]) {
            return rtrim($prefix, '/').'/'.$pattern;
        }

        return $prefix.$pattern;
    }
1069512
public static function dumpToFile(Config $config, $type)
    {
        if ($type === Config::CONFIG_LOCAL) {
            $filename = $config->get('local_config');

            if (null === $filename) {
                throw new \RuntimeException('Local configuration is not loaded and therefore it cannot be dumped.');
            }
        } elseif ($type === Config::CONFIG_SYSTEM) {
            $filename = $config->get('home_config');
        } else {
            throw new \InvalidArgumentException(
                sprintf(
                    'Config slot "%s" is not valid for dumping to a file "%s", use either: '.
                    'Config::CONFIG_SYSTEM or Config::CONFIG_LOCAL.',
                    $type
                )
            );
        }

        // Testing compatibility, write directly as there is no risk of problems
        if ('vfs://' === substr($filename, 0, 6)) {
            file_put_contents($filename, Yaml::dump($config->toArray($type)));
        } else {
            self::getFilesystem()->dumpFile(
                $filename,
                "# Gush configuration file, any comments will be lost.\n".Yaml::dump($config->toArray($type), 2)
            );
        }

        return $filename;
    }