Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix content modules #385

Merged
merged 3 commits into from
Nov 27, 2024
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
19 changes: 14 additions & 5 deletions app/Data/LayoutModules/ServicesTeaserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace App\Data\LayoutModules;

use App\Enums\ServicesTeaserCompilation;
use InvalidArgumentException;
use Spatie\LaravelData\Data;
use Statamic\Entries\EntryCollection;
use Statamic\Facades\Entry;
use Statamic\Fields\LabeledValue;
use Statamic\Fields\Values;
use Statamic\Stache\Query\EntryQueryBuilder;

Expand All @@ -23,8 +25,8 @@ final class ServicesTeaserData extends Data
* @param ServicesTeaserItemData[] $entries Array of entries to be displayed.
*/
public function __construct(
public string $headline,
public string $intro_text,
public ?string $headline,
public ?string $intro_text,
public ?string $overline,
public array $entries,
) {}
Expand All @@ -48,8 +50,14 @@ public static function fromStatamic(Values $context): self
$headline = $context->headline;
$intro_text = $context->intro_text;

/** @var LabeledValue $c */
$c = $context->compilation;
/** @var ServicesTeaserCompilation|null $compilation */
$compilation = $context->compilation ?? ServicesTeaserCompilation::ALL;
$compilation = match ($c->value()) {
'all' => ServicesTeaserCompilation::ALL,
'by_hand' => ServicesTeaserCompilation::BY_HAND,
default => throw new InvalidArgumentException('Ungültiger Wert für Compilation: '.$c->value()),
};

/** @var EntryCollection $raw_entries */
$raw_entries = $context->entries;
Expand All @@ -72,11 +80,12 @@ public static function fromStatamic(Values $context): self
*/
private static function getAllPublishedServiceEntries(): EntryCollection
{

/** @var EntryQueryBuilder $query */
$query = Entry::query();

$query = $query()
->where('collection', ['services'])
$query = $query
->where('collection', 'services')
->where('published', true)
->orderBy('date', 'desc');

Expand Down
10 changes: 7 additions & 3 deletions app/Livewire/LayoutModules/CaseStudyTeaserList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class CaseStudyTeaserList extends Component
protected array $collections = ['case_studies'];
public array $entries;
public string $class;
public string $compilation;

public function mount($class)
public function mount($class, $compilation, $entries)
{
$this->class = $class;
$this->entries = $this->getNewestEntries();
$this->compilation = $compilation;
$this->entries = $this->compilation === 'by_hand' ? $entries : $this->getNewestEntries();
}

/**
Expand All @@ -45,7 +47,9 @@ public function getNewestEntries($limit = 10)

public function updateEntries()
{
$this->entries = $this->getNewestEntries();
if ($this->compilation !== 'by_hand') {
$this->entries = $this->getNewestEntries();
}
}

public function render()
Expand Down
10 changes: 1 addition & 9 deletions app/View/Components/Elements/CaseStudyTeaser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class CaseStudyTeaser extends Component
class CaseStudyTeaser extends Element
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}

/**
* Get the view / contents that represent the component.
*/
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"socialiteproviders/google": "^4.1",
"spatie/fork": "^1.2",
"spatie/laravel-data": "^4.10",
"spatie/laravel-ray": "^1.37",
"statamic/cms": "^5.0",
"statamic/ssg": "^3.0",
"stillat/relationships": "^2.2"
Expand Down
Loading