gebeer

Find all fields that are multi language

3 posts in this topic

Hello,

I would like to find all fields that are multi-language.

My code

$langFields = new FieldsArray;
foreach ($fields as $f) {
	if($f->type instanceof FieldtypePageTitleLanguage || $f->type instanceof FieldtypeTextareaLanguage || $f->type instanceof FieldtypeTextLanguage) {
		$langFields->add($f);
	}
}

Is there a more generic way of how I can determine whether a field is multi language, other than checking  "$f->type instanceof" for all three fieldtypes?

Share this post


Link to post
Share on other sites

Untested, but every multi language field class should implement FieldtypeLanguageInterface, which you should be able to check for using instanceof.

if($f->type instanceof FieldtypeLanguageInterface) $langFields->add($f);
2 people like this

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bmacnaughton
      I would like to be able to fetch the labels for fields in a language different than the current logged in user.
      For field values that's easy 
      // p is page, l is language, and f is field $p->getLanguageValue($l, $f); I'm looking for something like
      $fields->getLanguageValue('en', 'length'); The only solution I know of is to save the current user language, iterate through the languages by setting the user language and fetching the value, and then restore the user language.
       
    • By hellomoto
      I have a fieldsettab I want to populate with two collapsable fields that are for display not input. One will display data directly from an extra MySQL table (corresponding with PW pages) and the other will list certain PW pages. How do I go about this? I wanted to lay them out using Dynatable, one per each field. Thanks.
    • By Brian Scramlin
      Hey!
      Quick question, 
      Should I limit how many find() methods I use on a single page? Is it fairly resource-intensive?
      I am getting consistent 
      2006 MySQL server has gone away errors and have followed all the suggestions I can find, but wonder if I am just "overloading" my server resources with database requests or something like that?
      Thank you!
    • By nbcommunication
      Hi,
      I'm sure this is maybe in the works already, given that findMany() is a recent addition to the API, but having this (and the other new find options) available to $users would be a great addition.
      Cheers,
      Chris
      NB Communication
       
    • By neonwired
      I have a category template and each page can be associated with multiple categories using a page field type.
      i have this in php : - 
      $categories = $pages->find("template=category, limit=6"); I want to sort the results by the amount of pages each category has, is there a way to do this in a selector or is there a better way of doing this?