Jump to content

Programmatic way to determine if field is multi-language?


bmacnaughton
 Share

Recommended Posts

You mean via the API? 

I wanted the same thing over the weekend and found a post where Ryan provided some simple instructions. Don't have it to hand but will in the morning. It was something very simple along the lines of

if $language == 'french' ; echo {}

 

Link to comment
Share on other sites

4 hours ago, Peter Knight said:

I don't know if this answers your question but here's the post i mentioned

Essentially I just used this part


if($user->language->name == 'french') echo "and pdf_file is the French version.";

 

Thanks. I was trying to find out if a field was multiple language as opposed to there being language alternate fields. But I appreciate the link.

Link to comment
Share on other sites

  • 1 year later...
On 6/12/2017 at 6:03 AM, kixe said:

if ($fields->get('myfield')->type instanceof FieldtypeLanguageInterface) {
    // do something
}

 

To avoid the notice "Trying to get property 'type' of non-object" and possible issues later it's better to check wether the field is really a Field:

$f = $fields->get('myfield');

if ($f instanceof Field && $f->type instanceof FieldtypeLanguageInterface) {
    // do something
}

 

  • Like 3
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

×
×
  • Create New...