Jump to content

How to check if the field is a MulitLang


workdreamer
 Share

Recommended Posts

I need a way when i am iterating the fields in some page, to check if the field is a multi lang value or not.

 

$data = [];
foreach ($page->template->fieldgroup as $field) {
    if (field support multi value) {
        continue;
    }
    $data[] = $field;
}
return $data;

 

How can i check that?

Thank you

Link to comment
Share on other sites

This seems to work

$implements = wireClassImplements($field->type);
$isMulti = in_array('FieldtypeLanguageInterface', $implements);

// OR
$isMulti = $field->type instanceof FieldtypeLanguageInterface;

Adapting to your code:

$data = [];
foreach ($page->template->fieldgroup as $field) {
    // check if field is multi language
    if ($field->type instanceof FieldtypeLanguageInterface) {
        continue;
    }
    $data[] = $field;
}
return $data;

 

  • Like 3
Link to comment
Share on other sites

@abdus Thank you very much for your feedback, but this is not working too

the result of the wireClassImplements is:

Array
(
    [ArrayAccess] => ArrayAccess
    [Traversable] => Traversable
    [IteratorAggregate] => IteratorAggregate
    [ProcessWire\WireTranslatable] => WireTranslatable
    [ProcessWire\WireFuelable] => WireFuelable
    [ProcessWire\WireTrackable] => WireTrackable
    [ProcessWire\Saveable] => Saveable
    [ProcessWire\Exportable] => Exportable
)

It doesnt show the language

 

Link to comment
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
 Share

×
×
  • Create New...