bmacnaughton Posted June 11, 2017 Share Posted June 11, 2017 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. Link to comment Share on other sites More sharing options...
Peter Knight Posted June 11, 2017 Share Posted June 11, 2017 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 More sharing options...
kixe Posted June 12, 2017 Share Posted June 12, 2017 if ($fields->get('myfield')->type instanceof FieldtypeLanguageInterface) { // do something } 'myfield' can be the fieldname or field-id 3 Link to comment Share on other sites More sharing options...
Peter Knight Posted June 12, 2017 Share Posted June 12, 2017 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."; Link to comment Share on other sites More sharing options...
bmacnaughton Posted June 12, 2017 Author Share Posted June 12, 2017 On 6/12/2017 at 4:03 AM, kixe said: if ($fields->get('myfield')->type instanceof FieldtypeLanguageInterface) Expand Perfect - thank you. 1 Link to comment Share on other sites More sharing options...
bmacnaughton Posted June 12, 2017 Author Share Posted June 12, 2017 On 6/12/2017 at 6:27 AM, 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."; Expand 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 More sharing options...
tpr Posted June 14, 2018 Share Posted June 14, 2018 On 6/12/2017 at 4:03 AM, kixe said: if ($fields->get('myfield')->type instanceof FieldtypeLanguageInterface) { // do something } Expand 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 } 3 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now