Jump to content

Page::localUrl and Page::localPath docs inaccuracy


Zeka
 Share

Recommended Posts

Hi.

Description in the docs for these methods says 'Return the page path in the current user's language, or specify $language argument (Language object, name, or ID).'.

But from what I see in the code it returns the page path in default user's language or in specified language....

	/**
	 * Add a Page::localPath function with optional $language as argument
	 *
	 * event param Language|string|int Optional language 
	 * event return string Localized language path
	 * 
	 * @param HookEvent $event
	 *
	 */
	public function hookPageLocalPath(HookEvent $event) {
		/** @var Page $page */
		$page = $event->object; 
		$language = $this->getLanguage($event->arguments(0)); 
		$event->return = $this->getPagePath($page, $language); 	
	}

	/**
	 * Add a Page::localUrl function with optional $language as argument
	 *
	 * event param Language|string|int Optional language 
	 * event return string Localized language URL
	 * 
	 * @param HookEvent $event
	 *
	 */
	public function hookPageLocalUrl(HookEvent $event) {
		/** @var Page $page */
		$page = $event->object; 
		$language = $this->getLanguage($event->arguments(0)); 
		$event->return = $this->wire('config')->urls->root . ltrim($this->getPagePath($page, $language), '/'); 	
	}
	

	/**
	 * Given an object, integer or string, return the Language object instance
	 *
	 * @param int|string|Language
	 * @return Language
	 *
	 */
	protected function getLanguage($language) {

		if(is_object($language)) {
			if($language instanceof Language) return $language; 
			$language = '';
		}

		if($language && (is_string($language) || is_int($language))) {
			if(ctype_digit("$language")) $language = (int) $language; 
				else $language = $this->wire('sanitizer')->pageNameUTF8($language); 
			$language = $this->wire("languages")->get($language); 
		}

		if(!$language || !$language->id || !$language instanceof Language) {
			$language = $this->wire('languages')->get('default'); 
		}

		return $language; 
	}

Am I right? Should I reise an issue to aks Ryan to correct it? 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...