Created
October 31, 2017 17:37
-
-
Save litzinger/f2659d9d77b3f84010ff164ef6356f20 to your computer and use it in GitHub Desktop.
Publisher hook example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$query = $this->query->modify( | |
'ORDER BY', | |
' AND ae.publisher_lang_id = '. $publisher_lang_id .' AND ae.publisher_status = "'. $publisher_status .'" ORDER BY', | |
$sql | |
); | |
// Publisher is disabled, but we still need to get default rows, | |
// otherwise it'll show duplicate rows. | |
if (!$this->setting->get('enabled')) | |
{ | |
return $query; | |
} | |
// If no rows were found, and fallback is set, then query default language instead. | |
if ($this->setting->show_fallback() && $query->num_rows() == 0) | |
{ | |
$query = $this->query->modify( | |
'ORDER BY', | |
' AND ae.publisher_lang_id = '. $this->defaultLanguageId .' AND ae.publisher_status = "'. $publisher_status .'" ORDER BY', | |
$sql | |
); | |
/** @var \BoldMinded\Publisher\Model\Language $languageModel */ | |
$languageModel = ee('Model')->make(\BoldMinded\Publisher\Model\Language::NAME); | |
$language = $languageModel->findLanguageById($publisher_lang_id); | |
// Still no results?? Get the default language and open status as a last resort. | |
// Also used if the entry is in an ignored channel. | |
// If we don't have a draft then try harder to find fallback content. | |
// If we do have a draft assume the draft had its rows explicitly removed if we've made it this far. | |
if ( | |
(REQ == 'CP' && $query->num_rows() == 0 && !$this->entry->hasDraft($this->request->getEntryId(), $language)) || | |
(REQ != 'CP' && $query->num_rows() == 0) | |
){ | |
$query = $this->query->modify( | |
'ORDER BY', | |
' AND publisher_lang_id = '. $this->defaultLanguageId .' AND publisher_status = "'. Status::OPEN .'" ORDER BY', | |
$sql | |
); | |
if ($query->num_rows() == 0) { | |
$query = $this->query->modify( | |
'ORDER BY', | |
' AND publisher_lang_id = '. $publisher_lang_id .' AND publisher_status = "'. Status::OPEN .'" ORDER BY', | |
$sql | |
); | |
} | |
} | |
} | |
return $query; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment