Jump to content

get-selector on WireArray with fallback


owzim
 Share

Recommended Posts

Hi,

I want to get one item of a WireArray with a certain type or a fallback type.

$wireArray->get('type=one|two');

Unfortunately if the array has items of type one AND two, a type two item is returned, but I only want type two as a fallback. I basically want  the same behavior like on WireData objects.

$wireData->get('headline|title');

does correctly return the headline field, even if a title field exists.

Am I missing something?

Note: I really want it as ONE selector string, I know I could do multiple and check for null, but I don't want that.

Link to comment
Share on other sites

WireData::get simply explodes given string from "|", iterates found keys, and compares them one by one to existing items. In the case of WireArray::get the argument is used as an actual selector string, which means that in your first example there you're asking for all items with type "one" or "two", and the rest depends on sort settings.

You might be able to use "sort" to do what you're describing here, though it really depends on your actual use case :)

  • Like 1
Link to comment
Share on other sites

Thanks, I already use sorting, but this is not reliable enough, since I would have to make sure that that items with type one come before items with type two. And if I want to, for whatever reason make two the prio type and one the fallback else where I would have to resort.

Is there another way to mimic the WireData behavior?

Hmm, I might just as well wrap the additional logic I wanted to prevent in a method and hook it into WireArray and be done with it :)

  • Like 1
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...