Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Fields/Values.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ public function toArray()
{
return $this->getProxiedInstance()->toArray();
}

public function all()
{
return $this->getProxiedInstance()->all();
}
}
9 changes: 8 additions & 1 deletion src/Modifiers/Modify.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ArrayIterator;
use Exception;
use Statamic\Fields\Values;
use Statamic\Support\Arr;

class Modify implements \IteratorAggregate
Expand Down Expand Up @@ -189,6 +190,12 @@ protected function runModifier($modifier, $params)
{
[$class, $method] = $this->loader->load($modifier);

return $class->$method($this->value, $params, $this->context);
$value = $this->value;

if ($value instanceof Values) {
$value = $value->all();
}

return $class->$method($value, $params, $this->context);
}
}
8 changes: 8 additions & 0 deletions tests/Fields/ValuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ public function collection_is_not_converted()
$this->assertEquals(['foo' => 'bar'], $collection->all());
}

/** @test */
public function it_can_get_itself_as_an_array()
{
$values = new Values(collect(['foo' => 'bar']));

$this->assertEquals(['foo' => 'bar'], $values->all());
}

/** @test */
public function its_arrayable()
{
Expand Down
30 changes: 30 additions & 0 deletions tests/Modifiers/FluentModifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Tests\Modifiers;

use Statamic\Fields\Values;
use Statamic\Modifiers\Modifier;
use Statamic\Modifiers\Modify;
use Tests\TestCase;

Expand All @@ -24,4 +26,32 @@ public function it_can_explicitly_fetch_result()
$this->assertTrue(is_string($result));
$this->assertEquals("I LOVE NACHO LIBRE, IT'S THE BESSS!!!", $result);
}

/** @test */
public function passing_a_values_instance_into_it_will_not_convert_it_to_an_array()
{
$values = new Values(['foo' => 'bar']);

$result = Modify::value($values)->fetch();

$this->assertSame($values, $result);
}

/** @test */
public function values_instances_get_converted_to_an_array_when_passing_to_a_modifier()
{
(new class extends Modifier
{
public static $handle = 'to_values';

public function index($value)
{
return new Values($value);
}
})::register();

$result = Modify::value(['foo' => 'bar'])->toValues()->typeOf()->fetch();

$this->assertEquals('array', $result);
}
}