Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
darrencoutts118 committed Sep 10, 2024
1 parent 9c283a9 commit 1ed6590
Showing 1 changed file with 0 additions and 43 deletions.
43 changes: 0 additions & 43 deletions src/Components/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace AppKit\Formulate\Components;

use AppKit\Formulate\Facades\Formulate;
use Illuminate\Support\Str;
use Illuminate\View\Component;

class Field extends Component
Expand Down Expand Up @@ -73,48 +72,6 @@ public function __construct(
}
}

/**
* Set the extra attributes that the component should make available.
*
* @param array $attributes
* @return $this
*/
public function withAttributes(array $attributes): self
{
// make sure that we have an attribute bag setup for everything
$this->attributes = $this->attributes ?: $this->newAttributeBag();

// return the instance of the component
return $this;
}

/**
* Filter out a list of attributes based on the prefix
*
* @param array $attributes
* @param null|string $prefix
* @return array
*/
public function getPrefixedAttributes(array $attributes, ?string $prefix = null): array
{
// filter over a collection of attributes
return collect($attributes)->filter(function ($attributeValue, $attribute) use ($prefix) {
// special case if we are dealing with the null prefix
if (is_null($prefix)) {
// in which case, we want to check if the attribute contains any prefix separator
return !Str::of($attribute)->contains(':');
}

// pick this one if it starts with the correct prefix
return Str::of($attribute)->startsWith($prefix . ':');
})->mapWithKeys(function ($attributeValue, $attribute) use ($prefix) {
// strip the prefix off of the attribute name
$attribute = Str::of($attribute)->replace($prefix . ':', '')->__toString();

return [$attribute => $attributeValue];
})->toArray();
}

/**
* Get the default value for the given field
*
Expand Down

0 comments on commit 1ed6590

Please sign in to comment.