code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function delete(mixed $item, ?FieldsContract $fields = null): bool { $item = $this->beforeDeleting($item); $fields ??= $this->getFormFields()->onlyFields(withApplyWrappers: true); $fields->fill($item->toArray(), $this->getCaster()->cast($item)); $relationDestroyer = static function (ModelRelationField $field) use ($item): void { $relationItems = $item->{$field->getRelationName()}; ! $field->isToOne() ?: $relationItems = collect([$relationItems]); $relationItems->each( static fn (mixed $relationItem): mixed => $field->afterDestroy($relationItem) ); }; $fields->each(function (FieldContract $field) use ($item, $relationDestroyer): void { if ($field instanceof ModelRelationField && $field instanceof HasOutsideSwitcherContract && ! $field->isOutsideComponent() && $this->isDeleteRelationships() ) { $relationDestroyer($field); } else { $field->afterDestroy($item); } }); if ($this->isDeleteRelationships()) { $this->getOutsideFields()->each($relationDestroyer); } return (bool) tap($item->delete(), fn (): mixed => $this->afterDeleted($item)); }
@param TData $item @param ?Fields $fields @throws Throwable
delete
php
moonshine-software/moonshine
src/Laravel/src/Resources/ModelResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Resources/ModelResource.php
MIT
public function save(mixed $item, ?FieldsContract $fields = null): mixed { $fields ??= $this->getFormFields()->onlyFields(withApplyWrappers: true); $fields->fill($item->toArray(), $this->getCaster()->cast($item)); try { $fields->each(static fn (FieldContract $field): mixed => $field->beforeApply($item)); if (! $item->exists) { $item = $this->beforeCreating($item); } if ($item->exists) { $item = $this->beforeUpdating($item); } $fields->withoutOutside() ->each(fn (FieldContract $field): mixed => $field->apply($this->fieldApply($field), $item)); if ($item->save()) { $this->isRecentlyCreated = $item->wasRecentlyCreated; $item = $this->afterSave($item, $fields); } } catch (QueryException $queryException) { throw new ResourceException($queryException->getMessage(), previous: $queryException); } $this->setItem($item); return $item; }
@param TData $item @param ?Fields $fields @return TData @throws ResourceException @throws Throwable
save
php
moonshine-software/moonshine
src/Laravel/src/Resources/ModelResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Resources/ModelResource.php
MIT
protected function afterSave(mixed $item, FieldsContract $fields): mixed { $wasRecentlyCreated = $this->isRecentlyCreated(); $fields->each(static fn (FieldContract $field): mixed => $field->afterApply($item)); if ($item->isDirty()) { $item->save(); } if ($wasRecentlyCreated) { $item = $this->afterCreated($item); } if (! $wasRecentlyCreated) { $item = $this->afterUpdated($item); } return $item; }
@param TData $item @param Fields $fields @return TData
afterSave
php
moonshine-software/moonshine
src/Laravel/src/Resources/ModelResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Resources/ModelResource.php
MIT
protected function rules($item): array { return [ 'name' => 'required', 'moonshine_user_role_id' => 'required', 'email' => [ 'sometimes', 'bail', 'required', 'email', Rule::unique('moonshine_users')->ignoreModel($item), ], 'avatar' => ['sometimes', 'nullable', 'image', 'mimes:jpeg,jpg,png,gif'], 'password' => $item->exists ? 'sometimes|nullable|min:6|required_with:password_repeat|same:password_repeat' : 'required|min:6|required_with:password_repeat|same:password_repeat', ]; }
@return array{name: array|string, moonshine_user_role_id: array|string, email: array|string, password: array|string}
rules
php
moonshine-software/moonshine
src/Laravel/src/Resources/MoonShineUserResource.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Resources/MoonShineUserResource.php
MIT
public function resolve(): array { $data = []; foreach ($this->core->getResources() as $resource) { $classAttributes = Attributes::for($resource)->get(); foreach ($classAttributes as $attribute) { $data[$resource::class][Attribute::TARGET_CLASS][$attribute->getName()] = $attribute->getArguments(); } $search = Attributes::for($resource, SearchUsingFullText::class)->method('search')->first(); if ($search !== null) { $data[$resource::class][Attribute::TARGET_METHOD][$search::class] = [ 'columns' => $search->columns, 'options' => $search->options, ]; } } foreach ($this->core->getPages() as $page) { $classAttributes = Attributes::for($page)->get(); foreach ($classAttributes as $attribute) { $data[$page::class][Attribute::TARGET_CLASS][$attribute->getName()] = $attribute->getArguments(); } } return $data; }
@return array<class-string, array<int, array<string, array>>>
resolve
php
moonshine-software/moonshine
src/Laravel/src/Support/CacheAttributes.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Support/CacheAttributes.php
MIT
public function resolve(?array $cached = null): array { return $this->generateMenu($cached ?? $this->toArray()); }
@param PSMenu|null $cached @return MenuElementContract[]
resolve
php
moonshine-software/moonshine
src/Laravel/src/Support/MenuAutoloader.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Support/MenuAutoloader.php
MIT
private function generateMenu(array $data): array { $menu = []; foreach ($data as $item) { if (isset($item['group'])) { $group = $item['group']; $menu[] = MenuGroup::make( $group['translatable'] ? __($group['label']) : $group['label'], $this->generateMenu($item['items']), $group['icon'], )->when($group['canSee'], fn (MenuGroup $ctx): MenuGroup => $ctx->canSee($this->canSee($group['class'], $group['canSee']))); continue; } $menu[] = $this->toMenuItem($item['filler'], $item['canSee']); } return $menu; }
@param PSMenu|list<PSMenuItem> $data @return list<MenuElementContract>
generateMenu
php
moonshine-software/moonshine
src/Laravel/src/Support/MenuAutoloader.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Support/MenuAutoloader.php
MIT
private function canSee(string|MenuFillerContract $filler, string $method): Closure { if (\is_string($filler)) { $filler = app($filler); } return static fn () => $filler->{$method}(); }
@param MenuFillerContract|class-string<MenuFillerContract> $filler
canSee
php
moonshine-software/moonshine
src/Laravel/src/Support/MenuAutoloader.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Support/MenuAutoloader.php
MIT
public function asyncSearch( ?string $column = null, ?Closure $searchQuery = null, ?Closure $formatted = null, ?string $associatedWith = null, int $limit = 15, ?string $url = null, ): static { $this->asyncSearch = true; $this->searchable = true; $this->asyncSearchColumn = $column; $this->asyncSearchCount = $limit; $this->asyncSearchQuery = $searchQuery; $this->asyncSearchValueCallback = $formatted ?? $this->getFormattedValueCallback(); $this->associatedWith = $associatedWith; $this->asyncUrl = $url; if ($this->associatedWith) { $this->customAttributes([ 'data-associated-with' => $this->getDotNestedToName($this->associatedWith), ]); } $this->valuesQuery = function (Builder $query) { if ($this->getRelatedModel()) { return $this->getRelation(); } return $query->whereRaw('1=0'); }; return $this; }
@param string|null $column @param ?Closure(Builder $query, RelationModelFieldRequest $request, string $term, FieldContract $field): static $searchQuery @param ?Closure(mixed $data, FieldContract $field): static $formatted
asyncSearch
php
moonshine-software/moonshine
src/Laravel/src/Traits/Fields/WithAsyncSearch.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Fields/WithAsyncSearch.php
MIT
public function associatedWith(string $column, ?Closure $searchQuery = null): static { $defaultQuery = static fn (Builder $query, Request $request) => $query->where($column, $request->input($column)); return $this->asyncSearch( searchQuery: \is_null($searchQuery) ? $defaultQuery : $searchQuery, associatedWith: $column, ); }
@param ?Closure(Builder $query, RelationModelFieldRequest $request, string $term, FieldContract $field): static $searchQuery
associatedWith
php
moonshine-software/moonshine
src/Laravel/src/Traits/Fields/WithAsyncSearch.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Fields/WithAsyncSearch.php
MIT
public function relatedLink(?string $linkRelation = null, Closure|bool|null $condition = null): static { $this->parentRelationName = $linkRelation; if (\is_null($condition)) { $this->isRelatedLink = true; return $this; } $this->isRelatedLink = $condition; return $this; }
@param (Closure(int $count, static $ctx): bool)|bool|null $condition
relatedLink
php
moonshine-software/moonshine
src/Laravel/src/Traits/Fields/WithRelatedLink.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Fields/WithRelatedLink.php
MIT
public function modifyRelatedLink(Closure $callback): static { $this->modifyRelatedLink = $callback; return $this; }
@param Closure(ActionButtonContract $button, bool $preview, static $ctx): ActionButtonContract $callback
modifyRelatedLink
php
moonshine-software/moonshine
src/Laravel/src/Traits/Fields/WithRelatedLink.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Fields/WithRelatedLink.php
MIT
public function getRoute( ?string $name = null, DataWrapperContract|int|string|null $key = null, array $query = [] ): string { $key = $key instanceof DataWrapperContract ? $key->getKey() : $key; return $this->getRouter()->to( $name, filled($key) ? array_merge(['resourceItem' => $key], $query) : $query ); }
@param DataWrapperContract<T>|int|string|null $key
getRoute
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceCrudRouter.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceCrudRouter.php
MIT
public function getPageUrl(string|PageContract $page, array $params = [], null|string|array $fragment = null): string { return $this->getRouter()->getEndpoints()->toPage($page, $this, params: $params, extra: [ 'fragment' => $fragment, ]); }
@param class-string<PageContract>|PageContract $page @param array<string, mixed> $params
getPageUrl
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceCrudRouter.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceCrudRouter.php
MIT
public function getFragmentLoadUrl( string|array $fragment, ?PageContract $page = null, DataWrapperContract|int|string|null $key = null, array $params = [] ): string { if (\is_null($page)) { $page = $this->getIndexPage(); } return $this->getPageUrl( $page, params: array_filter([ ...$params, ...['resourceItem' => $key instanceof DataWrapperContract ? $key->getKey() : $key], ], static fn ($value) => filled($value)), fragment: $fragment ); }
@param DataWrapperContract<T>|int|string|null $key
getFragmentLoadUrl
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceCrudRouter.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceCrudRouter.php
MIT
protected function queryTags(): array { return []; }
Get an array of custom form actions @return list<QueryTag>
queryTags
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceModelQuery.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceModelQuery.php
MIT
public function setQueryParams(iterable $params): static { $this->queryParams = $params; return $this; }
to specify data from a request in console mode
setQueryParams
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceQuery.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceQuery.php
MIT
protected function rules(mixed $item): array { return []; }
Get an array of validation rules for resource related model @param T $item @return array<string, string[]|string> @see https://laravel.com/docs/validation#available-validation-rules
rules
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceValidation.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceValidation.php
MIT
public function validationMessages(): array { return []; }
Get custom messages for validator errors @return array<string, string[]|string>
validationMessages
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceValidation.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceValidation.php
MIT
protected function indexButtons(): ListOf { return new ListOf(ActionButtonContract::class, [ $this->getDetailButton(), $this->getEditButton( isAsync: $this->isAsync() ), $this->getDeleteButton( redirectAfterDelete: $this->getRedirectAfterDelete(), isAsync: $this->isAsync() ), $this->getMassDeleteButton( redirectAfterDelete: $this->getRedirectAfterDelete(), isAsync: $this->isAsync() ), ]); }
TableBuilder row buttons @return ListOf<ActionButtonContract>
indexButtons
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceWithButtons.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceWithButtons.php
MIT
protected function formButtons(): ListOf { return new ListOf(ActionButtonContract::class, [ $this->getDetailButton(), $this->getDeleteButton( redirectAfterDelete: $this->getRedirectAfterDelete(), isAsync: false ), ]); }
Top form buttons @return ListOf<ActionButtonContract>
formButtons
php
moonshine-software/moonshine
src/Laravel/src/Traits/Resource/ResourceWithButtons.php
https://github.com/moonshine-software/moonshine/blob/master/src/Laravel/src/Traits/Resource/ResourceWithButtons.php
MIT
public function whenActive(Closure $when): static { $this->whenActive = $when; return $this; }
@param Closure(string $path, string $host, static $ctx): bool $when
whenActive
php
moonshine-software/moonshine
src/MenuManager/src/MenuItem.php
https://github.com/moonshine-software/moonshine/blob/master/src/MenuManager/src/MenuItem.php
MIT
public function selectors(array $data): static { if (array_filter($data) === []) { return $this; } $this->data['selectors'] = $this->transform($data); return $this; }
@param array<non-empty-string, scalar> $data
selectors
php
moonshine-software/moonshine
src/Support/src/EventParams.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/EventParams.php
MIT
public function fieldsValues(array $data): static { if (array_filter($data) === []) { return $this; } $this->data['fields_values'] = $this->transform($data); return $this; }
@param array<non-empty-string, scalar> $data
fieldsValues
php
moonshine-software/moonshine
src/Support/src/EventParams.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/EventParams.php
MIT
private function transform(array $data): string { return implode( '|', array_map( static fn (string $key, mixed $value): string => \is_scalar($value) ? "$key{->}$value" : throw new InvalidArgumentException('Only scalar values allowed'), array_keys($data), $data, ), ); }
@param array<non-empty-string, mixed> $data @return non-empty-string
transform
php
moonshine-software/moonshine
src/Support/src/EventParams.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/EventParams.php
MIT
function memoize(callable $callback): mixed { $trace = debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, 2 ); $backtrace = new Backtrace($trace); if ($backtrace->getFunctionName() === 'eval') { return $callback(); } $object = $backtrace->getObject(); $hash = $backtrace->getHash(); $cache = MemoizeRepository::getInstance(); if (\is_string($object)) { $object = $cache; } if (! $cache->isEnabled()) { return $callback($backtrace->getArguments()); } if (! $cache->has($object, $hash)) { $result = $callback($backtrace->getArguments()); $cache->set($object, $hash, $result); } return $cache->get($object, $hash); }
@template T @param (callable(): T | callable(array): T) $callback @return T
memoize
php
moonshine-software/moonshine
src/Support/src/helpers.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/helpers.php
MIT
public function except(object|string ...$data): self { $condition = static fn (object $item): bool => collect($data)->every( fn (object|string $i): bool => match (true) { \is_string($i) => $item::class !== $i, \is_callable($i) => ! $i($item), default => $i !== $item, } ); $this->items = collect($this->items) ->filter($condition) ->toArray(); return $this; }
@param object|class-string<T> ...$data @return ListOf<T>
except
php
moonshine-software/moonshine
src/Support/src/ListOf.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/ListOf.php
MIT
public function only(object|string ...$data): self { $condition = static fn (object $item): bool => collect($data)->contains( fn (object|string $i): bool => match (true) { \is_string($i) => $item::class === $i, \is_callable($i) => $i($item), default => $i === $item, } ); $this->items = collect($this->items) ->filter($condition) ->toArray(); return $this; }
@param object|class-string<T> ...$data @return ListOf<T>
only
php
moonshine-software/moonshine
src/Support/src/ListOf.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/ListOf.php
MIT
public function __construct( private array $values = [], private mixed $value = null, private array|Closure $properties = [] ) { }
@param array<int|string,string|Option|OptionGroup|array<int|string,string>> $values @param mixed|null $value @param array<OptionProperty>|Closure $properties
__construct
php
moonshine-software/moonshine
src/Support/src/DTOs/Select/Options.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/DTOs/Select/Options.php
MIT
public function toRaw(): array { $values = $this->getValues(); $options = $values->mapWithKeys(function (Option|OptionGroup $option): array { if ($option instanceof OptionGroup) { return [$option->getLabel() => collect($option->getValues()->toArray())->pluck('label', 'value')->toArray()]; } return [$option->getValue() => $option->getLabel()]; })->toArray(); $properties = collect($this->flatten())->pluck('properties', 'value')->toArray(); return [ 'options' => $options, 'properties' => $properties, ]; }
@return array{options: array, properties: array}
toRaw
php
moonshine-software/moonshine
src/Support/src/DTOs/Select/Options.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/DTOs/Select/Options.php
MIT
private function normalizeProperties(array $properties): array { if (! isset($properties['image']) || $properties['image'] instanceof OptionImage) { return $properties; } $imageData = $properties['image']; if (\is_string($imageData)) { $properties['image'] = new OptionImage($imageData); return $properties; } $properties['image'] = new OptionImage( $imageData['src'] ?? '', $imageData['width'] ?? null, $imageData['height'] ?? null, isset($imageData['objectFit']) ? ObjectFit::from($imageData['objectFit']) : null ); return $properties; }
@param array{image: OptionImage} $properties @return array
normalizeProperties
php
moonshine-software/moonshine
src/Support/src/DTOs/Select/Options.php
https://github.com/moonshine-software/moonshine/blob/master/src/Support/src/DTOs/Select/Options.php
MIT
public function add(string $fieldClass, string $applyClass): static { $this->applies[$this->type][$this->getFor()][$fieldClass] = $applyClass; return $this; }
@param class-string<FormElementContract> $fieldClass @param class-string<ApplyContract> $applyClass
add
php
moonshine-software/moonshine
src/UI/src/Applies/AppliesRegister.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Applies/AppliesRegister.php
MIT
public function push(array $data): static { $this->applies[$this->type][$this->getFor()] = array_merge( $this->applies[$this->type][$this->getFor()] ?? [], $data, ); return $this; }
@param array<class-string<FormElementContract>, class-string<ApplyContract>> $data
push
php
moonshine-software/moonshine
src/UI/src/Applies/AppliesRegister.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Applies/AppliesRegister.php
MIT
protected function extractFields(iterable $elements, array &$data): void { foreach ($elements as $element) { if ($element instanceof FieldContract) { $data[] = $element; } elseif ($element instanceof HasFieldsContract && ! $element instanceof WithoutExtractionContract) { $this->extractFields($element->getFields(), $data); } elseif ($element instanceof HasComponentsContract && ! $element instanceof WithoutExtractionContract) { $this->extractFields($element->getComponents(), $data); } } }
@param FieldsContract|ComponentsContract|list<ComponentContract> $elements @param list<FieldContract> $data @throws Throwable
extractFields
php
moonshine-software/moonshine
src/UI/src/Collections/Fields.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Collections/Fields.php
MIT
public function unwrapElements(string $class, ?string $except = null): static { $modified = self::make(); $this->each( static function ($element) use ($class, $except, $modified): void { $isUnwrapped = $except !== null ? $element instanceof $class && ! $element instanceof $except : $element instanceof $class; if ($isUnwrapped) { $element->getFields()->onlyFields()->each( static fn ($inner): Collection => $modified->push($inner) ); } else { $modified->push($element); } } ); /** @var static */ /** @noRector */ return $modified; }
@param class-string $class @param class-string|null $except
unwrapElements
php
moonshine-software/moonshine
src/UI/src/Collections/Fields.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Collections/Fields.php
MIT
public function prepareReindexNames(?FieldContract $parent = null, ?callable $before = null, ?callable $performName = null, ?Closure $except = null): static { /** @var static */ return $this->map(static function (FieldContract $field) use ($parent, $before, $performName, $except): FieldContract { $modifyField = \is_null($before) ? $field : $before($parent, $field); if ($modifyField instanceof FieldContract) { $field = $modifyField; } $name = str($parent ? $parent->getNameDot() : $field->getNameDot()); $level = $name->substrCount('$'); if ($field instanceof ID) { $field->showValue(); } $ignore = $except instanceof Closure && $except($parent, $field) === true; if ($ignore) { $level--; } $name = $field->generateNameFrom( $name->value(), $ignore ? "" : "\${index$level}", $parent ? $field->getColumn() : null, ); $group = $field->getAttribute('multiple') || $field->isGroup(); if ($group) { $name .= '[]'; } if ($parent) { $field ->formName($parent->getFormName()) ->setParent($parent); } if ($parent && ! $field->hasWrapper()) { $field->customAttributes([ 'x-id' => "[`field-{$parent->getFormName()}`]", ]); } return $field ->setNameAttribute( \is_null($performName) ? $name : $performName($name, $parent, $field) ) ->iterableAttributes($level); }) ->prepareShowWhenNames(); }
@param ?callable(FieldContract $parent, FieldContract $field): FieldsContract $before @param ?callable(string, FieldContract $parent, FieldContract $field): string $performName @param ?Closure(FieldContract $parent, FieldContract $field): bool $except @throws Throwable
prepareReindexNames
php
moonshine-software/moonshine
src/UI/src/Collections/Fields.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Collections/Fields.php
MIT
public function extractLabels(): array { return $this->flatMap( static fn (FieldContract $field): array => [$field->getColumn() => $field->getLabel()] )->toArray(); }
@return array<string, string> @throws Throwable
extractLabels
php
moonshine-software/moonshine
src/UI/src/Collections/Fields.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Collections/Fields.php
MIT
protected function systemViewData(): array { return [ ...parent::systemViewData(), 'components' => $this->getComponents(), ]; }
@return array<string, mixed> @throws Throwable
systemViewData
php
moonshine-software/moonshine
src/UI/src/Components/AbstractWithComponents.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/AbstractWithComponents.php
MIT
public function setUrl(Closure|string $url): static { $this->url = $url; return $this; }
@param (Closure(mixed $original, ?DataWrapperContract $casted, static $ctx): string)|string $url
setUrl
php
moonshine-software/moonshine
src/UI/src/Components/ActionButton.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/ActionButton.php
MIT
public function onBeforeSet(Closure $onBeforeSet): static { $this->onBeforeSetCallback = $onBeforeSet; return $this; }
@param Closure(?DataWrapperContract $data, ActionButtonContract $ctx): ?DataWrapperContract $onBeforeSet
onBeforeSet
php
moonshine-software/moonshine
src/UI/src/Components/ActionButton.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/ActionButton.php
MIT
public function onAfterSet(Closure $onAfterSet): static { $this->onAfterSetCallback = $onAfterSet; return $this; }
@param Closure(?DataWrapperContract $data, ActionButtonContract $ctx): void $onAfterSet
onAfterSet
php
moonshine-software/moonshine
src/UI/src/Components/ActionButton.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/ActionButton.php
MIT
public function onClick(Closure $onClick, ?string $modifier = null): static { $event = 'x-on:click'; if (! \is_null($modifier)) { $event .= ".$modifier"; } $this->customAttributes([ $event => $onClick($this), ]); return $this; }
@param Closure(ActionButtonContract $ctx): string $onClick
onClick
php
moonshine-software/moonshine
src/UI/src/Components/ActionButton.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/ActionButton.php
MIT
public function method( string $method, array|Closure $params = [], ?string $message = null, null|string|array $selector = null, array $events = [], ?AsyncCallback $callback = null, ?PageContract $page = null, ?ResourceContract $resource = null, ): static { $this->asyncMethod = $method; $this->url = fn (mixed $data, ?DataWrapperContract $casted): string => $this->getCore()->getRouter()->getEndpoints()->method( method: $method, message: $message, params: array_filter([ 'resourceItem' => $casted?->getKey(), ...value($params, $casted?->getOriginal()), ], static fn ($value) => filled($value)), page: $page, resource: $resource, ); return $this->async( selector: $selector, events: $events, callback: $callback, ); }
@param array|(Closure(mixed $original): array) $params = [] @throws Throwable
method
php
moonshine-software/moonshine
src/UI/src/Components/ActionButton.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/ActionButton.php
MIT
public function setComponents(iterable $components): static { return $this; }
Blocked because only two components inside are allowed (Modal and OffCanvas)
setComponents
php
moonshine-software/moonshine
src/UI/src/Components/ActionButton.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/ActionButton.php
MIT
public function title(Closure|string $value): self { $this->title = $value; return $this; }
@param (Closure(mixed $data, int $index, self $ctx): string)|string $value
title
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function subtitle(Closure|string $value): self { $this->subtitle = $value; return $this; }
@param (Closure(mixed $data, int $index, self $ctx): string)|string $value
subtitle
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function thumbnail(Closure|string $value): self { $this->thumbnail = $value; return $this; }
@param (Closure(mixed $data, int $index, self $ctx): string)|string $value
thumbnail
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function url(Closure|string $value): self { $this->url = $value; return $this; }
@param (Closure(mixed $data, int $index, self $ctx): string)|string $value
url
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function content(Closure|string $value): self { $this->content = $value; return $this; }
@param (Closure(mixed $data, int $index, self $ctx): string)|string $value
content
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function header(Closure|string $value): self { $this->header = $value; return $this; }
@param (Closure(mixed $data, int $index, self $ctx): string)|string $value
header
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function componentAttributes(array|Closure $attributes): self { $this->componentAttributes = $attributes; return $this; }
@param (Closure(mixed $data, int $index, self $ctx): array)|array $attributes
componentAttributes
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function customComponent(Closure $component): self { $this->customComponent = $component; return $this; }
@param Closure(mixed $data, int $index, self $ctx): ComponentContract $component
customComponent
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
protected function viewData(): array { return [ 'components' => $this->getComponents(), 'name' => $this->getName(), 'hasPaginator' => $this->hasPaginator(), 'paginator' => $this->getPaginator( $this->isAsync() ), 'async' => $this->isAsync(), 'asyncUrl' => $this->getAsyncUrl(), 'colSpan' => $this->getColumnSpanValue(), 'adaptiveColSpan' => $this->getAdaptiveColumnSpanValue(), 'topLeft' => $this->getTopLeft(), 'topRight' => $this->getTopRight(), 'searchable' => $this->isSearchable(), 'searchValue' => $this->getCore()->getRequest()->getScalar('search', ''), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/UI/src/Components/CardsBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/CardsBuilder.php
MIT
public function mapFields(Closure $callback): self { $this->getComponents() ->onlyFields() ->map(static fn (FieldContract $field, int $index): FieldContract => $callback($field, $index)); return $this; }
@param Closure(FieldContract $field, int $index): FieldContract $callback @throws Throwable
mapFields
php
moonshine-software/moonshine
src/UI/src/Components/FieldsGroup.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/FieldsGroup.php
MIT
public function onBeforeFieldsRender(Closure $callback): self { $this->onBeforeFieldsRender = $callback; return $this; }
@param Closure(FieldsContract $fields, static $ctx): FieldsContract $callback
onBeforeFieldsRender
php
moonshine-software/moonshine
src/UI/src/Components/FormBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/FormBuilder.php
MIT
public function apply( Closure $apply, ?Closure $default = null, ?Closure $before = null, ?Closure $after = null, bool $throw = false, ): bool { $values = $this->castData( $this->getValues(), )->getOriginal(); if (\is_null($default)) { $default = static fn (FieldContract $field): Closure => static function (mixed $item) use ($field): mixed { if (! $field->hasRequestValue() && ! $field->getDefaultIfExists()) { return $item; } $value = $field->getRequestValue() !== false ? $field->getRequestValue() : null; data_set($item, $field->getColumn(), $value); return $item; }; } try { $fields = $this ->getPreparedFields() ->onlyFields(withApplyWrappers: true) ->exceptElements( fn (ComponentContract $element): bool => $element instanceof FieldContract && \in_array($element->getColumn(), $this->getExcludedFields(), true), ); $values = \is_null($before) ? $values : $before($values); $fields->each(static fn (FieldContract $field): mixed => $field->beforeApply($values)); $fields->each(static fn (FieldContract $field): mixed => $field->apply($default($field), $values)); $apply($values, $fields); $fields->each(static fn (FieldContract $field): mixed => $field->afterApply($values)); value($after, $values); } catch (Throwable $e) { if ($throw) { throw $e; } return false; } return true; }
@param Closure(mixed $values, FieldsContract $fields): bool $apply @param null|Closure(FieldContract $field): void $default @param null|Closure(mixed $values): mixed $before @param null|Closure(mixed $values): void $after @throws Throwable
apply
php
moonshine-software/moonshine
src/UI/src/Components/FormBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/FormBuilder.php
MIT
protected function viewData(): array { $fields = $this->getPreparedFields(); if ($this->hasAdditionalFields()) { $this->getAdditionalFields()->each(static fn ($field) => $fields->push($field)); } $onlyFields = $fields->onlyFields(); $onlyFields->each( fn (FieldContract $field): FieldContract => $field->formName($this->getName()), ); if (! $this->isRaw()) { $fields->prepend( Hidden::make('_component_name')->formName($this->getName())->setValue($this->getName()), ); } $reactiveFields = $onlyFields->reactiveFields() ->mapWithKeys(static fn (FieldContract $field): array => [$field->getColumn() => $field->getReactiveValue()]); $whenFields = []; $this->showWhenFields($onlyFields, $whenFields); $xData = json_encode([ 'whenFields' => $whenFields, 'reactiveUrl' => $reactiveFields->isNotEmpty() ? $this->getReactiveUrl() : '', ], JSON_THROW_ON_ERROR); $this->xDataMethod('formBuilder', $this->getName(), $xData, $reactiveFields->toJson()); $this->customAttributes([ 'data-component' => $this->getName(), ]); if ($this->isPrecognitive()) { $this->customAttributes([ 'x-on:submit.prevent' => 'precognition()', ]); } $this->customAttributes([ AlpineJs::eventBlade(JsEvent::FORM_RESET, $this->getName()) => 'formReset', AlpineJs::eventBlade(JsEvent::FORM_SUBMIT, $this->getName()) => 'submit', AlpineJs::eventBlade(JsEvent::SHOW_WHEN_REFRESH, $this->getName()) => 'whenFieldsInit', ]); if ($this->isAsync()) { $this->action( $this->getAction() ?: $this->getAsyncUrl(), ); $this->customAttributes([ 'x-on:submit.prevent' => 'async(`' . $this->getAsyncEvents( ) . '`, ' . json_encode($this->getAsyncCallback(), JSON_THROW_ON_ERROR) . ')', ]); } if (! \is_null($this->onBeforeFieldsRender)) { $fields = value($this->onBeforeFieldsRender, $fields, $this); } return [ 'fields' => $fields, 'precognitive' => $this->isPrecognitive(), 'async' => $this->isAsync(), 'asyncUrl' => $this->getAsyncUrl(), 'buttons' => $this->getButtons(), 'hideSubmit' => $this->isHideSubmit(), 'submit' => $this->getSubmit(), 'errors' => $this->getCore()->getRequest()->getFormErrors($this->getName()), 'errorsAbove' => $this->hasErrorsAbove(), 'raw' => $this->isRaw(), ]; }
@throws Throwable @return array<string, mixed> @throws JsonException
viewData
php
moonshine-software/moonshine
src/UI/src/Components/FormBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/FormBuilder.php
MIT
public function itemsResolver(Closure $resolver): static { $this->itemsResolver = $resolver; return $this; }
@param Closure(iterable $items, static $ctx): iterable $resolver
itemsResolver
php
moonshine-software/moonshine
src/UI/src/Components/IterableComponent.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/IterableComponent.php
MIT
protected function viewData(): array { $componentsHtml = $this->getComponents()->isNotEmpty() ? Components::make($this->getComponents()) : ''; $outer = value($this->outer, $this); if ($outer instanceof ActionButtonContract) { $outer->openModal(); } return [ 'isWide' => $this->wide, 'isOpen' => $this->open, 'isAuto' => $this->auto, 'isAutoClose' => $this->autoClose, 'isCloseOutside' => $this->closeOutside, 'async' => ! empty($this->asyncUrl), 'asyncUrl' => value($this->asyncUrl, $this) ?? '', 'title' => value($this->title, $this), 'slot' => new ComponentSlot(value($this->content, $this) . $componentsHtml), 'outerHtml' => new ComponentSlot($outer, $this->outerAttributes), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/UI/src/Components/Modal.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Modal.php
MIT
public function withAttributes(array $attributes): static { /** @phpstan-ignore-next-line */ $this->attributes = $this->attributes ?: $this->newAttributeBag(); $this->attributes->setAttributes( array_merge($this->attributes->jsonSerialize(), $attributes), ); return $this; }
@internal Method is called after rendering
withAttributes
php
moonshine-software/moonshine
src/UI/src/Components/MoonShineComponent.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/MoonShineComponent.php
MIT
protected function viewData(): array { /** @var Collection<array-key, Tab> $tabs */ $tabs = $this->getTabs(); return [ 'tabs' => $tabs ->filter(fn (Tab $tab): bool => $tab->isSee()) ->mapWithKeys(fn (Tab $tab) => [$tab->getId() => $tab->toArray()]) ->toArray(), 'active' => $this->getActive(), 'justifyAlign' => $this->getJustifyAlign(), 'isVertical' => $this->isVertical(), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/UI/src/Components/Tabs.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Tabs.php
MIT
public function customAssets(array $assets): self { $this->customAssets = $assets; return $this; }
@param array{ apple-touch: string, 32: string, 16: string, safari-pinned-tab: string, web-manifest: string, } $assets
customAssets
php
moonshine-software/moonshine
src/UI/src/Components/Layout/Favicon.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Layout/Favicon.php
MIT
public function trAttributes(Closure $callback): self { $this->trAttributes[] = $callback; return $this; }
@param Closure(?DataWrapperContract $data, int $row, self $table): array $callback
trAttributes
php
moonshine-software/moonshine
src/UI/src/Components/Table/TableBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Table/TableBuilder.php
MIT
public function tdAttributes(Closure $callback): self { $this->tdAttributes[] = $callback; return $this; }
@param Closure(?DataWrapperContract $data, int $row, int $cell, self $table): array $callback
tdAttributes
php
moonshine-software/moonshine
src/UI/src/Components/Table/TableBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Table/TableBuilder.php
MIT
public function rows(TableRowsContract|Closure $rows): self { $this->rows = $rows; return $this; }
@param TableRowsContract|Closure(TableRowsContract $default): TableRowsContract $rows
rows
php
moonshine-software/moonshine
src/UI/src/Components/Table/TableBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Table/TableBuilder.php
MIT
public function modifyRowCheckbox(Closure $callback): self { $this->modifyRowCheckbox = $callback; return $this; }
@param Closure(Checkbox $checkbox, DataWrapperContract $data, self $ctx): Checkbox $callback
modifyRowCheckbox
php
moonshine-software/moonshine
src/UI/src/Components/Table/TableBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Table/TableBuilder.php
MIT
public function headRows(TableRowsContract|Closure $rows): self { $this->headRows = $rows; return $this; }
@param TableRowsContract|Closure(TableRowContract $default): TableRowsContract $rows
headRows
php
moonshine-software/moonshine
src/UI/src/Components/Table/TableBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Table/TableBuilder.php
MIT
public function footRows(TableRowsContract|Closure $rows): self { $this->footRows = $rows; return $this; }
@param TableRowsContract|Closure(TableRowContract $default): TableRowsContract $rows
footRows
php
moonshine-software/moonshine
src/UI/src/Components/Table/TableBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Table/TableBuilder.php
MIT
protected function viewData(): array { $columns = $this->getFields()->onlyVisible()->flatMap( static fn (FieldContract $field): ?array => $field->isColumnSelection() ? [$field->getIdentity() => $field->getLabel()] : null, )->filter()->toArray(); return [ 'rows' => $this->getRows(), 'headRows' => $this->getHeadRows(), 'columns' => $columns, 'footRows' => $this->getFootRows(), 'name' => $this->getName(), 'hasPaginator' => $this->hasPaginator(), 'simple' => $this->isSimple(), 'paginator' => $this->getPaginator( $this->isAsync(), ), 'async' => $this->isAsync(), 'asyncUrl' => $this->getAsyncUrl(), 'createButton' => $this->creatableButton, 'headAttributes' => $this->headAttributes, 'bodyAttributes' => $this->bodyAttributes, 'footAttributes' => $this->footAttributes, 'topLeft' => $this->getTopLeft(), 'topRight' => $this->getTopRight($columns), ...$this->statesToArray(), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/UI/src/Components/Table/TableBuilder.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Components/Table/TableBuilder.php
MIT
public function changePreview(Closure $callback): static { $this->previewCallback = $callback; return $this; }
@param Closure(mixed $value, static $field): mixed $callback
changePreview
php
moonshine-software/moonshine
src/UI/src/Fields/Field.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Field.php
MIT
public function onChangeUrl( Closure $url, HttpMethod $method = HttpMethod::PUT, array $events = [], null|string|array $selector = null, ?AsyncCallback $callback = null, ): static { $this->onChangeUrl = $url; return $this->onChangeAttributes( method: $method, events: $events, selector: $selector, callback: $callback ); }
@param Closure(mixed $data, mixed $value, static $field): string $url @param string[] $events
onChangeUrl
php
moonshine-software/moonshine
src/UI/src/Fields/Field.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Field.php
MIT
public function beforeRender(Closure $callback): static { $this->beforeRender = $callback; return $this; }
@param Closure(static $ctx): mixed $callback
beforeRender
php
moonshine-software/moonshine
src/UI/src/Fields/Field.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Field.php
MIT
public function afterRender(Closure $callback): static { $this->afterRender = $callback; return $this; }
@param Closure(static $ctx): mixed $callback
afterRender
php
moonshine-software/moonshine
src/UI/src/Fields/Field.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Field.php
MIT
public function changeRender(Closure $callback): static { $this->renderCallback = $callback; return $this; }
@param Closure(mixed $value, static $ctx): string $callback
changeRender
php
moonshine-software/moonshine
src/UI/src/Fields/Field.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Field.php
MIT
public function __construct( Closure|string|null $label = null, ?string $column = null, ?Closure $formatted = null, ) { parent::__construct(); $this->attributes = new MoonShineComponentAttributeBag( $this->getPropertyAttributes()->toArray(), ); $this->wrapperAttributes = new MoonShineComponentAttributeBag(); $this->setLabel($label ?? $this->getLabel()); $this->setColumn( trim($column ?? str($this->getLabel())->lower()->snake()->value()), ); if (! \is_null($formatted)) { $this->setFormattedValueCallback($formatted); } }
@param (Closure(static $ctx): string)|string|null $label @param ?Closure(mixed $original, int $index, static $ctx): mixed $formatted
__construct
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public function getFormattedValueCallback(): ?Closure { return $this->formattedValueCallback; }
@return null|Closure(mixed $original, int $index, static $ctx): mixed
getFormattedValueCallback
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public function changeFill(Closure $callback): static { $this->fillCallback = $callback; return $this; }
@param Closure(mixed $data, static $field): mixed $callback
changeFill
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public function afterFill(Closure $callback): static { $this->afterFillCallback = $callback; return $this; }
@param Closure(static $ctx): static $callback
afterFill
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public function modifyRawValue(Closure $callback): static { $this->rawValueCallback = $callback; return $this; }
@param Closure(mixed $raw, mixed $original, static): mixed $callback
modifyRawValue
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public function fromRaw(Closure $callback): static { $this->fromRaw = $callback; return $this; }
@param Closure(mixed $raw, static): mixed $callback
fromRaw
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public static function requestValueResolver(Closure $resolver): void { static::$requestValueResolver = $resolver; }
@param Closure(string|int|null $index, mixed $default, static $ctx): mixed $resolver
requestValueResolver
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public function onRequestValue(Closure $callback): static { $this->onRequestValue = $callback; return $this; }
@param Closure(mixed $value, string $name, mixed $default, static $ctx): mixed $callback
onRequestValue
php
moonshine-software/moonshine
src/UI/src/Fields/FormElement.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/FormElement.php
MIT
public function modifyTable(Closure $callback): self { $this->modifyTable = $callback; return $this; }
@param Closure(TableBuilder $table, bool $preview): TableBuilder $callback
modifyTable
php
moonshine-software/moonshine
src/UI/src/Fields/Json.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Json.php
MIT
public function modifyRemoveButton(Closure $callback): self { $this->modifyRemoveButton = $callback; return $this; }
@param Closure(ActionButton $button, self $field): ActionButton $callback
modifyRemoveButton
php
moonshine-software/moonshine
src/UI/src/Fields/Json.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Json.php
MIT
public function modifyCreateButton(Closure $callback): self { $this->modifyCreateButton = $callback; return $this; }
@param Closure(ActionButton $button, self $field): ActionButton $callback
modifyCreateButton
php
moonshine-software/moonshine
src/UI/src/Fields/Json.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Json.php
MIT
protected function viewData(): array { return [ 'component' => $this->getComponent(), ]; }
@return array<string, mixed> @throws Throwable
viewData
php
moonshine-software/moonshine
src/UI/src/Fields/Json.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Fields/Json.php
MIT
public function whenAsync(Closure $callback): static { return $this->when( fn (): bool => $this->getCore()->getRequest()->getScalar('_component_name') === $this->getName(), fn () => $callback($this), ); }
@param Closure(static $ctx): static $callback
whenAsync
php
moonshine-software/moonshine
src/UI/src/Traits/HasAsync.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/HasAsync.php
MIT
public function getOptions(): array { return [ ...$this->options ?? $this->getCore()->getConfig()->getDiskOptions(), 'disk' => $this->getDisk(), ]; }
@return non-empty-array<string, string>
getOptions
php
moonshine-software/moonshine
src/UI/src/Traits/WithStorage.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/WithStorage.php
MIT
public function inModal( Closure|string|null $title = null, Closure|string|null $content = null, Closure|string|null $name = null, ?Closure $builder = null, iterable $components = [], ): static { if (\is_null($name)) { $name = fn (mixed $data, ActionButtonContract $ctx): string => spl_object_id($this) . $ctx->getData()?->getKey(); } $async = $this->purgeAsyncTap(); $this->modal = static fn (mixed $item, ?DataWrapperContract $data, ActionButtonContract $ctx) => Modal::make( title: static fn () => value($title, $item, $ctx) ?? $ctx->getLabel(), content: static fn () => value($content, $item, $ctx) ?? '', asyncUrl: $async ? static fn (): string => $ctx->getUrl($item) : null, components: $components ) ->name(value($name, $item, $ctx)) ->when( ! \is_null($builder), static fn (Modal $modal): Modal => $builder($modal, $ctx) ); return $this->onBeforeRender( static fn (ActionButtonContract $ctx): ActionButtonContract => $ctx->toggleModal( value($name, $ctx->getData()?->getOriginal(), $ctx) ) ); }
@param ?Closure(Modal $modal, ActionButtonContract $ctx): Modal $builder
inModal
php
moonshine-software/moonshine
src/UI/src/Traits/ActionButton/WithModal.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/ActionButton/WithModal.php
MIT
public function withConfirm( Closure|string|null $title = null, Closure|string|null $content = null, Closure|string|null $button = null, Closure|array|null $fields = null, HttpMethod $method = HttpMethod::POST, /** @var null|Closure(mixed): FormBuilderContract $formBuilder */ ?Closure $formBuilder = null, ?Closure $modalBuilder = null, Closure|string|null $name = null, ): static { $method = $this->asyncHttpMethod ?: $method; $events = $this->asyncEvents; $callback = $this->asyncCallback; $selector = $this->asyncSelector; $isDefaultMethods = \in_array($method, [HttpMethod::GET, HttpMethod::POST], true); $async = $this->purgeAsyncTap(); if ($this->isBulk()) { $this->customAttributes([ 'data-button-type' => 'modal-button', ]); } return $this->inModal( static fn (mixed $item, ActionButtonContract $ctx) => value($title, $item, $ctx) ?? $ctx->getCore()->getTranslator()->get('moonshine::ui.confirm'), static fn (mixed $item, ActionButtonContract $ctx): string => (string) FormBuilder::make( $ctx->getUrl($item), $isDefaultMethods ? FormMethod::from($method->value) : FormMethod::POST )->fields( array_filter([ $isDefaultMethods ? null : Hidden::make('_method')->setValue($method->value), $ctx->isBulk() ? HiddenIds::make($ctx->getBulkForComponent()) : null, ...(\is_null($fields) ? [] : value($fields, $item)), Heading::make( \is_null($content) ? $ctx->getCore()->getTranslator()->get('moonshine::ui.confirm_message') : value($content, $item) ), ]) )->when( ! \is_null($selector), static fn (FormBuilderContract $form): FormBuilderContract => $form->asyncSelector($selector) )->when( $async, static fn (FormBuilderContract $form): FormBuilderContract => $form->async(events: $events, callback: $callback) )->submit( button: ActionButton::make( \is_null($button) ? $ctx->getCore()->getTranslator()->get('moonshine::ui.confirm') : value($button, $item) )->error() )->when( ! \is_null($formBuilder), static fn (FormBuilderContract $form): FormBuilderContract => $formBuilder($form, $item) )->when( $ctx->getAttribute('data-async-response-type') !== null, static fn (FormBuilder $form): FormBuilder => $form->download() ), name: $name, builder: $modalBuilder ); }
@param ?Closure(FormBuilderContract $form, mixed $data): FormBuilderContract $formBuilder @param ?Closure(Modal $modal, ActionButtonContract $ctx): Modal $modalBuilder
withConfirm
php
moonshine-software/moonshine
src/UI/src/Traits/ActionButton/WithModal.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/ActionButton/WithModal.php
MIT
public function inOffCanvas( Closure|string|null $title = null, Closure|string|null $content = null, Closure|string|null $name = null, ?Closure $builder = null, iterable $components = [], ): static { if (\is_null($name)) { $name = fn (mixed $data, ActionButtonContract $ctx): string => spl_object_id($this) . $ctx->getData()?->getKey(); } $async = $this->purgeAsyncTap(); $this->offCanvas = static fn (mixed $item, ?DataWrapperContract $data, ActionButtonContract $ctx) => OffCanvas::make( title: static fn () => value($title, $item, $ctx) ?? $ctx->getLabel(), content: static fn () => value($content, $item, $ctx) ?? '', asyncUrl: $async ? $ctx->getUrl($item) : null, components: $components ) ->name(value($name, $item, $ctx)) ->when( ! \is_null($builder), static fn (OffCanvas $offCanvas) => $builder($offCanvas, $ctx) ); return $this->onBeforeRender( static fn (ActionButtonContract $ctx): ActionButtonContract => $ctx->toggleOffCanvas( value($name, $ctx->getData()?->getOriginal(), $ctx) ) ); }
@param ?Closure(OffCanvas $offCanvas, ActionButtonContract $ctx): OffCanvas $builder
inOffCanvas
php
moonshine-software/moonshine
src/UI/src/Traits/ActionButton/WithOffCanvas.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/ActionButton/WithOffCanvas.php
MIT
public function apply(Closure $default, mixed $data): mixed { if (! $this->isCanApply()) { return $data; } if (\is_null($this->onApply) && ! $this->isConsoleMode()) { $classApply = $this->getApplyClass(); $this->when( ! \is_null($classApply), static fn (FieldContract $field): FieldContract => $field->onApply($classApply->apply($field)) ); } $applyFunction = \is_null($this->onApply) ? $this->resolveOnApply() : $this->onApply; return \is_null($applyFunction) ? $default($data, $this->getRequestValue(), $this) : $applyFunction($data, $this->getRequestValue(), $this); }
@template D @param Closure(D $data, mixed $value, static $ctx): D $default @param D $data @return D
apply
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/Applies.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/Applies.php
MIT
public function onApply(Closure $onApply): static { $this->onApply = $onApply; return $this; }
@param Closure(mixed, mixed, FieldContract): mixed $onApply
onApply
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/Applies.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/Applies.php
MIT
public function onBeforeApply(Closure $onBeforeApply): static { $this->onBeforeApply = $onBeforeApply; return $this; }
@param Closure(mixed, mixed, FieldContract): static $onBeforeApply
onBeforeApply
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/Applies.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/Applies.php
MIT
public function onAfterApply(Closure $onAfterApply): static { $this->onAfterApply = $onAfterApply; return $this; }
@param Closure(mixed, mixed, FieldContract): static $onAfterApply
onAfterApply
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/Applies.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/Applies.php
MIT
public function onAfterDestroy(Closure $onAfterDestroy): static { $this->onAfterDestroy = $onAfterDestroy; return $this; }
@param Closure(mixed, mixed, FieldContract): static $onAfterDestroy
onAfterDestroy
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/Applies.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/Applies.php
MIT
public function reorderable(string|Closure $url, ?string $group = null): static { return $this->dropzoneAttributes(static function (FileableContract $ctx) use ($url, $group): array { $url = value($url, $ctx); return [ 'x-data' => "sortable(`$url`, `$group`)", 'data-handle' => '.dropzone-item', ]; }); }
@param string|Closure(static): string $url
reorderable
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/FileTrait.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
MIT
public function names(Closure $callback): static { $this->names = $callback; return $this; }
@param Closure(string $filename, int $index): string $callback
names
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/FileTrait.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
MIT
public function resolveNames(): Closure { return function (string $filename, int $index = 0): string { if (\is_null($this->names)) { return $filename; } return \call_user_func($this->names, $filename, $index); }; }
@return Closure(string, int, static): string
resolveNames
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/FileTrait.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
MIT
public function itemAttributes(Closure $callback): static { $this->itemAttributes = $callback; return $this; }
@param Closure(string $filename, int $index): array $callback
itemAttributes
php
moonshine-software/moonshine
src/UI/src/Traits/Fields/FileTrait.php
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
MIT