Jump to content

[solved] WireArray::remove() doesn't seems to work


Recommended Posts

I'm working on a module that extends FieldtypeMulti, with the same way of storing data as FieldtypePagetable (field value is a WireArray).

I used without any issues WireArray->add(), WireArray->prepend() or WireArray->insertAfter() but WireArray->remove() doesn't seem to work.

Here is a minimal test case (tested in module init(), PW version 3.0.200)

$array = wire(new WireArray);
$array->add('Foo');
$array->add('Bar');
$array->add('Baz');

bd($array);
/**
 * ProcessWire\WireArray
 * count: 3
 * items: array
 * 0 => 'Foo'
 * 1 => 'Bar'
 * 2 => 'Baz'
*/

$array->remove('Foo');
// $newArray = $array->remove('Foo'); does the same...

bd($array);
/**
 * ProcessWire\WireArray
 * count: 3
 * items: array
 * 0 => 'Foo'
 * 1 => 'Bar'
 * 2 => 'Baz'
 */

I would expect the WireArray to remove the element and update the count. But alas, it's not doing anything.

Does anyone with an idea of what I don't understand here?

Thanks!

Link to comment
Share on other sites

remove() takes the key as argument, not the value. 

I'd wonder, if the WireArray is numerically indexed, would there be a way to use a selector to find the item to delete first? 

  • Like 2
Link to comment
Share on other sites

  • Studio Lambelet changed the title to [solved] WireArray::remove() doesn't seems to work

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...