diff --git a/resources/js/entity-list/EntityList.ts b/resources/js/entity-list/EntityList.ts
index 9cf3af295..30bc458e8 100644
--- a/resources/js/entity-list/EntityList.ts
+++ b/resources/js/entity-list/EntityList.ts
@@ -18,6 +18,7 @@ export class EntityList implements EntityListData {
pageAlert: EntityListData['pageAlert'];
query: EntityListData['query'];
filterValues: EntityListData['filterValues'];
+ title: EntityListData['title'];
entityKey: string;
hiddenFilters?: Record;
diff --git a/resources/js/form/Form.ts b/resources/js/form/Form.ts
index 314ecefa9..9b5d9779e 100644
--- a/resources/js/form/Form.ts
+++ b/resources/js/form/Form.ts
@@ -25,6 +25,7 @@ export class Form implements FormData, CommandFormData {
layout: FormData['layout'];
locales: FormData['locales'];
pageAlert: FormData['pageAlert'];
+ title: FormData['title'];
state = reactive<{
data: FormData['data'],
diff --git a/resources/js/show/Show.ts b/resources/js/show/Show.ts
index 4930e9ff3..057a9d4c8 100644
--- a/resources/js/show/Show.ts
+++ b/resources/js/show/Show.ts
@@ -20,6 +20,7 @@ export class Show implements ShowData {
layout: ShowData['layout'];
locales: ShowData['locales'];
pageAlert: ShowData['pageAlert'];
+ title: ShowData['title'];
entityKey: string;
instanceId?: string;
@@ -65,15 +66,10 @@ export class Show implements ShowData {
}
getTitle(locale: string): string | null {
- if(!this.config.titleAttribute) {
- return null;
- }
- if(this.fields[this.config.titleAttribute]) {
- const field = this.fields[this.config.titleAttribute] as ShowTextFieldData;
- const value = this.data[this.config.titleAttribute] as ShowTextFieldData['value'];
- return field.localized && typeof value?.text === 'object'
- ? value?.text?.[locale]
- : value?.text as string;
+ if(this.title) {
+ return typeof this.title === 'object'
+ ? this.title?.[locale]
+ : this.title;
}
return null;
}
diff --git a/resources/js/types/generated.d.ts b/resources/js/types/generated.d.ts
index a3c1252f3..b81831425 100644
--- a/resources/js/types/generated.d.ts
+++ b/resources/js/types/generated.d.ts
@@ -149,6 +149,7 @@ export type EntityListData = {
data: Array<{ [key: string]: any }>;
filterValues: FilterValuesData;
query: EntityListQueryParamsData | null;
+ title: string | null;
forms: { [key: string]: EntityListMultiformData } | null;
meta: PaginatorMetaData | null;
pageAlert: PageAlertData | null;
@@ -274,9 +275,7 @@ export type FormConditionalDisplayData = {
fields: Array<{ key: string; values: string | boolean | Array }>;
};
export type FormConfigData = {
- hasShowPage: boolean;
isSingle: boolean;
- breadcrumbAttribute: string | null;
};
export type FormCustomFieldData = {
value?: any;
@@ -295,6 +294,7 @@ export type FormData = {
fields: { [key: string]: FormFieldData };
layout: FormLayoutData;
locales: Array;
+ title: string | null;
pageAlert: PageAlertData | null;
};
export type FormDateFieldData = {
@@ -575,8 +575,6 @@ export type FormUploadFieldData = {
allowedExtensions: Array | null;
maxFileSize: number | null;
validationRule: Array | null;
- storageBasePath: string | null;
- storageDisk: string | null;
label: string | null;
readOnly: boolean | null;
conditionalDisplay: FormConditionalDisplayData | null;
@@ -764,6 +762,7 @@ export type ShowData = {
fields: { [key: string]: ShowFieldData };
layout: ShowLayoutData;
locales: Array | null;
+ title: string | { [locale: string]: string } | null;
pageAlert: PageAlertData | null;
};
export type ShowEntityListFieldData = {
diff --git a/src/Data/EntityList/EntityListData.php b/src/Data/EntityList/EntityListData.php
index eb3e2445e..cccd40c27 100644
--- a/src/Data/EntityList/EntityListData.php
+++ b/src/Data/EntityList/EntityListData.php
@@ -15,6 +15,7 @@
final class EntityListData extends Data
{
public function __construct(
+ public ?string $title,
public EntityListAuthorizationsData $authorizations,
public EntityListConfigData $config,
/** @var EntityListFieldData[] */
@@ -32,6 +33,7 @@ public function __construct(
public static function from(array $entityList): self
{
return new self(
+ title: $entityList['title'] ?? null,
authorizations: new EntityListAuthorizationsData(...$entityList['authorizations']),
config: EntityListConfigData::from($entityList['config']),
fields: EntityListFieldData::collection($entityList['fields']),
diff --git a/src/Data/Form/FormConfigData.php b/src/Data/Form/FormConfigData.php
index 1dbec67ca..55232744f 100644
--- a/src/Data/Form/FormConfigData.php
+++ b/src/Data/Form/FormConfigData.php
@@ -10,9 +10,7 @@
final class FormConfigData extends Data
{
public function __construct(
- public bool $hasShowPage,
public bool $isSingle = false,
- public ?string $breadcrumbAttribute = null,
) {}
public static function from(array $config): self
diff --git a/src/Data/Form/FormData.php b/src/Data/Form/FormData.php
index 2c40569bb..01da1998a 100644
--- a/src/Data/Form/FormData.php
+++ b/src/Data/Form/FormData.php
@@ -14,6 +14,7 @@
final class FormData extends Data
{
public function __construct(
+ public ?string $title,
public InstanceAuthorizationsData $authorizations,
public FormConfigData $config,
#[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')]
@@ -29,6 +30,7 @@ public function __construct(
public static function from(array $form): self
{
return new self(
+ title: $form['title'],
authorizations: InstanceAuthorizationsData::from($form['authorizations']),
config: FormConfigData::from($form['config']),
data: $form['data'],
diff --git a/src/Data/Show/ShowData.php b/src/Data/Show/ShowData.php
index 2b757d744..94ea1fadc 100644
--- a/src/Data/Show/ShowData.php
+++ b/src/Data/Show/ShowData.php
@@ -14,6 +14,8 @@
final class ShowData extends Data
{
public function __construct(
+ #[LiteralTypeScriptType('string | { [locale:string]: string } | null')]
+ public string|array|null $title,
public InstanceAuthorizationsData $authorizations,
public ShowConfigData $config,
#[LiteralTypeScriptType('{ [key:string]: ShowFieldData["value"] }')]
@@ -29,6 +31,7 @@ public function __construct(
public static function from(array $show): self
{
return new self(
+ title: $show['title'],
authorizations: InstanceAuthorizationsData::from($show['authorizations']),
config: ShowConfigData::from($show['config']),
data: $show['data'],
diff --git a/src/EntityList/Commands/QuickCreate/QuickCreationCommand.php b/src/EntityList/Commands/QuickCreate/QuickCreationCommand.php
index 8739b8b67..f2960bc2e 100644
--- a/src/EntityList/Commands/QuickCreate/QuickCreationCommand.php
+++ b/src/EntityList/Commands/QuickCreate/QuickCreationCommand.php
@@ -73,7 +73,7 @@ public function execute(array $data = []): array
? $this->link(sprintf(
'%s/s-show/%s/%s',
$currentUrl,
- sharp_normalize_entity_key($this->entityKey)[0],
+ $this->entityKey,
$instanceId
))
: $this->reload();
diff --git a/src/Form/SharpForm.php b/src/Form/SharpForm.php
index 97a4ee102..ec34feb56 100644
--- a/src/Form/SharpForm.php
+++ b/src/Form/SharpForm.php
@@ -38,17 +38,7 @@ final public function formLayout(): array
public function formConfig(): array
{
- return tap(
- [
- 'hasShowPage' => $this->displayShowPageAfterCreation,
-// 'title' => sharp()->context()->isCreation()
-// ? $this->createFormTitle
-// : $this->editFormTitle,
- ],
- function (&$config) {
- $this->appendBreadcrumbCustomLabelAttribute($config);
- },
- );
+ return [];
}
final public function instance($id): array
@@ -106,6 +96,16 @@ protected function configureCreateTitle(string $createFormTitle): self
return $this;
}
+
+ final public function getCreateTitle(): ?string
+ {
+ return $this->createFormTitle;
+ }
+
+ final public function getEditTitle(): ?string
+ {
+ return $this->editFormTitle;
+ }
public function isDisplayShowPageAfterCreation(): bool
{
diff --git a/src/Http/Context/SharpBreadcrumb.php b/src/Http/Context/SharpBreadcrumb.php
index cd5d015af..02ff8c130 100644
--- a/src/Http/Context/SharpBreadcrumb.php
+++ b/src/Http/Context/SharpBreadcrumb.php
@@ -4,6 +4,7 @@
use Code16\Sharp\Http\Context\Util\BreadcrumbItem;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
+use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Code16\Sharp\Utils\Menu\SharpMenuManager;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
@@ -203,6 +204,13 @@ private function getDocumentTitleLabelFor(BreadcrumbItem $item, bool $isLeaf): ?
default => null
};
}
+
+ public function getParentShowCachedBreadcrumbLabel(): ?string
+ {
+ $item = $this->breadcrumbItems()->last();
+
+ return Cache::get("sharp.breadcrumb.{$item->key}.s-show.{$item->instance}");
+ }
/**
* Only for Shows and Forms.
@@ -211,7 +219,7 @@ private function getEntityLabelForInstance(BreadcrumbItem $item, bool $isLeaf):
{
$cacheKey = "sharp.breadcrumb.{$item->key}.{$item->type}.{$item->instance}";
- if ($item->isForm() && ($cached = Cache::get("sharp.breadcrumb.{$item->key}.s-show.{$item->instance}"))) {
+ if ($item->isForm() && ($cached = $this->getParentShowCachedBreadcrumbLabel())) {
return $cached;
}
@@ -228,13 +236,9 @@ private function getEntityLabelForInstance(BreadcrumbItem $item, bool $isLeaf):
}
}
- $entity = app(SharpEntityManager::class)->entityFor($item->key);
-
- if (str_contains($item->key, ':')) {
- return $entity->getMultiforms()[Str::after($item->key, ':')][1] ?? $entity->getLabel();
- }
-
- return $entity->getLabel();
+ return app(SharpEntityManager::class)
+ ->entityFor($item->key)
+ ->getLabel((new EntityKey($item->key))->subEntity());
}
private function isSameEntityKeys(string $key1, string $key2, bool $compareBaseEntities): bool
diff --git a/src/Http/Controllers/Api/ApiController.php b/src/Http/Controllers/Api/ApiController.php
index 5e2976fe6..6e571f8be 100644
--- a/src/Http/Controllers/Api/ApiController.php
+++ b/src/Http/Controllers/Api/ApiController.php
@@ -29,11 +29,6 @@ protected function getShowInstance(string $entityKey): SharpShow
return $this->entityManager->entityFor($entityKey)->getShowOrFail();
}
- protected function getFormInstance(string $entityKey): SharpForm
- {
- return $this->entityManager->entityFor($entityKey)->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
- }
-
protected function getDashboardInstance(string $dashboardKey): ?SharpDashboard
{
return $this->entityManager->entityFor($dashboardKey)->getViewOrFail();
diff --git a/src/Http/Controllers/Api/ApiFormAutocompleteController.php b/src/Http/Controllers/Api/ApiFormAutocompleteController.php
index c17d20ae0..9361f74ee 100644
--- a/src/Http/Controllers/Api/ApiFormAutocompleteController.php
+++ b/src/Http/Controllers/Api/ApiFormAutocompleteController.php
@@ -10,6 +10,7 @@
use Code16\Sharp\Http\Controllers\Api\Commands\HandlesEntityCommand;
use Code16\Sharp\Http\Controllers\Api\Commands\HandlesInstanceCommand;
use Code16\Sharp\Http\Controllers\Api\Embeds\HandlesEmbed;
+use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Code16\Sharp\Utils\Transformers\ArrayConverter;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
@@ -21,7 +22,7 @@ class ApiFormAutocompleteController extends ApiController
use HandlesEntityCommand;
use HandlesInstanceCommand;
- public function index(string $entityKey, string $autocompleteFieldKey)
+ public function index(EntityKey $entityKey, string $autocompleteFieldKey)
{
$fieldContainer = $this->getFieldContainer($entityKey);
$field = $fieldContainer->findFieldByKey($autocompleteFieldKey);
@@ -86,7 +87,7 @@ public function index(string $entityKey, string $autocompleteFieldKey)
]);
}
- private function getFieldContainer(string $entityKey): SharpFormEditorEmbed|Command|SharpForm
+ private function getFieldContainer(EntityKey $entityKey): SharpFormEditorEmbed|Command|SharpForm
{
if (request()->input('embed_key')) {
return $this->getEmbedFromKey(request()->input('embed_key'));
@@ -117,7 +118,7 @@ private function getFieldContainer(string $entityKey): SharpFormEditorEmbed|Comm
);
}
- return $entity->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
+ return $entity->getFormOrFail($entityKey->subEntity());
}
private function normalizeEndpoint(string $input): string
diff --git a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php
index d4e64e77b..995231fc9 100644
--- a/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php
+++ b/src/Http/Controllers/Api/Commands/ApiEntityListQuickCreationCommandController.php
@@ -4,8 +4,8 @@
use Code16\Sharp\Data\Commands\CommandFormData;
use Code16\Sharp\Http\Controllers\Api\ApiController;
+use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Code16\Sharp\Utils\Uploads\SharpUploadManager;
-use Illuminate\Support\Str;
class ApiEntityListQuickCreationCommandController extends ApiController
{
@@ -17,7 +17,7 @@ public function __construct(private readonly SharpUploadManager $uploadManager)
parent::__construct();
}
- public function create(string $entityKey)
+ public function create(EntityKey $entityKey)
{
$entity = $this->entityManager->entityFor($entityKey);
@@ -29,16 +29,14 @@ public function create(string $entityKey)
403
);
- $form = $entity->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
+ $form = $entity->getFormOrFail($entityKey->subEntity());
$form->buildFormConfig();
$quickCreationHandler
->setEntityKey($entityKey)
->setFormInstance($form)
->setTitle(__('sharp::breadcrumb.form.create_entity', [
- 'entity' => str_contains($entityKey, ':')
- ? $entity->getMultiforms()[Str::after($entityKey, ':')][1] ?? $entity->getLabel()
- : $entity->getLabel(),
+ 'entity' => $entity->getLabel($entityKey->subEntity()),
]));
$quickCreationHandler->buildCommandConfig();
@@ -50,7 +48,7 @@ public function create(string $entityKey)
);
}
- public function store(string $entityKey)
+ public function store(EntityKey $entityKey)
{
$list = $this->getListInstance($entityKey);
$list->buildListConfig();
@@ -60,7 +58,7 @@ public function store(string $entityKey)
403
);
- $form = $this->entityManager->entityFor($entityKey)->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
+ $form = $this->entityManager->entityFor($entityKey)->getFormOrFail($entityKey->subEntity());
$form->buildFormConfig();
$quickCreationHandler
diff --git a/src/Http/Controllers/EntityListController.php b/src/Http/Controllers/EntityListController.php
index 16bb83ced..53ebef3d6 100644
--- a/src/Http/Controllers/EntityListController.php
+++ b/src/Http/Controllers/EntityListController.php
@@ -8,6 +8,7 @@
use Code16\Sharp\Data\NotificationData;
use Code16\Sharp\Exceptions\SharpInvalidConfigException;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
+use Code16\Sharp\Utils\Menu\SharpMenuManager;
use Inertia\Inertia;
class EntityListController extends SharpProtectedController
@@ -58,7 +59,12 @@ public function show(string $entityKey)
}
return Inertia::render('EntityList/EntityList', [
- 'entityList' => EntityListData::from($data),
+ 'entityList' => EntityListData::from([
+ ...$data,
+ 'title' => app(SharpMenuManager::class)
+ ->getEntityMenuItem($entityKey)
+ ?->getLabel() ?: trans('sharp::breadcrumb.entityList'),
+ ]),
'breadcrumb' => BreadcrumbData::from([
'items' => sharp()->context()->breadcrumb()->allSegments(),
]),
diff --git a/src/Http/Controllers/FormController.php b/src/Http/Controllers/FormController.php
index 350c198bb..bb52cb7bd 100644
--- a/src/Http/Controllers/FormController.php
+++ b/src/Http/Controllers/FormController.php
@@ -8,6 +8,7 @@
use Code16\Sharp\Form\SharpForm;
use Code16\Sharp\Form\SharpSingleForm;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
+use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Code16\Sharp\Utils\Uploads\SharpUploadManager;
use Inertia\Inertia;
@@ -23,11 +24,11 @@ public function __construct(
parent::__construct();
}
- public function create(string $parentUri, string $entityKey)
+ public function create(string $parentUri, EntityKey $entityKey)
{
$entity = $this->entityManager->entityFor($entityKey);
- $form = $entity->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
+ $form = $entity->getFormOrFail($entityKey->subEntity());
if ($form instanceof SharpSingleForm) {
// There is no creation in SingleForms
@@ -40,14 +41,19 @@ public function create(string $parentUri, string $entityKey)
$data = $this->buildFormData($form, $entityKey);
return Inertia::render('Form/Form', [
- 'form' => FormData::from($data),
+ 'form' => FormData::from([
+ ...$data,
+ 'title' => $form->getCreateTitle() ?: trans('sharp::breadcrumb.form.create_entity', [
+ 'entity' => $entity->getLabel($entityKey->subEntity()),
+ ]),
+ ]),
'breadcrumb' => BreadcrumbData::from([
'items' => sharp()->context()->breadcrumb()->allSegments(),
]),
]);
}
- public function edit(string $parentUri, string $entityKey, ?string $instanceId = null)
+ public function edit(string $parentUri, EntityKey $entityKey, ?string $instanceId = null)
{
$entity = $this->entityManager->entityFor($entityKey);
@@ -57,7 +63,7 @@ public function edit(string $parentUri, string $entityKey, ?string $instanceId =
$instanceId
);
- $form = $entity->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
+ $form = $entity->getFormOrFail($entityKey->subEntity());
abort_if(
(! $instanceId && ! $form instanceof SharpSingleForm)
@@ -69,20 +75,26 @@ public function edit(string $parentUri, string $entityKey, ?string $instanceId =
$data = $this->buildFormData($form, $entityKey, $instanceId);
return Inertia::render('Form/Form', [
- 'form' => FormData::from($data),
+ 'form' => FormData::from([
+ ...$data,
+ 'title' => $form->getEditTitle() ?: trans('sharp::breadcrumb.form.edit_entity', [
+ 'entity' => sharp()->context()->breadcrumb()->getParentShowCachedBreadcrumbLabel()
+ ?: $entity->getLabel($entityKey->subEntity()),
+ ]),
+ ]),
'breadcrumb' => BreadcrumbData::from([
'items' => sharp()->context()->breadcrumb()->allSegments(),
]),
]);
}
- public function update(string $parentUri, string $entityKey, ?string $instanceId = null)
+ public function update(string $parentUri, EntityKey $entityKey, ?string $instanceId = null)
{
sharp_check_ability('update', $entityKey, $instanceId);
$form = $this->entityManager
->entityFor($entityKey)
- ->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
+ ->getFormOrFail($entityKey->subEntity());
abort_if(
(! $instanceId && ! $form instanceof SharpSingleForm)
@@ -97,9 +109,11 @@ public function update(string $parentUri, string $entityKey, ?string $instanceId
return redirect()->to(sharp()->context()->breadcrumb()->getPreviousSegmentUrl());
}
- public function store(string $parentUri, string $entityKey)
+ public function store(string $parentUri, EntityKey $entityKey)
{
- $form = $this->entityManager->entityFor($entityKey)->getFormOrFail(sharp_normalize_entity_key($entityKey)[1]);
+ $form = $this->entityManager
+ ->entityFor($entityKey)
+ ->getFormOrFail($entityKey->subEntity());
if ($form instanceof SharpSingleForm) {
// There is no creation in SingleForms
@@ -120,7 +134,7 @@ public function store(string $parentUri, string $entityKey)
? sprintf(
'%s/s-show/%s/%s',
$previousUrl,
- sharp_normalize_entity_key($entityKey)[0],
+ $entityKey,
$instanceId
)
: $previousUrl
diff --git a/src/Http/Controllers/ShowController.php b/src/Http/Controllers/ShowController.php
index 9fc244ce7..5294ad6b5 100644
--- a/src/Http/Controllers/ShowController.php
+++ b/src/Http/Controllers/ShowController.php
@@ -8,6 +8,7 @@
use Code16\Sharp\Data\Show\ShowData;
use Code16\Sharp\Show\SharpSingleShow;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
+use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Inertia\Inertia;
class ShowController extends SharpProtectedController
@@ -22,18 +23,20 @@ public function __construct(
parent::__construct();
}
- public function show(string $parentUri, string $entityKey, string $instanceId)
+ public function show(string $parentUri, EntityKey $entityKey, string $instanceId)
{
sharp_check_ability('view', $entityKey, $instanceId);
- $show = $this->entityManager->entityFor($entityKey)->getShowOrFail();
+ $entity = $this->entityManager->entityFor($entityKey);
+ $show = $entity->getShowOrFail();
abort_if($show instanceof SharpSingleShow, 404);
$show->buildShowConfig();
-
+
$showData = $show->instance($instanceId);
$payload = ShowData::from([
+ 'title' => $showData[$show->titleAttribute()] ?? $entity->getLabel($entityKey->subEntity()),
'config' => $show->showConfig($instanceId),
'fields' => $show->fields(),
'layout' => $show->showLayout(),
diff --git a/src/Http/Controllers/SingleShowController.php b/src/Http/Controllers/SingleShowController.php
index 86639bb2d..df47031be 100644
--- a/src/Http/Controllers/SingleShowController.php
+++ b/src/Http/Controllers/SingleShowController.php
@@ -7,6 +7,7 @@
use Code16\Sharp\Data\NotificationData;
use Code16\Sharp\Data\Show\ShowData;
use Code16\Sharp\Utils\Entities\SharpEntityManager;
+use Code16\Sharp\Utils\Entities\ValueObjects\EntityKey;
use Inertia\Inertia;
class SingleShowController extends SharpProtectedController
@@ -21,16 +22,18 @@ public function __construct(
parent::__construct();
}
- public function show(string $entityKey)
+ public function show(EntityKey $entityKey)
{
sharp_check_ability('view', $entityKey);
-
- $show = $this->entityManager->entityFor($entityKey)->getShowOrFail();
+
+ $entity = $this->entityManager->entityFor($entityKey);
+ $show = $entity->getShowOrFail();
$show->buildShowConfig();
$showData = $show->instance(null);
$payload = ShowData::from([
+ 'title' => $showData[$show->titleAttribute()] ?? $entity->getLabel($entityKey->subEntity()),
'config' => $show->showConfig(null),
'fields' => $show->fields(),
'layout' => $show->showLayout(),
diff --git a/src/Show/SharpShow.php b/src/Show/SharpShow.php
index ce8bc63ff..cebf10958 100644
--- a/src/Show/SharpShow.php
+++ b/src/Show/SharpShow.php
@@ -108,6 +108,11 @@ final protected function configureDeleteConfirmationText(string $text): self
return $this;
}
+
+ final public function titleAttribute(): ?string
+ {
+ return $this->pageTitleField?->key();
+ }
private function buildFormFields(FieldsContainer $fields): void
{
diff --git a/src/Utils/Entities/BaseSharpEntity.php b/src/Utils/Entities/BaseSharpEntity.php
index 1b8852d8c..c07149f48 100644
--- a/src/Utils/Entities/BaseSharpEntity.php
+++ b/src/Utils/Entities/BaseSharpEntity.php
@@ -32,10 +32,7 @@ final public function getPolicyOrDefault(): SharpEntityPolicy
return $policy;
}
- final public function getLabel(): string
- {
- return $this->label;
- }
+ abstract public function getLabel(): string;
final public function isDashboard(): bool
{
diff --git a/src/Utils/Entities/SharpDashboardEntity.php b/src/Utils/Entities/SharpDashboardEntity.php
index 576b8d80b..1aa0eb734 100644
--- a/src/Utils/Entities/SharpDashboardEntity.php
+++ b/src/Utils/Entities/SharpDashboardEntity.php
@@ -23,6 +23,11 @@ final public function hasView(): bool
{
return $this->getView() !== null;
}
+
+ final public function getLabel(): string
+ {
+ return $this->label;
+ }
protected function getView(): SharpDashboard
{
diff --git a/src/Utils/Entities/SharpEntity.php b/src/Utils/Entities/SharpEntity.php
index d8958ea50..12562d135 100644
--- a/src/Utils/Entities/SharpEntity.php
+++ b/src/Utils/Entities/SharpEntity.php
@@ -60,7 +60,12 @@ final public function isSingle(): bool
{
return $this->isSingle;
}
-
+
+ final public function getLabel(?string $subEntity = null): string
+ {
+ return $subEntity ? $this->getMultiforms()[$subEntity][1] : $this->label;
+ }
+
protected function getList(): ?SharpEntityList
{
if ($this->isSingle) {
diff --git a/src/Utils/Entities/SharpEntityManager.php b/src/Utils/Entities/SharpEntityManager.php
index b65bb791d..1a7f498e7 100644
--- a/src/Utils/Entities/SharpEntityManager.php
+++ b/src/Utils/Entities/SharpEntityManager.php
@@ -3,12 +3,13 @@
namespace Code16\Sharp\Utils\Entities;
use Code16\Sharp\Exceptions\SharpInvalidEntityKeyException;
+use Illuminate\Support\Str;
class SharpEntityManager
{
public function entityFor(string $entityKey): SharpEntity|SharpDashboardEntity
{
- $entityKey = sharp_normalize_entity_key($entityKey)[0];
+ $entityKey = Str::before($entityKey, ':');
if (count(sharp()->config()->get('entities')) > 0) {
$entity = sharp()->config()->get('entities.'.$entityKey);
diff --git a/src/Utils/Entities/ValueObjects/EntityKey.php b/src/Utils/Entities/ValueObjects/EntityKey.php
new file mode 100644
index 000000000..97727d706
--- /dev/null
+++ b/src/Utils/Entities/ValueObjects/EntityKey.php
@@ -0,0 +1,55 @@
+key, ':')
+ ? Str::after($this->key, ':')
+ : null;
+ }
+
+ public function getRouteKey()
+ {
+ return $this->key;
+ }
+
+ public function getRouteKeyName()
+ {
+ return 'key';
+ }
+
+ public function resolveRouteBinding($value, $field = null)
+ {
+ return new static($value);
+ }
+
+ public function resolveChildRouteBinding($childType, $value, $field)
+ {
+ return null;
+ }
+
+ public function toString(): string
+ {
+ return $this->key;
+ }
+
+ public function __toString()
+ {
+ return $this->key;
+ }
+}
diff --git a/src/sharp_helper.php b/src/sharp_helper.php
index c1e8ed3ff..47e30108a 100644
--- a/src/sharp_helper.php
+++ b/src/sharp_helper.php
@@ -1,5 +1,7 @@
isAllowed($ability, sharp_normalize_entity_key($entityKey)[0], $instanceId);
+ ->isAllowed($ability, Str::before($entityKey, ':'), $instanceId);
}
function sharp_check_ability(string $ability, string $entityKey, ?string $instanceId = null)
{
app(Code16\Sharp\Auth\SharpAuthorizationManager::class)
- ->check($ability, sharp_normalize_entity_key($entityKey)[0], $instanceId);
-}
-
-function sharp_normalize_entity_key(string $entityKey): array
-{
- $parts = explode(':', $entityKey);
-
- return count($parts) == 1 ? [$parts[0], null] : $parts;
+ ->check($ability, Str::before($entityKey, ':'), $instanceId);
}
diff --git a/tests/Http/Auth/AuthorizationsTest.php b/tests/Http/Auth/AuthorizationsTest.php
index 069b22967..5fa07e425 100644
--- a/tests/Http/Auth/AuthorizationsTest.php
+++ b/tests/Http/Auth/AuthorizationsTest.php
@@ -212,7 +212,7 @@ public function getListData(): array|Arrayable
app(SharpEntityManager::class)
->entityFor('person')
->setMultiforms([
- 'big' => [FakeSharpForm::class],
+ 'big' => [FakeSharpForm::class, 'Big'],
])
->setProhibitedActions(['delete']);
diff --git a/tests/Http/Form/FormControllerTest.php b/tests/Http/Form/FormControllerTest.php
index 373a14ade..4a240c6de 100644
--- a/tests/Http/Form/FormControllerTest.php
+++ b/tests/Http/Form/FormControllerTest.php
@@ -143,22 +143,6 @@ public function buildFormLayout(FormLayout $formLayout): void
);
});
-it('returns form configuration', function () {
- fakeFormFor('person', new class() extends PersonForm
- {
- public function buildFormConfig(): void
- {
- $this->configureBreadcrumbCustomLabelAttribute('name');
- }
- });
-
- $this->get('/sharp/s-list/person/s-form/person/1')
- ->assertOk()
- ->assertInertia(fn (Assert $page) => $page
- ->where('form.config.breadcrumbAttribute', 'name')
- );
-});
-
it('stores or updates an instance and redirect to the list', function () {
$this
->post('/sharp/s-list/person/s-form/person', [
diff --git a/tests/Unit/Form/SharpFormTest.php b/tests/Unit/Form/SharpFormTest.php
index 75cfc60c3..fc16e596d 100644
--- a/tests/Unit/Form/SharpFormTest.php
+++ b/tests/Unit/Form/SharpFormTest.php
@@ -103,26 +103,6 @@ public function buildFormFields(FieldsContainer $formFields): void
$this->assertEquals(
[
'isSingle' => true,
- 'hasShowPage' => false,
- ],
- $sharpForm->formConfig(),
- );
-});
-
-it('allows to declare setDisplayShowPageAfterCreation in config', function () {
- $sharpForm = new class() extends FakeSharpForm
- {
- public function buildFormConfig(): void
- {
- $this->configureDisplayShowPageAfterCreation();
- }
- };
-
- $sharpForm->buildFormConfig();
-
- $this->assertEquals(
- [
- 'hasShowPage' => true,
],
$sharpForm->formConfig(),
);