Skip to content

Commit

Permalink
Merge pull request #45 from art-institute-of-chicago/drift/update-pro…
Browse files Browse the repository at this point in the history
…mpt-artwork-title

Update `ThemePromptArtwork.title` when updating artwork
  • Loading branch information
nikhiltri authored May 28, 2024
2 parents e92087d + 084b1e4 commit 87a1fcf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/Repositories/ArtworkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Repositories;

use A17\Twill\Models\Contracts\TwillModelContract;
use A17\Twill\Repositories\Behaviors\HandleMedias;
use A17\Twill\Repositories\Behaviors\HandleRevisions;
use A17\Twill\Repositories\Behaviors\HandleTranslations;
use A17\Twill\Repositories\ModuleRepository;
use App\Libraries\Api\Builders\ApiQueryBuilder;
use App\Models\Artwork;
use App\Models\ThemePromptArtwork;
use App\Repositories\Traits\HandleDynamicArtworkFields;
use Illuminate\Support\Str;

Expand Down Expand Up @@ -54,6 +56,16 @@ public function prepareFieldsBeforeCreate(array $fields): array
return parent::prepareFieldsBeforeCreate([...$fields, ...$apiFields, ...$translatedFields]);
}

public function afterSave(TwillModelContract $model, array $fields): void
{
// Update hidden artwork title field used in repeater
ThemePromptArtwork::where('artwork_id', $model->id)->get()->each->update([
'title' => $fields['en']['title'],
]);

parent::afterSave($model, $fields);
}

public function getCountVisible(): int
{
return $this->model->active()->count();
Expand Down

0 comments on commit 87a1fcf

Please sign in to comment.