| null */ protected ?array $cachedItemsRawStateStructure = null; protected string | Closure | null $orderColumn = null; protected string | Closure | null $relationship = null; protected string | Htmlable | Closure | null $itemLabel = null; protected bool | Closure $hasItemNumbers = false; protected bool | Closure $hasItemHeaders = true; protected Field | Closure | null $simpleField = null; protected Alignment | string | Closure | null $addActionAlignment = null; protected ?Closure $modifyRelationshipQueryUsing = null; protected ?Closure $modifyRelationshipRecordsUsing = null; protected ?Closure $modifyAddActionUsing = null; protected ?Closure $modifyAddBetweenActionUsing = null; protected ?Closure $modifyCloneActionUsing = null; protected ?Closure $modifyDeleteActionUsing = null; protected ?Closure $modifyMoveDownActionUsing = null; protected ?Closure $modifyMoveUpActionUsing = null; protected ?Closure $modifyReorderActionUsing = null; protected ?Closure $modifyCollapseActionUsing = null; protected ?Closure $modifyExpandActionUsing = null; protected ?Closure $modifyCollapseAllActionUsing = null; protected ?Closure $modifyExpandAllActionUsing = null; protected ?Closure $mutateRelationshipDataBeforeCreateUsing = null; protected ?Closure $mutateRelationshipDataBeforeFillUsing = null; protected ?Closure $mutateRelationshipDataBeforeSaveUsing = null; protected ?Closure $afterCreate = null; protected ?Closure $afterUpdate = null; protected ?Closure $afterDelete = null; /** * @var array | null */ protected ?array $hydratedDefaultState = null; protected string | Closure | null $labelBetweenItems = null; protected bool | Closure $isItemLabelTruncated = true; protected ?Field $cachedSimpleField = null; /** * @var array | Closure | null */ protected array | Closure | null $tableColumns = null; protected bool $shouldMergeHydratedDefaultStateWithItemsStateAfterStateHydrated = true; protected bool | Closure | null $shouldPartiallyRenderAfterActionsCalled = null; protected function setUp(): void { parent::setUp(); $this->defaultItems(1); $this->afterStateHydrated(static function (Repeater $component): void { $component->hydrateItems(); }); $this->registerActions([ fn (Repeater $component): Action => $component->getAddAction(), fn (Repeater $component): Action => $component->getAddBetweenAction(), fn (Repeater $component): Action => $component->getCloneAction(), fn (Repeater $component): Action => $component->getCollapseAction(), fn (Repeater $component): Action => $component->getCollapseAllAction(), fn (Repeater $component): Action => $component->getDeleteAction(), fn (Repeater $component): Action => $component->getExpandAction(), fn (Repeater $component): Action => $component->getExpandAllAction(), fn (Repeater $component): Action => $component->getMoveDownAction(), fn (Repeater $component): Action => $component->getMoveUpAction(), fn (Repeater $component): Action => $component->getReorderAction(), ]); $this->mutateDehydratedStateUsing(static function (Repeater $component, ?array $state): array { return $component->dehydrateItems($state); }); } public function hydrateItems(): void { if ( is_array($this->hydratedDefaultState) && $this->shouldMergeHydratedDefaultStateWithItemsStateAfterStateHydrated ) { $this->mergeHydratedDefaultStateWithItemsState(); } if (is_array($this->hydratedDefaultState)) { return; } $items = []; $simpleField = $this->getSimpleField(); foreach ($this->getRawState() ?? [] as $itemData) { if ($simpleField) { $itemData = [$simpleField->getName() => $itemData]; } if ($uuid = $this->generateUuid()) { $items[$uuid] = $itemData; } else { $items[] = $itemData; } } $this->rawState($items); } /** * @param array> | null $state * @return array> */ public function dehydrateItems(?array $state): array { if ($simpleField = $this->getSimpleField()) { return collect($state ?? []) ->values() ->pluck($simpleField->getName()) ->all(); } return array_values($state ?? []); } public function getAddAction(): Action { $action = Action::make($this->getAddActionName()) ->label(fn (Repeater $component) => $component->getAddActionLabel()) ->color('gray') ->action(function (Repeater $component): void { $newUuid = $component->generateUuid(); $items = $component->getRawState(); if ($newUuid) { $items[$newUuid] = []; } else { $items[] = []; } $component->rawState($items); $component->getChildSchema($newUuid ?? array_key_last($items))->fill(); $component->collapsed(false, shouldMakeComponentCollapsible: false); $component->callAfterStateUpdated(); $component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null; }) ->button() ->size(Size::Small) ->visible(fn (Repeater $component): bool => $component->isAddable()); if ($this->modifyAddActionUsing) { $action = $this->evaluate($this->modifyAddActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function addActionAlignment(Alignment | string | Closure | null $addActionAlignment): static { $this->addActionAlignment = $addActionAlignment; return $this; } public function getAddActionAlignment(): Alignment | string | null { $alignment = $this->evaluate($this->addActionAlignment); if (is_string($alignment)) { $alignment = Alignment::tryFrom($alignment) ?? $alignment; } return $alignment; } public function addAction(?Closure $callback): static { $this->modifyAddActionUsing = $callback; return $this; } public function getAddActionName(): string { return 'add'; } public function getAddBetweenAction(): Action { $action = Action::make($this->getAddBetweenActionName()) ->label(fn (Repeater $component) => $component->getAddBetweenActionLabel()) ->color('gray') ->action(function (array $arguments, Repeater $component): void { $state = $component->getRawState() ?? []; if (! array_key_exists($arguments['afterItem'], $state)) { return; } $newKey = $component->generateUuid(); if (! $newKey) { $state[] = []; $newKey = array_key_last($state); unset($state[$newKey]); } $items = []; foreach ($state as $key => $item) { $items[$key] = $item; if ((string) $key === (string) $arguments['afterItem']) { $items[$newKey] = []; } } $component->rawState($items); $component->getChildSchema($newKey)->fill(); $component->collapsed(false, shouldMakeComponentCollapsible: false); $component->callAfterStateUpdated(); $component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null; }) ->button() ->size(Size::Small) ->visible(false); if ($this->modifyAddBetweenActionUsing) { $action = $this->evaluate($this->modifyAddBetweenActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function addBetweenAction(?Closure $callback): static { $this->modifyAddBetweenActionUsing = $callback; return $this; } public function getAddBetweenActionName(): string { return 'addBetween'; } public function addBetweenActionLabel(string | Closure | null $label): static { $this->addBetweenActionLabel = $label; return $this; } public function getAddBetweenActionLabel(): string { return $this->evaluate($this->addBetweenActionLabel) ?? __('filament-forms::components.repeater.actions.add_between.label'); } public function getCloneAction(): Action { $action = Action::make($this->getCloneActionName()) ->label(__('filament-forms::components.repeater.actions.clone.label')) ->icon(FilamentIcon::resolve(FormsIconAlias::COMPONENTS_REPEATER_ACTIONS_CLONE) ?? Heroicon::Square2Stack) ->color('gray') ->action(function (array $arguments, Repeater $component): void { $items = $component->getRawState() ?? []; if (! array_key_exists($arguments['item'], $items)) { return; } $newUuid = $component->generateUuid(); if ($newUuid) { $items[$newUuid] = $items[$arguments['item']]; } else { $items[] = $items[$arguments['item']]; } $component->rawState($items); $component->collapsed(false, shouldMakeComponentCollapsible: false); $component->callAfterStateUpdated(); $component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null; }) ->iconButton() ->size(Size::Small) ->visible(fn (Repeater $component): bool => $component->isCloneable()); if ($this->modifyCloneActionUsing) { $action = $this->evaluate($this->modifyCloneActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function cloneAction(?Closure $callback): static { $this->modifyCloneActionUsing = $callback; return $this; } public function getCloneActionName(): string { return 'clone'; } public function getDeleteAction(): Action { $action = Action::make($this->getDeleteActionName()) ->label(__('filament-forms::components.repeater.actions.delete.label')) ->icon(FilamentIcon::resolve(FormsIconAlias::COMPONENTS_REPEATER_ACTIONS_DELETE) ?? Heroicon::Trash) ->color('danger') ->action(function (array $arguments, Repeater $component): void { $items = $component->getRawState() ?? []; if (! array_key_exists($arguments['item'], $items)) { return; } unset($items[$arguments['item']]); $component->rawState($items); $component->callAfterStateUpdated(); $component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null; }) ->iconButton() ->size(Size::Small) ->visible(fn (Repeater $component): bool => $component->isDeletable()); if ($this->modifyDeleteActionUsing) { $action = $this->evaluate($this->modifyDeleteActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function deleteAction(?Closure $callback): static { $this->modifyDeleteActionUsing = $callback; return $this; } public function getDeleteActionName(): string { return 'delete'; } public function getMoveDownAction(): Action { $action = Action::make($this->getMoveDownActionName()) ->label(__('filament-forms::components.repeater.actions.move_down.label')) ->icon(FilamentIcon::resolve(FormsIconAlias::COMPONENTS_REPEATER_ACTIONS_MOVE_DOWN) ?? Heroicon::ArrowDown) ->color('gray') ->action(function (array $arguments, Repeater $component): void { $items = $component->getRawState() ?? []; if (! array_key_exists($arguments['item'], $items)) { return; } $items = array_move_after($items, $arguments['item']); $component->rawState($items); $component->callAfterStateUpdated(); $component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null; }) ->iconButton() ->size(Size::Small) ->visible(fn (Repeater $component): bool => $component->isReorderable()); if ($this->modifyMoveDownActionUsing) { $action = $this->evaluate($this->modifyMoveDownActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function moveDownAction(?Closure $callback): static { $this->modifyMoveDownActionUsing = $callback; return $this; } public function getMoveDownActionName(): string { return 'moveDown'; } public function getMoveUpAction(): Action { $action = Action::make($this->getMoveUpActionName()) ->label(__('filament-forms::components.repeater.actions.move_up.label')) ->icon(FilamentIcon::resolve(FormsIconAlias::COMPONENTS_REPEATER_ACTIONS_MOVE_UP) ?? Heroicon::ArrowUp) ->color('gray') ->action(function (array $arguments, Repeater $component): void { $items = $component->getRawState() ?? []; if (! array_key_exists($arguments['item'], $items)) { return; } $items = array_move_before($items, $arguments['item']); $component->rawState($items); $component->callAfterStateUpdated(); $component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null; }) ->iconButton() ->size(Size::Small) ->visible(fn (Repeater $component): bool => $component->isReorderable()); if ($this->modifyMoveUpActionUsing) { $action = $this->evaluate($this->modifyMoveUpActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function moveUpAction(?Closure $callback): static { $this->modifyMoveUpActionUsing = $callback; return $this; } public function getMoveUpActionName(): string { return 'moveUp'; } public function getReorderAction(): Action { $action = Action::make($this->getReorderActionName()) ->label(__('filament-forms::components.repeater.actions.reorder.label')) ->icon(FilamentIcon::resolve(FormsIconAlias::COMPONENTS_REPEATER_ACTIONS_REORDER) ?? Heroicon::ArrowsUpDown) ->color('gray') ->action(function (array $arguments, Repeater $component): void { $items = $component->getRawState() ?? []; $order = array_flip($arguments['items']); if (array_diff_key($order, $items)) { return; } $items = array_replace($order, $items); $component->rawState($items); $component->callAfterStateUpdated(); $component->shouldPartiallyRenderAfterActionsCalled() ? $component->partiallyRender() : null; }) ->livewireClickHandlerEnabled(false) ->iconButton() ->size(Size::Small) ->visible(fn (Repeater $component): bool => $component->isReorderableWithDragAndDrop()); if ($this->modifyReorderActionUsing) { $action = $this->evaluate($this->modifyReorderActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function reorderAction(?Closure $callback): static { $this->modifyReorderActionUsing = $callback; return $this; } public function getReorderActionName(): string { return 'reorder'; } public function getCollapseAction(): Action { $action = Action::make($this->getCollapseActionName()) ->label(__('filament-forms::components.repeater.actions.collapse.label')) ->icon(FilamentIcon::resolve(FormsIconAlias::COMPONENTS_REPEATER_ACTIONS_COLLAPSE) ?? Heroicon::ChevronUp) ->color('gray') ->livewireClickHandlerEnabled(false) ->iconButton() ->size(Size::Small); if ($this->modifyCollapseActionUsing) { $action = $this->evaluate($this->modifyCollapseActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function collapseAction(?Closure $callback): static { $this->modifyCollapseActionUsing = $callback; return $this; } public function getCollapseActionName(): string { return 'collapse'; } public function getExpandAction(): Action { $action = Action::make($this->getExpandActionName()) ->label(__('filament-forms::components.repeater.actions.expand.label')) ->icon(FilamentIcon::resolve(FormsIconAlias::COMPONENTS_REPEATER_ACTIONS_EXPAND) ?? Heroicon::ChevronDown) ->color('gray') ->livewireClickHandlerEnabled(false) ->iconButton() ->size(Size::Small); if ($this->modifyExpandActionUsing) { $action = $this->evaluate($this->modifyExpandActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function expandAction(?Closure $callback): static { $this->modifyExpandActionUsing = $callback; return $this; } public function getExpandActionName(): string { return 'expand'; } public function getCollapseAllAction(): Action { $action = Action::make($this->getCollapseAllActionName()) ->label(__('filament-forms::components.repeater.actions.collapse_all.label')) ->color('gray') ->livewireClickHandlerEnabled(false) ->link() ->size(Size::Small); if ($this->modifyCollapseAllActionUsing) { $action = $this->evaluate($this->modifyCollapseAllActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function collapseAllAction(?Closure $callback): static { $this->modifyCollapseAllActionUsing = $callback; return $this; } public function getCollapseAllActionName(): string { return 'collapseAll'; } public function getExpandAllAction(): Action { $action = Action::make($this->getExpandAllActionName()) ->label(__('filament-forms::components.repeater.actions.expand_all.label')) ->color('gray') ->livewireClickHandlerEnabled(false) ->link() ->size(Size::Small); if ($this->modifyExpandAllActionUsing) { $action = $this->evaluate($this->modifyExpandAllActionUsing, [ 'action' => $action, ]) ?? $action; } return $action; } public function expandAllAction(?Closure $callback): static { $this->modifyExpandAllActionUsing = $callback; return $this; } public function getExpandAllActionName(): string { return 'expandAll'; } public function addActionLabel(string | Closure | null $label): static { $this->addActionLabel = $label; return $this; } /** * @deprecated Use `addActionLabel()` instead. */ public function createItemButtonLabel(string | Closure | null $label): static { $this->addActionLabel($label); return $this; } public function labelBetweenItems(string | Closure | null $label): static { $this->labelBetweenItems = $label; return $this; } public function truncateItemLabel(bool | Closure $condition = true): static { $this->isItemLabelTruncated = $condition; return $this; } public function defaultItems(int | Closure $count): static { $this->default(static function (Repeater $component) use ($count): array { $count = $component->evaluate($count); if (! $count) { return []; } return array_fill(0, $count, $component->isSimple() ? null : []); }); $this->shouldMergeHydratedDefaultStateWithItemsStateAfterStateHydrated = false; return $this; } public function default(mixed $state): static { parent::default(function (Repeater $component) use ($state) { $state = $component->evaluate($state); $simpleField = $component->getSimpleField(); $items = []; foreach ($state ?? [] as $itemData) { if ($simpleField) { $itemData = [$simpleField->getName() => $itemData]; } if ($uuid = $component->generateUuid()) { $items[$uuid] = $itemData; } else { $items[] = $itemData; } } $component->hydratedDefaultState = $items; return $items; }); $this->shouldMergeHydratedDefaultStateWithItemsStateAfterStateHydrated = true; return $this; } public function addable(bool | Closure $condition = true): static { $this->isAddable = $condition; return $this; } public function deletable(bool | Closure $condition = true): static { $this->isDeletable = $condition; return $this; } public function reorderable(bool | Closure $condition = true): static { $this->isReorderable = $condition; return $this; } /** * @deprecated Use `addable()` instead. */ public function disableItemCreation(bool | Closure $condition = true): static { $this->addable(fn (Repeater $component): bool => ! $this->evaluate($condition)); return $this; } /** * @deprecated Use `deletable()` instead. */ public function disableItemDeletion(bool | Closure $condition = true): static { $this->deletable(fn (Repeater $component): bool => ! $this->evaluate($condition)); return $this; } /** * @deprecated Use `reorderable()` instead. */ public function disableItemMovement(bool | Closure $condition = true): static { $this->reorderable(fn (Repeater $component): bool => ! $this->evaluate($condition)); return $this; } public function reorderableWithDragAndDrop(bool | Closure $condition = true): static { $this->isReorderableWithDragAndDrop = $condition; return $this; } public function reorderableWithButtons(bool | Closure $condition = true): static { $this->isReorderableWithButtons = $condition; return $this; } /** * @deprecated No longer part of the design system. */ public function inset(bool | Closure $condition = true): static { return $this; } /** * @return array */ public function getItems(): array { return $this->getCachedDefaultChildSchemas(); } /** * @return array */ public function getDefaultChildSchemas(): array { $rawState = ($this->getRawState() ?? []); $this->cachedItemsRawStateStructure = array_map(is_array(...), $rawState); $relationship = $this->getRelationship(); $records = $relationship ? $this->getCachedExistingRecords() : null; $items = []; foreach ($rawState as $itemKey => $itemData) { $items[$itemKey] = $this ->getChildSchema() ->statePath($itemKey) ->constantState(((! ($relationship && $records->has($itemKey))) && is_array($itemData)) ? $itemData : null) ->model($relationship ? $records[$itemKey] ?? $this->getRelatedModel() : null) ->inlineLabel(false) ->getClone(); } return $items; } /** * Item schemas only depend on the raw state's structure - the item keys, their * order, and whether each item holds an array - since fields inside the items * read their values from the live raw state. Comparing a structural fingerprint * instead of the item values keeps this check cheap when it runs often, and * avoids rebuilding the item schemas every time a value inside an item changes. * The existing records that relationship items embed are not observable through * the raw state, so `clearCachedExistingRecords()` clears the items explicitly. */ protected function areCachedDefaultChildSchemasFresh(): bool { return $this->cachedItemsRawStateStructure === array_map(is_array(...), $this->getRawState() ?? []); } protected function isCachedDefaultChildSchemaFresh(string | int $key): bool { $rawState = $this->getRawState(); return is_array($rawState) && array_key_exists($key, $rawState) && array_key_exists($key, $this->cachedItemsRawStateStructure ?? []) && ($this->cachedItemsRawStateStructure[$key] === is_array($rawState[$key])); } public function getAddActionLabel(): string { return $this->evaluate($this->addActionLabel) ?? __('filament-forms::components.repeater.actions.add.label', [ 'label' => Str::lcfirst($this->getLabel()), ]); } public function isReorderable(): bool { if ($this->isDisabled()) { return false; } return (bool) $this->evaluate($this->isReorderable); } public function isReorderableWithDragAndDrop(): bool { return $this->evaluate($this->isReorderableWithDragAndDrop) && $this->isReorderable(); } public function isReorderableWithButtons(): bool { return $this->evaluate($this->isReorderableWithButtons) && $this->isReorderable(); } public function isAddable(): bool { if ($this->isDisabled()) { return false; } if (filled($this->getMaxItems()) && ($this->getMaxItems() <= $this->getItemsCount())) { return false; } return (bool) $this->evaluate($this->isAddable); } public function isDeletable(): bool { if ($this->isDisabled()) { return false; } return (bool) $this->evaluate($this->isDeletable); } public function orderColumn(string | Closure | null $column = 'sort'): static { $this->orderColumn = $column; $this->reorderable($column); return $this; } /** * @deprecated Use `orderColumn()` instead. */ public function orderable(string | Closure | null $column = 'sort'): static { $this->orderColumn($column); return $this; } public function relationship(string | Closure | null $name = null, ?Closure $modifyQueryUsing = null, ?Closure $modifyRecordsUsing = null): static { $this->relationship = $name ?? $this->getName(); $this->modifyRelationshipQueryUsing = $modifyQueryUsing; $this->modifyRelationshipRecordsUsing = $modifyRecordsUsing; $this->afterStateHydrated(static function (Repeater $component): void { if (! is_array($component->hydratedDefaultState)) { return; } $component->mergeHydratedDefaultStateWithItemsState(); }); $this->loadStateFromRelationshipsUsing(static function (Repeater $component): void { $component->clearCachedExistingRecords(); $component->fillFromRelationship(); }); $this->saveRelationshipsUsing(static function (Repeater $component): void { $component->saveToRelationship(); }); $this->dehydrated(false); $this->reorderable(false); return $this; } public function saveToRelationship(): void { $state = $this->getState(); if (! is_array($state)) { $state = []; } $relationship = $this->getRelationship(); $existingRecords = $this->getCachedExistingRecords(); $recordsToDelete = []; foreach ($existingRecords->pluck($relationship->getRelated()->getKeyName()) as $keyToCheckForDeletion) { if (array_key_exists("record-{$keyToCheckForDeletion}", $state)) { continue; } $recordsToDelete[] = $keyToCheckForDeletion; $existingRecords->forget("record-{$keyToCheckForDeletion}"); } if (filled($recordsToDelete)) { $relationship ->whereKey($recordsToDelete) ->get() ->each(function (Model $record): void { $record->delete(); $this->callAfterDelete($record); }); } $itemOrder = 1; $orderColumn = $this->getOrderColumn(); $translatableContentDriver = $this->getLivewire()->makeFilamentTranslatableContentDriver(); foreach ($this->getItems() as $itemKey => $item) { $itemData = $item->getState(shouldCallHooksBefore: false); if ($orderColumn) { $itemData[$orderColumn] = $itemOrder; $itemOrder++; } if ($record = ($existingRecords[$itemKey] ?? null)) { $itemData = $this->mutateRelationshipDataBeforeSave($itemData, record: $record); if ($itemData === null) { continue; } $translatableContentDriver ? $translatableContentDriver->updateRecord($record, $itemData) : $record->fill($itemData)->save(); $this->callAfterUpdate($itemData, $record); continue; } $relatedModel = $this->getRelatedModel(); $itemData = $this->mutateRelationshipDataBeforeCreate($itemData); if ($itemData === null) { continue; } if ($translatableContentDriver) { $record = $translatableContentDriver->makeRecord($relatedModel, $itemData); } else { $record = new $relatedModel; $record->fill($itemData); } $record = $relationship->save($record); $item->model($record)->saveRelationships(); $this->callAfterCreate($itemData, $record); $existingRecords->push($record); } $this->getRecord()->setRelation($this->getRelationshipName(), $existingRecords); } /** * After hydrating the state of child component containers, the default state * of fields inside the repeater can be lost, if it was defined on the repeater * itself. This method merges the hydrated default state with the state of the * child component containers, so that the default state of the fields inside * the repeater is preserved. */ protected function mergeHydratedDefaultStateWithItemsState(): void { $state = $this->getRawState(); $items = $this->hydratedDefaultState; foreach ($items as $itemKey => $itemData) { $items[$itemKey] = [ ...$state[$itemKey] ?? [], ...$itemData, ]; } $this->rawState($items); } public function itemLabel(string | Htmlable | Closure | null $label): static { $this->itemLabel = $label; return $this; } public function itemNumbers(bool | Closure $condition = true): static { $this->hasItemNumbers = $condition; return $this; } public function itemHeaders(bool | Closure $condition = true): static { $this->hasItemHeaders = $condition; return $this; } public function fillFromRelationship(): void { $this->state( $this->getStateFromRelatedRecords($this->getCachedExistingRecords()), ); } /** * @return array> */ protected function getStateFromRelatedRecords(Collection $records): array { if (! $records->count()) { return []; } $translatableContentDriver = $this->getLivewire()->makeFilamentTranslatableContentDriver(); return $records ->map(function (Model $record) use ($translatableContentDriver): array { $data = $translatableContentDriver ? $translatableContentDriver->getRecordAttributesToArray($record) : $record->attributesToArray(); return $this->mutateRelationshipDataBeforeFill($data); }) ->toArray(); } public function getLabel(): string | Htmlable | null { if ($this->label === null && $this->hasRelationship()) { $label = (string) str($this->getRelationshipName()) ->before('.') ->kebab() ->replace(['-', '_'], ' ') ->ucfirst(); return ($this->shouldTranslateLabel) ? __($label) : $label; } return parent::getLabel(); } public function getOrderColumn(): ?string { return $this->evaluate($this->orderColumn); } public function getRelationship(): HasOneOrMany | BelongsToMany | null { if (! $this->hasRelationship()) { return null; } $record = $this->getModelInstance(); $relationshipName = $this->getRelationshipName(); if ($record->hasAttribute($relationshipName) || (! $record->isRelation($relationshipName))) { throw new LogicException("The relationship [{$relationshipName}] does not exist on the model [{$this->getModel()}]."); } return $this->getModelInstance()->{$relationshipName}(); } public function getRelationshipName(): ?string { return $this->evaluate($this->relationship); } protected function modifyRelationshipRecords(Collection $records): Collection { return $this->evaluate( $this->modifyRelationshipRecordsUsing, namedInjections: [ 'records' => $records, ], typedInjections: [ Collection::class => $records, ], ) ?? $records; } public function getCachedExistingRecords(): Collection { if ($this->cachedExistingRecords) { return $this->cachedExistingRecords; } if (! $this->getModelInstance()?->exists) { return $this->cachedExistingRecords = new Collection; } $relationship = $this->getRelationship(); $relatedKeyName = $relationship->getRelated()->getKeyName(); $relationshipName = $this->getRelationshipName(); $orderColumn = $this->getOrderColumn(); if ( $this->getModelInstance()->relationLoaded($relationshipName) && (! $this->modifyRelationshipQueryUsing) ) { return $this->cachedExistingRecords = $this->modifyRelationshipRecords($this->getRecord()->getRelationValue($relationshipName) ->when(filled($orderColumn), fn (Collection $records) => $records->sortBy($orderColumn)) ->mapWithKeys( fn (Model $item): array => ["record-{$item[$relatedKeyName]}" => $item], )); } $relationshipQuery = $relationship->getQuery(); // Explicitly select the related table's columns so the query is not ambiguous if it is // later modified to include a join (for example, through `modifyRelationshipQueryUsing()`). // Without this, `select *` across a join can hydrate the key from the wrong table. if ($relationship instanceof BelongsToMany) { $relationshipQuery->select([ $relationship->getTable() . '.*', $relationshipQuery->getModel()->getTable() . '.*', ]); } else { $relationshipQuery->select($relationshipQuery->getModel()->getTable() . '.*'); } if ($this->modifyRelationshipQueryUsing) { $relationshipQuery = $this->evaluate($this->modifyRelationshipQueryUsing, [ 'query' => $relationshipQuery, ]) ?? $relationshipQuery; } if (filled($orderColumn)) { // Qualify the order column so it is not ambiguous when the query includes a join. $relationshipQuery->orderBy($relationshipQuery->qualifyColumn($orderColumn)); } return $this->cachedExistingRecords = $this->modifyRelationshipRecords($relationshipQuery->get()->mapWithKeys( fn (Model $item): array => ["record-{$item[$relatedKeyName]}" => $item], )); } public function getItemLabel(string $key, ?int $index = null): string | Htmlable | null { $container = null; $getContainer = function () use ($key, &$container): ?Schema { return $container ??= $this->getChildSchema($key); }; return $this->evaluate($this->itemLabel, [ 'container' => $getContainer, 'item' => $getContainer, 'key' => $key, 'schema' => $getContainer, 'state' => static fn (): array => $getContainer()->getStateSnapshot(), 'uuid' => $key, 'index' => $index, ]); } public function hasItemLabels(): bool { return $this->itemLabel !== null; } public function hasItemNumbers(): bool { return (bool) $this->evaluate($this->hasItemNumbers); } public function hasItemHeaders(): bool { return (bool) $this->evaluate($this->hasItemHeaders); } public function simple(Field | Closure | null $field): static { $this->simpleField = $field; $this->schema(fn (Repeater $component): array => [$component->getSimpleField()]); return $this; } public function isSimple(): bool { return $this->simpleField !== null; } /** * @param array | Closure | null $columns */ public function table(array | Closure | null $columns): static { $this->tableColumns = $columns; return $this; } /** * @return ?array */ public function getTableColumns(): ?array { return $this->evaluate($this->tableColumns); } public function isTable(): bool { return filled($this->getTableColumns()); } public function getSimpleField(): ?Field { return ($this->cachedSimpleField ??= $this->evaluate($this->simpleField))?->hiddenLabel(); } public function clearCachedExistingRecords(): void { $this->cachedExistingRecords = null; // Items embed the existing records, which the raw state snapshot cannot // observe, so they must be cleared explicitly alongside the records. $this->clearCachedChildSchemas(); } /** * @return class-string */ public function getRelatedModel(): string { return $this->getRelationship()->getModel()::class; } public function hasRelationship(): bool { return filled($this->getRelationshipName()); } public function mutateRelationshipDataBeforeCreateUsing(?Closure $callback): static { $this->mutateRelationshipDataBeforeCreateUsing = $callback; return $this; } /** * @param array> $data * @return array> | null */ public function mutateRelationshipDataBeforeCreate(array $data): ?array { if ($this->mutateRelationshipDataBeforeCreateUsing instanceof Closure) { $data = $this->evaluate($this->mutateRelationshipDataBeforeCreateUsing, [ 'data' => $data, ]); } return $data; } public function mutateRelationshipDataBeforeSaveUsing(?Closure $callback): static { $this->mutateRelationshipDataBeforeSaveUsing = $callback; return $this; } /** * @param array> $data * @return array> */ public function mutateRelationshipDataBeforeFill(array $data): array { if ($this->mutateRelationshipDataBeforeFillUsing instanceof Closure) { $data = $this->evaluate($this->mutateRelationshipDataBeforeFillUsing, [ 'data' => $data, ]); } return $data; } public function mutateRelationshipDataBeforeFillUsing(?Closure $callback): static { $this->mutateRelationshipDataBeforeFillUsing = $callback; return $this; } /** * @param array> $data * @return array> | null */ public function mutateRelationshipDataBeforeSave(array $data, Model $record): ?array { if ($this->mutateRelationshipDataBeforeSaveUsing instanceof Closure) { $data = $this->evaluate( $this->mutateRelationshipDataBeforeSaveUsing, namedInjections: [ 'data' => $data, 'record' => $record, ], typedInjections: [ Model::class => $record, $record::class => $record, ], ); } return $data; } public function afterCreate(?Closure $callback): static { $this->afterCreate = $callback; return $this; } public function afterUpdate(?Closure $callback): static { $this->afterUpdate = $callback; return $this; } public function afterDelete(?Closure $callback): static { $this->afterDelete = $callback; return $this; } /** * @param array $data */ protected function callAfterCreate(array $data, Model $record): void { if ($this->afterCreate instanceof Closure) { $this->evaluate( $this->afterCreate, namedInjections: [ 'data' => $data, 'record' => $record, ], typedInjections: [ Model::class => $record, $record::class => $record, ], ); } } /** * @param array $data */ protected function callAfterUpdate(array $data, Model $record): void { if ($this->afterUpdate instanceof Closure) { $this->evaluate( $this->afterUpdate, namedInjections: [ 'data' => $data, 'record' => $record, ], typedInjections: [ Model::class => $record, $record::class => $record, ], ); } } protected function callAfterDelete(Model $record): void { if ($this->afterDelete instanceof Closure) { $this->evaluate( $this->afterDelete, namedInjections: [ 'record' => $record, ], typedInjections: [ Model::class => $record, $record::class => $record, ], ); } } public function getPublishedViewOverrideCheckPath(): ?string { if ($this->isTable()) { return 'filament-forms::components.repeater.table'; } if ($this->isSimple()) { return 'filament-forms::components.repeater.simple'; } return 'filament-forms::components.repeater.index'; } public function toEmbeddedHtml(): string { if ($this->isTable()) { return $this->toTableEmbeddedHtml(); } if ($this->isSimple()) { return $this->toSimpleEmbeddedHtml(); } $items = $this->getItems(); $addAction = $this->getAction($this->getAddActionName()); $addActionAlignment = $this->getAddActionAlignment(); $addBetweenAction = $this->getAction($this->getAddBetweenActionName()); $cloneAction = $this->getAction($this->getCloneActionName()); $collapseAllAction = $this->getAction($this->getCollapseAllActionName()); $expandAllAction = $this->getAction($this->getExpandAllActionName()); $deleteAction = $this->getAction($this->getDeleteActionName()); $moveDownAction = $this->getAction($this->getMoveDownActionName()); $moveUpAction = $this->getAction($this->getMoveUpActionName()); $reorderAction = $this->getAction($this->getReorderActionName()); $extraItemActions = $this->getExtraItemActions(); $hasItemNumbers = $this->hasItemNumbers(); $hasItemHeaders = $this->hasItemHeaders(); $isAddable = $this->isAddable(); $isCloneable = $this->isCloneable(); $isCollapsible = $this->isCollapsible(); $isDeletable = $this->isDeletable(); $isReorderableWithButtons = $this->isReorderableWithButtons(); $isReorderableWithDragAndDrop = $this->isReorderableWithDragAndDrop(); $collapseAllActionIsVisible = $isCollapsible && $collapseAllAction->isVisible(); $expandAllActionIsVisible = $isCollapsible && $expandAllAction->isVisible(); $persistCollapsed = $this->shouldPersistCollapsed(); $key = $this->getKey(); $itemLabelHeadingTag = $this->getHeadingTag(); $isItemLabelTruncated = $this->isItemLabelTruncated(); $labelBetweenItems = $this->getLabelBetweenItems(); $id = $this->getId(); $outerAttributes = (new FilamentComponentAttributeBag) ->merge($this->getExtraAttributes(), escape: false) ->merge($this->getAlpineAttributes($items), escape: false) ->merge([ 'aria-describedby' => $this->getAccessibilityAttributes()['aria-describedby'] ?? null, 'aria-labelledby' => "{$id}-label", 'id' => $id, 'role' => 'group', ], escape: false) ->class([ 'fi-fo-repeater', 'fi-collapsible' => $isCollapsible, ]); $itemsAttributes = (new FilamentComponentAttributeBag) ->grid($this->getGridColumns()) ->merge([ 'data-sortable-animation-duration' => $this->getReorderAnimationDuration(), 'x-on:end.stop' => 'reorder', 'x-ref' => 'reorderItems', ], escape: false) ->class(['fi-fo-repeater-items']); $itemCount = count($items); $itemIndex = 0; ob_start(); ?>
toHtml() ?>> getReorderingDescriptionHtml($items) ?>
class([ 'fi-fo-repeater-actions', 'fi-hidden' => $itemCount < 2, ])->toHtml() ?> > toHtml() ?> toHtml() ?>
    toHtml() ?>> $item) { ?> getItemLabel($itemKey, $itemIndex - 1); $visibleExtraItemActions = array_filter( $extraItemActions, fn (Action $action): bool => $action(['item' => $itemKey])->isVisible(), ); $itemCloneAction = $cloneAction(['item' => $itemKey]); $cloneActionIsVisible = $isCloneable && $itemCloneAction->isVisible(); $itemDeleteAction = $deleteAction(['item' => $itemKey]); $deleteActionIsVisible = $isDeletable && $itemDeleteAction->isVisible(); $reorderActionIsVisible = $isReorderableWithDragAndDrop && $reorderAction->isVisible(); $itemMoveDownAction = $moveDownAction(['item' => $itemKey]); $itemMoveDownAction->disabled($isLast || $itemMoveDownAction->isDisabled())->extraAttributes($this->getReorderingActionAttributes($itemMoveDownAction, 'down', ! $isReorderableWithButtons), merge: true); $moveDownActionIsVisible = ($isReorderableWithButtons || $reorderActionIsVisible) && $itemMoveDownAction->isVisible(); $itemMoveUpAction = $moveUpAction(['item' => $itemKey]); $itemMoveUpAction->disabled($isFirst || $itemMoveUpAction->isDisabled())->extraAttributes($this->getReorderingActionAttributes($itemMoveUpAction, 'up', ! $isReorderableWithButtons), merge: true); $moveUpActionIsVisible = ($isReorderableWithButtons || $reorderActionIsVisible) && $itemMoveUpAction->isVisible(); $hasItemHeader = $hasItemHeaders && ($reorderActionIsVisible || $moveUpActionIsVisible || $moveDownActionIsVisible || filled($itemLabel) || $cloneActionIsVisible || $deleteActionIsVisible || $isCollapsible || $visibleExtraItemActions); ?>
  • )" x-on:repeater-expand.window="expandFromEvent" x-on:repeater-collapse.window="collapseFromEvent" x-on:expand="expand" x-sortable-item="" class([ 'fi-fo-repeater-item', 'fi-fo-repeater-item-has-header' => $hasItemHeader, ])->toHtml() ?> x-bind:class="itemClasses" >
    x-on:click.stop="toggleCollapsed" class="fi-fo-repeater-item-header" >
    • extraAttributes(['x-sortable-handle' => true], merge: true)->toHtml() ?>
    • toHtml() ?>
    • toHtml() ?>
    < class([ 'fi-fo-repeater-item-header-label', 'fi-truncated' => $isItemLabelTruncated, ])->toHtml() ?> > >
    • $itemKey])->toHtml() ?>
    • toHtml() ?>
    • toHtml() ?>
    • getAction('collapse')->toHtml() ?>
      getAction('expand')->toHtml() ?>
    toHtml() ?>
  • $itemKey])->isVisible()) { ?>
  • $itemKey])->toHtml() ?>
isVisible()) { ?>
class([ 'fi-fo-repeater-add', ($addActionAlignment instanceof Alignment) ? ('fi-align-' . $addActionAlignment->value) : $addActionAlignment, ])->toHtml() ?> > toHtml() ?>
wrapEmbeddedHtml(ob_get_clean(), labelTag: 'div'); } protected function toSimpleEmbeddedHtml(): string { $items = $this->getItems(); $addAction = $this->getAction($this->getAddActionName()); $addActionAlignment = $this->getAddActionAlignment(); $cloneAction = $this->getAction($this->getCloneActionName()); $deleteAction = $this->getAction($this->getDeleteActionName()); $moveDownAction = $this->getAction($this->getMoveDownActionName()); $moveUpAction = $this->getAction($this->getMoveUpActionName()); $reorderAction = $this->getAction($this->getReorderActionName()); $extraItemActions = $this->getExtraItemActions(); $isAddable = $this->isAddable(); $isCloneable = $this->isCloneable(); $isDeletable = $this->isDeletable(); $isReorderableWithButtons = $this->isReorderableWithButtons(); $isReorderableWithDragAndDrop = $this->isReorderableWithDragAndDrop(); $id = $this->getId(); $outerAttributes = (new FilamentComponentAttributeBag) ->merge($this->getExtraAttributes(), escape: false) ->merge($this->getAlpineAttributes($items), escape: false) ->merge([ 'aria-describedby' => $this->getAccessibilityAttributes()['aria-describedby'] ?? null, 'aria-labelledby' => "{$id}-label", 'id' => $id, 'role' => 'group', ], escape: false) ->class(['fi-fo-simple-repeater']); $itemsAttributes = (new FilamentComponentAttributeBag) ->grid($this->getGridColumns()) ->merge([ 'data-sortable-animation-duration' => $this->getReorderAnimationDuration(), 'x-on:end.stop' => 'reorder', 'x-ref' => 'reorderItems', ], escape: false) ->class(['fi-fo-simple-repeater-items']); $itemCount = count($items); $itemIndex = 0; ob_start(); ?>
toHtml() ?>> getReorderingDescriptionHtml($items) ?>
    toHtml() ?>> $item) { ?> $action(['item' => $itemKey])->isVisible(), ); $itemCloneAction = $cloneAction(['item' => $itemKey]); $cloneActionIsVisible = $isCloneable && $itemCloneAction->isVisible(); $itemDeleteAction = $deleteAction(['item' => $itemKey]); $deleteActionIsVisible = $isDeletable && $itemDeleteAction->isVisible(); $reorderActionIsVisible = $isReorderableWithDragAndDrop && $reorderAction->isVisible(); $itemMoveDownAction = $moveDownAction(['item' => $itemKey]); $itemMoveDownAction->disabled($isLast || $itemMoveDownAction->isDisabled())->extraAttributes($this->getReorderingActionAttributes($itemMoveDownAction, 'down', ! $isReorderableWithButtons), merge: true); $moveDownActionIsVisible = ($isReorderableWithButtons || $reorderActionIsVisible) && $itemMoveDownAction->isVisible(); $itemMoveUpAction = $moveUpAction(['item' => $itemKey]); $itemMoveUpAction->disabled($isFirst || $itemMoveUpAction->isDisabled())->extraAttributes($this->getReorderingActionAttributes($itemMoveUpAction, 'up', ! $isReorderableWithButtons), merge: true); $moveUpActionIsVisible = ($isReorderableWithButtons || $reorderActionIsVisible) && $itemMoveUpAction->isVisible(); ?>
  • toHtml() ?>
    • extraAttributes(['x-sortable-handle' => true], merge: true)->toHtml() ?>
    • toHtml() ?>
    • toHtml() ?>
    • $itemKey])->toHtml() ?>
    • toHtml() ?>
    • toHtml() ?>
isVisible()) { ?>
class([ 'fi-fo-simple-repeater-add', ($addActionAlignment instanceof Alignment) ? ('fi-align-' . $addActionAlignment->value) : $addActionAlignment, ])->toHtml() ?> > toHtml() ?>
wrapEmbeddedHtml(ob_get_clean(), labelTag: 'div'); } protected function toTableEmbeddedHtml(): string { $items = $this->getItems(); $addAction = $this->getAction($this->getAddActionName()); $addActionAlignment = $this->getAddActionAlignment(); $cloneAction = $this->getAction($this->getCloneActionName()); $deleteAction = $this->getAction($this->getDeleteActionName()); $moveDownAction = $this->getAction($this->getMoveDownActionName()); $moveUpAction = $this->getAction($this->getMoveUpActionName()); $reorderAction = $this->getAction($this->getReorderActionName()); $extraItemActions = $this->getExtraItemActions(); $isAddable = $this->isAddable(); $isCloneable = $this->isCloneable(); $isDeletable = $this->isDeletable(); $isReorderableWithButtons = $this->isReorderableWithButtons(); $isReorderableWithDragAndDrop = $this->isReorderableWithDragAndDrop(); $tableColumns = $this->getTableColumns() ?? []; $isCompact = $this->isCompact(); $id = $this->getId(); $outerAttributes = (new FilamentComponentAttributeBag) ->merge($this->getExtraAttributes(), escape: false) ->merge($this->getAlpineAttributes($items), escape: false) ->merge([ 'aria-describedby' => $this->getAccessibilityAttributes()['aria-describedby'] ?? null, 'aria-labelledby' => "{$id}-label", 'id' => $id, 'role' => 'group', ], escape: false) ->class([ 'fi-fo-table-repeater', 'fi-compact' => $isCompact, ]); $tbodyAttributes = (new FilamentComponentAttributeBag) ->merge([ 'data-sortable-animation-duration' => $this->getReorderAnimationDuration(), 'x-on:end.stop' => 'reorder', 'x-ref' => 'reorderItems', ], escape: false); $itemCount = count($items); $itemIndex = 0; $hasReorderColumn = ($itemCount > 1) && ($isReorderableWithButtons || $isReorderableWithDragAndDrop); $hasActionsColumn = count($extraItemActions) || $isCloneable || $isDeletable; ob_start(); ?>
toHtml() ?>> getReorderingDescriptionHtml($items) ?> getAlignment(); $columnWidth = $column->getWidth(); $thAttributes = (new FilamentComponentAttributeBag) ->class([ 'fi-wrapped' => $column->canHeaderWrap(), ($columnAlignment instanceof Alignment) ? ('fi-align-' . $columnAlignment->value) : $columnAlignment, ]); if (filled($columnWidth)) { $thAttributes = $thAttributes->style(['width: ' . e($columnWidth)]); } ?> toHtml() ?>> $item) { ?> $action(['item' => $itemKey])->isVisible(), ); $itemCloneAction = $cloneAction(['item' => $itemKey]); $cloneActionIsVisible = $isCloneable && $itemCloneAction->isVisible(); $itemDeleteAction = $deleteAction(['item' => $itemKey]); $deleteActionIsVisible = $isDeletable && $itemDeleteAction->isVisible(); $reorderActionIsVisible = $isReorderableWithDragAndDrop && $reorderAction->isVisible(); $itemMoveDownAction = $moveDownAction(['item' => $itemKey]); $itemMoveDownAction->disabled($isLast || $itemMoveDownAction->isDisabled())->extraAttributes($this->getReorderingActionAttributes($itemMoveDownAction, 'down', ! $isReorderableWithButtons), merge: true); $moveDownActionIsVisible = ($isReorderableWithButtons || $reorderActionIsVisible) && $itemMoveDownAction->isVisible(); $itemMoveUpAction = $moveUpAction(['item' => $itemKey]); $itemMoveUpAction->disabled($isFirst || $itemMoveUpAction->isDisabled())->extraAttributes($this->getReorderingActionAttributes($itemMoveUpAction, 'up', ! $isReorderableWithButtons), merge: true); $moveUpActionIsVisible = ($isReorderableWithButtons || $reorderActionIsVisible) && $itemMoveUpAction->isVisible(); ?> getComponents(withHidden: true) as $schemaComponent) { ?> $counter) { ?> toHtml() ?> isVisible()) { ?> getVerticalAlignment(); $tdAttributes = (new FilamentComponentAttributeBag) ->class([ ($columnVerticalAlignment instanceof VerticalAlignment) ? ('fi-vertical-align-' . $columnVerticalAlignment->value) : (is_string($columnVerticalAlignment) ? $columnVerticalAlignment : ''), ]); ?>
toHtml() ?>> isHeaderLabelHidden()) { ?> getLabel()) ?>isMarkedAsRequired()) { ?>* getLabel()) ?>
extraAttributes(['x-sortable-handle' => true], merge: true)->toHtml() ?>
toHtml() ?>
toHtml() ?>
toHtml() ?>> toSchemaHtml() ?>
$itemKey])->toHtml() ?>
toHtml() ?>
toHtml() ?>
isVisible()) { ?>
class([ 'fi-fo-table-repeater-add', ($addActionAlignment instanceof Alignment) ? ('fi-align-' . $addActionAlignment->value) : $addActionAlignment, ])->toHtml() ?> > toHtml() ?>
wrapEmbeddedHtml(ob_get_clean(), labelTag: 'div'); } public function getLabelBetweenItems(): ?string { return $this->evaluate($this->labelBetweenItems); } public function isItemLabelTruncated(): bool { return (bool) $this->evaluate($this->isItemLabelTruncated); } /** * @return array */ public function getItemState(string $key): array { return $this->getChildSchema($key)->getState(shouldCallHooksBefore: false); } /** * @return array */ public function getRawItemState(string $key): array { return $this->getChildSchema($key)->getStateSnapshot(); } public function getHeadingsCount(): int { if (! $this->hasItemLabels()) { return 0; } return 1; } public function partiallyRenderAfterActionsCalled(bool | Closure | null $condition = true): static { $this->shouldPartiallyRenderAfterActionsCalled = $condition; return $this; } public function shouldPartiallyRenderAfterActionsCalled(): bool { $condition = $this->evaluate($this->shouldPartiallyRenderAfterActionsCalled); if ($condition !== null) { return (bool) $condition; } return ! $this->isLive(); } /** * @param array $items * @return array */ protected function getAlpineAttributes(array $items): array { return [ 'data-reorder-owner' => true, 'data-reorder-items' => e(json_encode(array_map('strval', array_keys($items)))), 'x-load' => true, 'x-load-src' => FilamentAsset::getAlpineComponentSrc('repeater', 'filament/forms'), 'x-data' => 'repeaterFormComponent(' . Js::from([ 'statePath' => $this->getStatePath(), 'schemaComponent' => $this->getKey(), 'moveUpAction' => $this->getMoveUpActionName(), 'moveDownAction' => $this->getMoveDownActionName(), 'reorderAction' => $this->getReorderActionName(), 'message' => __('filament-forms::components.repeater.reordering.moved'), 'hasCustomReorderAction' => (bool) $this->modifyReorderActionUsing, ]) . ')', ]; } /** @return array */ protected function getReorderingActionAttributes(Action $action, string $direction, bool $isVisuallyHidden): array { return [ ...($isVisuallyHidden ? ['tabindex' => -1, 'data-reorder-hidden' => true] : []), 'data-reorder-direction' => $direction, 'data-reorder-action' => ($action->getActionFunction() && (! $action->getLivewireEventClickHandler()) && blank($action->getParentActionCallLivewireClickHandler())) ? $action->getLivewireClickHandler() : null, 'aria-describedby' => $this->getId() . '-item-' . md5((string) $action->getArguments()['item']), ]; } /** @param array $items */ protected function getReorderingDescriptionHtml(array $items): string { $html = ''; $position = 0; foreach ($items as $itemKey => $item) { $label = ($this->hasItemLabels() ? $this->getItemLabel((string) $itemKey, $position) : null) ?? __('filament-forms::components.repeater.reordering.item'); if ($label instanceof Htmlable) { $label = html_entity_decode(strip_tags($label->toHtml()), ENT_QUOTES | ENT_HTML5, 'UTF-8'); } $label = trim($label); if ($label === '') { $label = __('filament-forms::components.repeater.reordering.item'); } $description = __('filament-forms::components.repeater.reordering.position', ['label' => $label, 'position' => ++$position, 'count' => count($items)]); $html .= '' . e($description) . ''; } return $html; } }