findByIdOrAliasAndPid() публичный статический Метод

Find an article by its ID or alias and its page
public static findByIdOrAliasAndPid ( mixed $varId, integer $intPid, array $arrOptions = [] ) : ArticleModel | null
$varId mixed The numeric ID or alias name
$intPid integer The page ID
$arrOptions array An optional options array
Результат ArticleModel | null The model or null if there is no article
 /**
  * Translate URL parameters for articles.
  *
  * @param ChangelanguageNavigationEvent $event
  */
 public function onChangelanguageNavigation(ChangelanguageNavigationEvent $event)
 {
     // Try to find matching article
     if ($event->getNavigationItem()->isCurrentPage() || !$event->getUrlParameterBag()->hasUrlAttribute('articles')) {
         return;
     }
     /** @var PageModel $objPage */
     global $objPage;
     $parameterBag = $event->getUrlParameterBag();
     $currentArticle = ArticleModel::findByIdOrAliasAndPid($parameterBag->getUrlAttribute('articles'), $objPage->id);
     if (null === $currentArticle) {
         return;
     }
     $pageFinder = new PageFinder();
     $targetRoot = $event->getNavigationItem()->getRootPage();
     $masterRoot = $pageFinder->findMasterRootForPage($targetRoot);
     $targetArticle = $this->findTargetArticle($currentArticle, $targetRoot->id, $objPage->rootId === $masterRoot->id, null !== $masterRoot && $targetRoot->id === $masterRoot->id);
     if (null === $targetArticle) {
         $parameterBag->removeUrlAttribute('articles');
     } else {
         $parameterBag->setUrlAttribute('articles', $targetArticle->alias);
     }
 }
Пример #2
0
 /**
  * Generate an article and return it as string
  *
  * @param mixed   $varId          The article ID or a Model object
  * @param boolean $blnMultiMode   If true, only teasers will be shown
  * @param boolean $blnIsInsertTag If true, there will be no page relation
  * @param string  $strColumn      The name of the column
  *
  * @return string|boolean The article HTML markup or false
  */
 public static function getArticle($varId, $blnMultiMode = false, $blnIsInsertTag = false, $strColumn = 'main')
 {
     /** @var \PageModel $objPage */
     global $objPage;
     if (is_object($varId)) {
         $objRow = $varId;
     } else {
         if (!$varId) {
             return '';
         }
         $objRow = \ArticleModel::findByIdOrAliasAndPid($varId, !$blnIsInsertTag ? $objPage->id : null);
         if ($objRow === null) {
             return false;
         }
     }
     // Check the visibility (see #6311)
     if (!static::isVisibleElement($objRow)) {
         return '';
     }
     // Print the article as PDF
     if (isset($_GET['pdf']) && \Input::get('pdf') == $objRow->id) {
         // Deprecated since Contao 4.0, to be removed in Contao 5.0
         if ($objRow->printable == 1) {
             trigger_error('Setting tl_article.printable to "1" has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED);
             $objArticle = new \ModuleArticle($objRow);
             $objArticle->generatePdf();
         } elseif ($objRow->printable != '') {
             $options = deserialize($objRow->printable);
             if (is_array($options) && in_array('pdf', $options)) {
                 $objArticle = new \ModuleArticle($objRow);
                 $objArticle->generatePdf();
             }
         }
     }
     $objRow->headline = $objRow->title;
     $objRow->multiMode = $blnMultiMode;
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['getArticle']) && is_array($GLOBALS['TL_HOOKS']['getArticle'])) {
         foreach ($GLOBALS['TL_HOOKS']['getArticle'] as $callback) {
             static::importStatic($callback[0])->{$callback}[1]($objRow);
         }
     }
     $objArticle = new \ModuleArticle($objRow, $strColumn);
     $strBuffer = $objArticle->generate($blnIsInsertTag);
     // Disable indexing if protected
     if ($objArticle->protected && !preg_match('/^\\s*<!-- indexer::stop/', $strBuffer)) {
         $strBuffer = "\n<!-- indexer::stop -->" . $strBuffer . "<!-- indexer::continue -->\n";
     }
     return $strBuffer;
 }