Jump to content

Recommended Posts

Posted

Is there a way to tell if a field is a multi-language field?

I am currently checking to see if the last 8 characters are 'Language' but that seems like a fragile solution.

 

 

Posted

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 {}

 

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

'myfield' can be the fieldname or field-id

  • Like 3
Posted

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.";

 

Posted
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.

  • 1 year later...
Posted
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

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
×
×
  • Create New...