src/Pages/HailPageController.php
public function article(HTTPRequest $request)
    {
        $params = $request->params();
        if ($params['ID']) {
            $article = Article::get()->filter(['HailID' => $params['ID']])->first();
            //Try to find the article with the database ID field, to be backward compatible with old Hail module (after upgrade)
            if(!isset($article) || empty($article)) {
                $article = Article::get()->filter(['ID' => $params['ID']])->first();
            }
        }

        if (!$params['ID'] || !isset($article) || empty($article)) {
            return $this->httpError(404, 'That article could not be found');
        }
        $data = [
            'Article' => $article,
            'Related' => null
        ];
        
        //Store the current article so we can use it in other functions in the controller
        $this->article = $article;

        //If Related Articles are enabled on the page (from the CMS)
        if ($this->owner->EnableRelated === "Yes") {
            //Try to find 3 related articles
            if ($article->PublicTags()->Count() > 0) {
                $related = Article::get()->filter(['PublicTags.ID' => $article->PublicTags()->map('ID', 'ID')->toArray()])->exclude(['HailID' => $params['ID']])->sort('Date DESC')->limit(3);
                if ($related->Count() > 0) {
                    $data['Related'] = $related;
                }
            }
        }

        return $data;
    }
public function article(HTTPRequest $request)
    {
        $params = $request->params();
        if ($params['ID']) {
            $article = Article::get()->filter(['HailID' => $params['ID']])->first();
            //Try to find the article with the database ID field, to be backward compatible with old Hail module (after upgrade)
            if(!isset($article) || empty($article)) {
                $article = Article::get()->filter(['ID' => $params['ID']])->first();
            }
        }

        if (!$params['ID'] || !isset($article) || empty($article)) {
            return $this->httpError(404, 'That article could not be found');
        }
        $data = [
            'Article' => $article,
            'Related' => null
        ];
        
        //Store the current article so we can use it in other functions in the controller
        $this->article = $article;

        //If Related Articles are enabled on the page (from the CMS)
        if ($this->owner->EnableRelated === "Yes") {
            //Try to find 3 related articles
            if ($article->PublicTags()->Count() > 0) {
                $related = Article::get()->filter(['PublicTags.ID' => $article->PublicTags()->map('ID', 'ID')->toArray()])->exclude(['HailID' => $params['ID']])->sort('Date DESC')->limit(3);
                if ($related->Count() > 0) {
                    $data['Related'] = $related;
                }
            }
        }

        return $data;
    }
public function article ( HTTPRequest $ request ) { $ params = $ request -> params ( ) ; if ( $ params [ 'ID' ] ) { $ article = Article :: get ( ) -> filter ( [ 'HailID' => $ params [ 'ID' ] ] ) -> first ( ) ; //Try to find the article with the database ID field, to be backward compatible with old Hail module (after upgrade)
 if ( ! isset ( $ article ) || empty ( $ article ) ) { $ article = Article :: get ( ) -> filter ( [ 'ID' => $ params [ 'ID' ] ] ) -> first ( ) ; } } if ( ! $ params [ 'ID' ] || ! isset ( $ article ) || empty ( $ article ) ) { return $ this -> httpError ( 404 , 'That article could not be found' ) ; } $ data = [ 'Article' => $ article , 'Related' => null ] ; //Store the current article so we can use it in other functions in the controller
 $ this -> article = $ article ; //If Related Articles are enabled on the page (from the CMS)
 if ( $ this -> owner -> EnableRelated === "Yes" ) { //Try to find 3 related articles
 if ( $ article -> PublicTags ( ) -> Count ( ) > 0 ) { $ related = Article :: get ( ) -> filter ( [ 'PublicTags.ID' => $ article -> PublicTags ( ) -> map ( 'ID' , 'ID' ) -> toArray ( ) ] ) -> exclude ( [ 'HailID' => $ params [ 'ID' ] ] ) -> sort ( 'Date DESC' ) -> limit ( 3 ) ; if ( $ related -> Count ( ) > 0 ) { $ data [ 'Related' ] = $ related ; } } } return $ data ; }
Render a Hail Article

@param HTTPRequest $request

@return array
@throws HTTPResponse_Exception
Render a Hail Article