Jump to content

get field value from non-default language, $page->title


Recommended Posts

hello,

Is it possible to get any language field value, specifically for the $page->title?

My situation is this: I have the FormBuilder module that generates a page when a user fills the form. If FormBuilder is loaded in the Italian translation, FormBuilder creates a new page with the title in Italian. And if I want to get the title from the API using $page->title nothing comes up.

The form is loaded in several languages, so each time the title could be in any language and I don't know which one to pick-up.

The "Page Title (Multi-Language)" is very useful for all other pages, but not with the ones created automatically. Is there a way to solve this, something like

$page->title_first_available_entry ?

Thanks in advance for your help

Link to comment
Share on other sites

  • 4 weeks later...

Thank you LostKobrakai!

this is how I solved the problem, maybe is not the most elegant but it works

if (!$page->title) {

		$italiano = $languages->get("italiano");
		$page->setOutputFormatting(false);
		$pagetitle = $page->title->getLanguageValue($italiano); // get the unformatted value 
		
		if (!$pagetitle) {
			$spanish  = $languages->get("spanish");
			$page->setOutputFormatting(false);
			$pagetitle = $page->title->getLanguageValue($spanish); 
		}
		if (!$pagetitle) {
			$portuguese = $languages->get("portuguese");
			$page->setOutputFormatting(false);
			$pagetitle = $page->title->getLanguageValue($portuguese);
		}
		if (!$pagetitle) {
			$japanese = $languages->get("japanese");
			$page->setOutputFormatting(false);
			$pagetitle = $page->title->getLanguageValue($japanese);
		}
		if (!$pagetitle) {
			$french = $languages->get("french");
			$page->setOutputFormatting(false);
			$pagetitle = $page->title->getLanguageValue($french);
		}
		if (!$pagetitle) {
			$russian = $languages->get("russian");
			$page->setOutputFormatting(false);
			$pagetitle = $page->title->getLanguageValue($russian);
		}
		if (!$pagetitle) {
			$pagetitle = "E00.000.0";
		}

		$page->set("title", $pagetitle); 
		$page->save("title");
		$page->setOutputFormatting(true);
	}
  • 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...