function getPreferredImage($aspect = null, $orientation = null)
    {
        // If theres no images, check for placeholders
        if (!$this->getFilteredMedia(['image'], false)) {
            if ($ph = $this->getPlaceholder()) {
                if ($aspect) {
                    return $ph['meta']['src'][$aspect];
                }
                return $ph;
            }
            return null;
        }

        if ($this->hasPreferredImage()) {
            $medium = $this->getMedium($this['meta']['media']['preferred_image']);
        }
        elseif ($orientation) {
            $medium = $this->getPreferredImageByOrientation($orientation);
        }
        else {
            $medium = $this['media'][0];
        }

        if ($aspect) {
            return $medium['meta']['src'][$aspect];
        }
        return $medium;
    }
function getPreferredImage($aspect = null, $orientation = null)
    {
        // If theres no images, check for placeholders
        if (!$this->getFilteredMedia(['image'], false)) {
            if ($ph = $this->getPlaceholder()) {
                if ($aspect) {
                    return $ph['meta']['src'][$aspect];
                }
                return $ph;
            }
            return null;
        }

        if ($this->hasPreferredImage()) {
            $medium = $this->getMedium($this['meta']['media']['preferred_image']);
        }
        elseif ($orientation) {
            $medium = $this->getPreferredImageByOrientation($orientation);
        }
        else {
            $medium = $this['media'][0];
        }

        if ($aspect) {
            return $medium['meta']['src'][$aspect];
        }
        return $medium;
    }
function getPreferredImage ( $ aspect = null , $ orientation = null ) { // If theres no images, check for placeholders if ( ! $ this -> getFilteredMedia ( [ 'image' ] , false ) ) { if ( $ ph = $ this -> getPlaceholder ( ) ) { if ( $ aspect ) { return $ ph [ 'meta' ] [ 'src' ] [ $ aspect ] ; } return $ ph ; } return null ; } if ( $ this -> hasPreferredImage ( ) ) { $ medium = $ this -> getMedium ( $ this [ 'meta' ] [ 'media' ] [ 'preferred_image' ] ) ; } elseif ( $ orientation ) { $ medium = $ this -> getPreferredImageByOrientation ( $ orientation ) ; } else { $ medium = $ this [ 'media' ] [ 0 ] ; } if ( $ aspect ) { return $ medium [ 'meta' ] [ 'src' ] [ $ aspect ] ; } return $ medium ; }
If there is a preferred image this one will be returned. If not, the first one of the
collection will be returned.

If an $orientation is passed, @getPreferredImageByOrientation will be called as a fallback, this will allow
alot less boilerplate code in sitations where you might want the user' favourite image as the highest priority,
but the best fitting alternative to a certain orientation, if not.

F.e.: A large header image:

getPreferredImage('1080p', 'landscape')          Get the user-preferred image, and return the url to the source
of the '1080' format. Or give me the image that best fits the
'landscape' aspect. And if there is no image found at all, give me
a placeholder if possible.

NB: Falls back to placeholders

@param null $aspect                              Return the src string instead of the medium array
@param string|null $orientation                  portrait|landscape|null

@return null|string|array
If there is a preferred image this one will be returned . If not the first one of the collection will be returned .