Skip to content

Commit

Permalink
fix: fix content modules (#385)
Browse files Browse the repository at this point in the history
* fix: add rel and target attributes to logo links for security and accessibility and opening in new tab in logo wall

* feat: add services teaser layout module and enhance case study teaser component with compilation logic
  • Loading branch information
JimSeven authored Nov 27, 2024
1 parent 1b23893 commit ada2465
Show file tree
Hide file tree
Showing 8 changed files with 867 additions and 94 deletions.
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

0 comments on commit ada2465

Please sign in to comment.