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

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 EyeDentify
      Hello There fellow PW gurus.

      I am trying to make a field show as open only if the field is filled out with at string.
      for example: "my_styles.css" and stay hidden if the field is empty.

      The field in question is of type "text" if that helps.

      And i put in the "show this field only if"
      css_filename!=''

      because the field name is "css_filename"

      But no mather what the field is closed because i have choosen it as "closed" as default.

      What am i doing wrong?

      i am running PW 3.0.83 Dev.
       


    • By celfred
      Hello,
      Still in my 'teaching game'. Here's my problem : I 'find' all players with a request like

      $allPlayers = $pages->find("template=player"); [/code Then, I limit to players belonging to the team of the logged in player with [code] $teamPlayers = $allPlayers->find("team=$loggedPlayer->team");
      No problem so far. But my scoreboards rely on either :

      $allPlayers->getItemKey($loggedPlayer);
      or

      $teamPlayers->getItemKey($loggedPlayer);
      to find the logged player's position in the charts.
      On the 'global' newboard with scoreboards based upon $allPlayers, everything works as expected.
      BUT on my 'team' newsboard, even though I'm using $teamPlayers, the returned indexes are based upon $allPlayers. Am I clear ? In other words, I have a total of 125 players, and my logged player is 61 out of 125 regarding the number of places he freed. But in his particular team of 25 players, he sould be 15 whereas he's still 61
      I'd like to reset my indexes (and start back from 0), but I can't find my way out of this...
      If someone has a hint to help, I'd appreciate.
      I have a second part in my worry : I had a way around it by simply making another 'raw' request :

      $teamPlayers = $pages->find("team=$loggedPlayer->team");
      Then my team indexes were right, but I faced another issue : Reordering my wirearray according to the scoreboard I want usually worked fine (simple sort() based upon an integer field, for example, player's coins, player's karma...) and indexes were updated BUT resorting with places.count ('places' field is a pageArray) doesn't update the indexes returned by getItemKey and my logged player is always at the position he was when I first did my initial $pages->find() query  
      So my way around found its limit and that's why I'm posting here, after struggling with this for a couple of hours...
      Thanks in advance for the help. 
    • By Vigilante
      I'm wondering about creating a query that involves looking across two different parent page trees.
      One parent is for blog posts and it has each post under that.
      Another parent is used for categories and subcategories for the blog.
      Then in the blogs there is a page field that can reference the categories. This is all pretty normal setup so far.
      I created a navigation that lists the current category and its children, but I want to not show categories that have no posts. For some reason I'm drawing a blank.
      So let's say a user clicks category1, and it shows a blog listing for that category. I query for all the child categories of the current one. Now I want to exclude any categories where NO blogs exist that make reference to the category (an unused category). How do I do this in a way that is performant? I don't want to have to query the blogs tree over and over to test for the presence of each category in the list!
      Here is the tree:
      blogs
       - article1  [pagefieldcat = "cat1"]
       - article2 [pagefieldcat = ""]
      categories
      - cat1
      - cat2
      Now when I get all children of categories, I want to exclude cat2 since it's not referenced from any blogs. Can I do this without having to loop and query every category against every blog one by one?
      Thanks
    • By bobbit6k
      Hi guys, 
       
      is there a way to declare numbers other than integer and float?
       
      My issue is that intgere is not enough for me because i'm dealing with multiple of bilions (let's say something like 111,532,372,567)
       
      Thanks,
       
      Rob
    • By zaib
      I'm fetching results from a template which works fine but when i change the language (in my case changed language is ARABIC), its showing me nothing
      $getResult = $pages->find("template=t3Cities_list, tags={$page->title}"); where "tags" are checkboxes with multi selection, How i can match the values?