Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Console/ConfigureCmsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ private function updateCmsConfigurationFor($model, int $order = 1, bool $isSubCo
'isDeletable' => $collection->isDeletable(),
'subCollections' => $collection->subCollections()
->map(fn ($subCollectionClass) => app($subCollectionClass)->ozuCollectionKey()),
'labelAttribute' => $collection->labelAttribute(),
'order' => $order,
'list' => [
'isReorderable' => $list->isReorderable(),
Expand Down
13 changes: 13 additions & 0 deletions src/OzuCms/OzuCollectionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class OzuCollectionConfig
protected ?string $autoDeployDateField = null;
private bool $isCreatable = true;
private bool $isDeletable = true;
private string $labelAttribute = 'title';
private array $subCollections = [];

public function setLabel(string $label): self
Expand Down Expand Up @@ -71,6 +72,18 @@ public function setIsDeletable(bool $isDeletable = true): self
return $this;
}

public function overrideLabelAttributeInDashboard(string $attribute): self
{
$this->labelAttribute = $attribute;

return $this;
}

public function labelAttribute(): string
{
return $this->labelAttribute;
}

public function label(): string
{
return $this->label ?? 'no label';
Expand Down
28 changes: 26 additions & 2 deletions tests/Unit/OzuCollectionConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
->and($ozuCollectionConfig->autoDeployDateField())->toBeNull()
->and($ozuCollectionConfig->isCreatable())->toBeTrue()
->and($ozuCollectionConfig->isDeletable())->toBeTrue()
->and($ozuCollectionConfig->labelAttribute())->toBe('title')
->and($ozuCollectionConfig)->toHaveProperties([
'label',
'icon',
'hasPublicationState',
'autoDeployDateField',
'isCreatable',
'isDeletable',
'labelAttribute',
])
->and($ozuCollectionConfig::class)->toHaveMethods([
'setLabel',
Expand All @@ -25,13 +27,17 @@
'setAutoDeployDateField',
'setIsCreatable',
'setIsDeletable',
'addSubCollection',
'subCollections',
'overrideLabelAttributeInDashboard',
'label',
'icon',
'hasPublicationState',
'autoDeployDateField',
'hasAutoDeployDateField',
'isCreatable',
'isDeletable',
'labelAttribute',
]);

});
Expand Down Expand Up @@ -67,6 +73,22 @@
->and($ozuCollectionConfig->isDeletable())->toBeFalse();
});

it('allows to add a sub collection', function () {
$ozuCollectionConfig = new OzuCollectionConfig();

$ozuCollectionConfig->addSubCollection('CollectionClass');

expect($ozuCollectionConfig->subCollections()->toArray())->toBe(['CollectionClass']);
});

it('allows to override label attribute', function () {
$ozuCollectionConfig = new OzuCollectionConfig();

$ozuCollectionConfig->overrideLabelAttributeInDashboard('name');

expect($ozuCollectionConfig->labelAttribute())->toBe('name');
});

it('allows to chain methods', function () {
$ozuCollectionConfig = new OzuCollectionConfig();

Expand All @@ -76,12 +98,14 @@
->setHasPublicationState()
->setAutoDeployDateField('date')
->setIsCreatable(false)
->setIsDeletable(false);
->setIsDeletable(false)
->overrideLabelAttributeInDashboard('name');

expect($ozuCollectionConfig->label())->toBe('label')
->and($ozuCollectionConfig->icon())->toBe('icon')
->and($ozuCollectionConfig->hasPublicationState())->toBeTrue()
->and($ozuCollectionConfig->autoDeployDateField())->toBe('date')
->and($ozuCollectionConfig->isCreatable())->toBeFalse()
->and($ozuCollectionConfig->isDeletable())->toBeFalse();
->and($ozuCollectionConfig->isDeletable())->toBeFalse()
->and($ozuCollectionConfig->labelAttribute())->toBe('name');
});