Skip to content

Commit

Permalink
🩹 fix: Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tombroucke committed Oct 14, 2024
1 parent 8bc2400 commit fa51e6b
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/AcfObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AcfObjects
* @param $postId mixed the post_id of which the value is saved against
* @param $formatValue boolean whether or not to format the value as described above
*/
public function getField(string $selector, mixed $postId = false, bool $formatValue = true): FieldContract|CollectionContract
public function getField(string $selector, mixed $postId = false, bool $formatValue = true): FieldContract|CollectionContract|bool
{
$postId = acf_get_valid_post_id($postId);
$field = acf_maybe_get_field($selector, $postId);
Expand Down
2 changes: 2 additions & 0 deletions src/Contracts/CollectionContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ interface CollectionContract
{
public function isEmpty();

public function getValue(): mixed;

public static function prepareData(mixed $data): mixed;
}
2 changes: 2 additions & 0 deletions src/Contracts/FieldContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ interface FieldContract
{
public function isSet(): bool;

public function getValue(): mixed;

public static function prepareData(mixed $data): mixed;
}
5 changes: 5 additions & 0 deletions src/Fields/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

abstract class Collection extends SupportCollection implements CollectionContract
{
public function getValue(): mixed
{
return $this->items;
}

public function default(mixed $value): CollectionContract
{
if ($this->isEmpty()) {
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/DatePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class DatePicker extends Carbon implements FieldContract
{
public function getValue(): mixed
{
return $this;
}

public function isSet(): bool
{
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/DateTimePicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

class DateTimePicker extends Carbon implements FieldContract
{
public function getValue(): mixed
{
return $this;
}

public function isSet(): bool
{
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ abstract class Field implements FieldContract
{
public function __construct(protected mixed $value) {}

public function getValue(): mixed
{
return $this->value;
}

public function isSet(): bool
{
return isset($this->value) && ! empty($this->value);
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ class Group extends Collection
{
public static function prepareData(mixed $data): mixed
{

if (is_bool($data) && ! $data) {
$data = [];
}

foreach ($data as $key => $value) {
if (is_object($value) && method_exists($value, 'isSet') && ! $value->isSet()) {
unset($data[$key]);
Expand Down
2 changes: 0 additions & 2 deletions src/Fields/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace Otomaties\AcfObjects\Fields;

use Otomaties\AcfObjects\Traits\Numeric;
use Otomaties\AcfObjects\Traits\Stringable;

class Select extends Field
{
use Stringable;
use Numeric;
}
5 changes: 0 additions & 5 deletions src/Fields/TrueFalse.php

This file was deleted.

6 changes: 6 additions & 0 deletions src/Providers/AcfObjectsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function register()
*/
$this->app->bind('acf-objects.field', function ($app, $parameters) {
extract($parameters);

if (! class_exists($className)) {
$className = FallbackField::class;
}
Expand Down Expand Up @@ -73,6 +74,11 @@ public function boot()
return $value;
}

$excludeTypes = ['true_false'];
if (in_array($field['type'], $excludeTypes)) {
return $value;
}

$fieldType = $field['type'] ?? 'FallbackField';
$className = 'Otomaties\AcfObjects\Fields\\'.Str::studly($fieldType);

Expand Down
1 change: 1 addition & 0 deletions src/Traits/FetchesArrayValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ trait FetchesArrayValues
public function __call(string $name, mixed $arguments): mixed
{
$snakeName = Str::snake($name);

if (! $this->value) {
return null;
}
Expand Down

0 comments on commit fa51e6b

Please sign in to comment.