gebeer

Find all fields that are multi language

Recommended Posts

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);
  • Like 2

Share this post


Link to post
Share on other sites

@BitPoet

Thanks a lot. I just tested this and it brings the desired results.

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 dweeda
      How do I migrate a template with all its fields and values to a new site? Is their an export/import process?
    • By rareyush
      I am using module "FormTemplateProcessor" to get data in a pages but they all are unpublished and when I am trying to display them with relevent pages it not working
       
      page1 p1 p2 p3 page2 (FormTemplateProcessor) up1 (unpublished page and have p1 id on field knows as "ID") up2 (unpublished page and have p3 id on field knows as "ID") up3 (unpublished page and have p2 id on field knows as "ID") now here
      up1, ip2, up3 can be created by p1, p2 or p3 and I am saving respectively I'm saving their id in field which is being used by up1,up2,up3, etc template.
       
      now I want to show the data from unpublished pages which belongs to p1, p2 and p3 respectively
       
       
      anyone has experienced this or knows something which can help me out ?
    • By androbey
      Hi there, 

      I feel like I have another rather stupid question, but I am stucked in a problem. 
      I wrote a small module, which makes use of the multi-language option.

      The inputfield code looks like this:
      $donationText = $this->modules->InputfieldCKEditor; $donationText->useLanguages = true; $donationText->name = 'donationtext'; $donationText->label = 'Donation CTA Text'; $donationText->value = $this->donationtext; $donationText->required = true; $wrapper->add($donationText); My simplified render method in the module looks like this:
      public function renderDonationCTA(){ echo $this->donationtext; } However, when I call this method in my template code only the default language gets outputted.
      What did I miss or what can I do, in order to output the inserted text in the "right" language? 
    • By Eunico Cornelius
      I am trying to filter my $pages with a find($selector method). 
      $matches = $pages->find($selector); and this is an example of what my selector looks like
      $selector = "include=all, title|body~=$q, limit=50"; In this case, it only searches according to the matching exact words.
      For example:we search="art", the result="art times","these art",....
      Is there any way to search based on the alphabet?
      For example: we search="ab", the result="absolutely correct","abstract art",....
    • By Peter Knight
      A minor gripe but one that trips me up every time.
      When there's naming error on a field, ALL the field values are erased and I have to setup everything again. IE name, type, label and descriptions details and sometimes notes.
      Would be really helpful if ProcessWire didn't zap all the values but just cleared the illegal field name.