mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 00:06:55 +02:00
Update the MarkupQA abstract link feature so that it gets URLs directly from Page objects when the Page::path method is hooked. Previously it would use the $pages->getPath() method which is not aware of hooks to the Page::path method, so could return a different result.
This commit is contained in:
@@ -509,7 +509,6 @@ class MarkupQA extends Wire {
|
|||||||
$replacements = array();
|
$replacements = array();
|
||||||
$languages = $this->wire()->languages;
|
$languages = $this->wire()->languages;
|
||||||
$config = $this->wire()->config;
|
$config = $this->wire()->config;
|
||||||
$pages = $this->wire()->pages;
|
|
||||||
$rootURL = $config->urls->root;
|
$rootURL = $config->urls->root;
|
||||||
$adminURL = $config->urls->admin;
|
$adminURL = $config->urls->admin;
|
||||||
$adminPath = $rootURL === '/' ? $adminURL : str_replace($rootURL, '/', $adminURL);
|
$adminPath = $rootURL === '/' ? $adminURL : str_replace($rootURL, '/', $adminURL);
|
||||||
@@ -543,9 +542,7 @@ class MarkupQA extends Wire {
|
|||||||
$language = null;
|
$language = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$livePath = $pages->getPath($pageID, array(
|
$livePath = $this->getPagePathFromId($pageID, $language);
|
||||||
'language' => $language
|
|
||||||
));
|
|
||||||
|
|
||||||
if($urlSegmentStr) {
|
if($urlSegmentStr) {
|
||||||
$livePath = rtrim($livePath, '/') . "/$urlSegmentStr";
|
$livePath = rtrim($livePath, '/') . "/$urlSegmentStr";
|
||||||
@@ -1026,4 +1023,68 @@ class MarkupQA extends Wire {
|
|||||||
$this->settings['verbose'] = $verbose ? true : false;
|
$this->settings['verbose'] = $verbose ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given page ID return the path to it
|
||||||
|
*
|
||||||
|
* @param int $pageID
|
||||||
|
* @param Language|null $language
|
||||||
|
* @return string
|
||||||
|
* @since 3.0.330
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function getPagePathFromId($pageID, $language = null) {
|
||||||
|
|
||||||
|
$pages = $this->wire()->pages;
|
||||||
|
$path = null;
|
||||||
|
|
||||||
|
if($this->isPagePathHooked()) {
|
||||||
|
$this->warning("page path is hooked");
|
||||||
|
$page = $pages->get($pageID);
|
||||||
|
if($page->id) {
|
||||||
|
if($language && $language->id) {
|
||||||
|
$languages = $this->wire()->languages;
|
||||||
|
$languages->setLanguage($language);
|
||||||
|
$path = $page->path();
|
||||||
|
$languages->unsetLanguage();
|
||||||
|
} else {
|
||||||
|
$path = $page->path();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($path === null) {
|
||||||
|
$path = $pages->getPath($pageID, array(
|
||||||
|
'language' => $language
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the Page::path method hooked in a manner that might affect MarkupQA?
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* @since 3.0.330
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function isPagePathHooked() {
|
||||||
|
$config = $this->wire()->config;
|
||||||
|
$property = '_MarkupQA_pagePathHooked';
|
||||||
|
$hooked = $config->get($property);
|
||||||
|
if($hooked !== null) return $hooked;
|
||||||
|
$hooks = $this->wire()->hooks;
|
||||||
|
$hooked = $hooks->isHooked('Page::path()');
|
||||||
|
if($hooked) {
|
||||||
|
// only consider Page::path hooked if something other than LanguageSupportPageNames hooks it
|
||||||
|
$hookItems = $hooks->getHooks($this->page, 'path', WireHooks::getHooksStatic);
|
||||||
|
foreach($hookItems as $key => $hook) {
|
||||||
|
if(((string) $hook['toObject']) === 'LanguageSupportPageNames') unset($hookItems[$key]);
|
||||||
|
}
|
||||||
|
$hooked = count($hookItems) > 0;
|
||||||
|
}
|
||||||
|
$config->setQuietly($property, $hooked);
|
||||||
|
return $hooked;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user