infoweb\cms\behaviors\ImageBehave::getImageByIdentifier PHP Method

getImageByIdentifier() public method

Returns a model's image with a specific identifier
public getImageByIdentifier ( string $identifier = '', $fallbackToPlaceholder = true, $placeHolderPath = null ) : array | null | ActiveRecord
$identifier string The identifier of the image
return array | null | ActiveRecord
    public function getImageByIdentifier($identifier = '', $fallbackToPlaceholder = true, $placeHolderPath = null)
    {
        if ($identifier == '') {
            return $this->owner->getImage($fallbackToPlaceholder, $placeHolderPath);
        }
        if ($this->getModule()->className === null) {
            $imageQuery = Image::find();
        } else {
            $class = $this->getModule()->className;
            $imageQuery = $class::find();
        }
        $finder = $this->getImagesFinder(['identifier' => $identifier]);
        $imageQuery->where($finder);
        $img = $imageQuery->one();
        if (!$img && $fallbackToPlaceholder) {
            if (!$placeHolderPath) {
                return new PlaceHolder();
            } else {
                return new Image(['filePath' => basename(Yii::getAlias($placeHolderPath)), 'urlAlias' => basename($placeHolderPath)]);
            }
        }
        return $img;
    }