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

feat: add logo wall layout module #329

Merged
merged 10 commits into from
Oct 18, 2024
1 change: 0 additions & 1 deletion app/View/Components/Layout/ModuleWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class ModuleWrapper extends Component
*/
public function __construct(public $context)
{
// dd($context);
$this->context = $context;
}

Expand Down
91 changes: 91 additions & 0 deletions app/View/Components/LayoutModules/LogoWall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace App\View\Components\LayoutModules;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
use Statamic\Entries\Entry;
use Statamic\Entries\EntryCollection;

class LogoWall extends Module
{
public array $clients;

/**
* Initializes the client data by setting it through getClients method.
*/
protected function init(): void
{
$this->clients = $this->getClients();
}

/**
* Augments the data passed to the view.
*
* @return array<string, array<int, array{title: string, url: string, logo: string}>|string>
*/
protected function augmentData(): array
{
return [
'clients' => $this->clients,
];
}

/**
* Retrieves the client data, converts it, and returns it as an array.
*
* @return array<int, array{title: string, url: string, logo: string}>
*
* @throws \UnexpectedValueException If any item in the collection is not of type Entry.
*/
private function getClients(): array
{
/**
* @var EntryCollection<Entry>|null $clients_data
*/
$clients_data = $this->context?->clients;

if ($clients_data === null) {
throw new \UnexpectedValueException('$clients_data must not be null');
}

return $clients_data->map(function (Entry $client): array {
return $this->convertClient($client);
})->toArray();
}

/**
* Converts a client entry into an array with title, URL, and logo.
*
* @param Entry $client The client entry to be converted.
* @return array{title: string, url: string, logo: string} The converted array with client data.
*
* @throws \InvalidArgumentException If the client data is missing required fields.
*/
private function convertClient(Entry $client): array
{
// dd($client->get('title'), $client->get('logo'), $client->augmentedValue('logo')->value(), $client->logo);
$title = $client->get('title');
$url = $client->get('client_url');
$logo = $client->augmentedValue('logo')->value();

if (empty($title) || empty($url) || empty($logo)) {
throw new \InvalidArgumentException('Client data is missing required fields.');
}

return [
'title' => (string) $title,
'url' => (string) $url,
'logo' => (string) $logo,
];
}

/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.layout-modules.logo-wall');
}
}
37 changes: 34 additions & 3 deletions app/View/Components/LayoutModules/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,52 @@ class Module extends Component
{
/**
* Create a new component instance.
*
* @param string|null $module_id The module identifier.
* @param string|null $type The type of the module.
* @param mixed $context The context data passed to the component.
*/
public function __construct(public string $module_id, public string $type, public $context)
public function __construct(public ?string $module_id, public ?string $type, public $context)
{
$this->module_id = $module_id;
$this->type = $type;
$this->context = $context;
$this->init();
}

public function data()
/**
* Initialize the module. This method can be overridden in child classes.
*/
protected function init(): void {}

/**
* Augments the data passed to the view.
*
* @return array<string, string|array<string, string|array>> Augmented data array.
*/
protected function augmentData(): array
{
return [];
}

/**
* Combines the parent's data with context and augmented data.
*
* @return array<string, mixed> Combined data for the component.
*/
public function data(): array
{
return array_merge(parent::data(), $this->context->toArray());
return array_merge(
parent::data(),
$this->context ? $this->context->toArray() : [],
$this->augmentData()
);
}

/**
* Get the view / contents that represent the component.
*
* @return View|Closure|string The view to be rendered.
*/
public function render(): View|Closure|string
{
Expand Down
4 changes: 2 additions & 2 deletions app/View/Components/LayoutModules/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class Quote extends Module
{
public function data()
public function augmentData(): array
{
$quote_data = [
'author_name' => $this->context['author']->title,
Expand All @@ -25,7 +25,7 @@ public function data()
]);
}

return array_merge(parent::data(), $quote_data);
return $quote_data;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions content/collections/clients/a-cold-wall.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 825ad067-352d-4721-9adf-3fd577facc0b
blueprint: client
title: 'A-COLD-WALL*'
url: 'https://a-cold-wall.com'
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542149
logo: clients/a-cold-wall.svg
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081447
logo: a-cold-wall
client_url: 'https://a-cold-wall.com/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/avacon.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 65f4bec1-f1bd-4392-8304-02bfd76c84a6
blueprint: client
title: Avacon
url: 'https://www.avacon.de'
logo: clients/avacon.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725554135
logo: avacon
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081481
client_url: 'https://www.avacon.de/de.html'
---
7 changes: 4 additions & 3 deletions content/collections/clients/bayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 623ec2e5-d971-4c78-ba91-88131f4ed049
blueprint: client
title: Bayer
url: 'https://www.bayer.com'
logo: clients/bayer.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542157
logo: bayer
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081507
client_url: 'https://www.bayer.com'
---
7 changes: 4 additions & 3 deletions content/collections/clients/butlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 9b11926e-08b3-4061-a987-e61a34739051
blueprint: client
title: Butlers
url: 'https://www.butlers.com'
logo: clients/butlers.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542170
logo: butlers
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081526
client_url: 'https://www.butlers.com/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/deutsche-telekom.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 5ea2dcd9-ba69-46c9-b80d-05cc1ee39f3e
blueprint: client
title: 'Deutsche Telekom'
url: 'https://www.telekom.com'
logo: clients/deutsche-telekom.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542179
logo: deutsche-telekom
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081547
client_url: 'https://www.electronicbeats.net/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/elbjazz.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 397f19e7-0fae-4b86-99c7-2f5da703730d
blueprint: client
title: Elbjazz
url: 'https://elbjazz.de'
logo: clients/elbjazz.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725550870
logo: elbjazz
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081568
client_url: 'https://elbjazz.de/en/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/ensemble-resonanz.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: b2c34847-17a9-487f-bdaa-cc513aba2e04
blueprint: client
title: 'Ensemble Resonanz'
url: 'https://www.ensembleresonanz.com'
logo: clients/ensemble-resonanz.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542186
logo: ensemble-resonanz
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081581
client_url: 'https://www.ensembleresonanz.com/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/fiege-logistik.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: dfed226e-6457-4bb2-b5b6-98b32fb7eaf6
blueprint: client
title: 'FIEGE Logistik'
url: 'https://www.fiege.com'
logo: clients/fiege.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542196
logo: fiege
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081596
client_url: 'https://fiege.com'
---
7 changes: 4 additions & 3 deletions content/collections/clients/gruner-jahr.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 3fb97b78-7ff5-4ace-9bd8-b2037668b440
blueprint: client
title: 'Gruner + Jahr'
url: 'https://guj.de'
logo: clients/gruner-und-jahr.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542205
logo: gruner-und-jahr
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081636
client_url: 'https://company.rtl.com/de/business-units/overview/rtl-deutschland/unternehmen/gruner-jahr-deutschland-gmbh/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/hb-fuller.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 57eaf692-c94c-454d-a9cf-aabc4a920c0f
blueprint: client
title: 'H.B. Fuller'
url: 'https://www.hbfuller.com'
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542215
logo: clients/hb-fuller.svg
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081658
logo: hb-fuller
client_url: 'https://www.hbfuller.com'
---
7 changes: 4 additions & 3 deletions content/collections/clients/kumi-health.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 3e0b26d9-b68f-4142-b994-f160926abd98
blueprint: client
title: 'Kumi Health'
url: 'https://kumihealth.de'
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542223
logo: clients/kumi.svg
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081679
logo: kumi
client_url: 'https://kumihealth.de/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/maklaro.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: e1cf77b6-0d15-4dc7-ba94-ac019d078672
blueprint: client
title: Maklaro
url: 'https://www.maklaro.de'
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542231
logo: clients/maklaro.svg
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081700
logo: maklaro
client_url: 'https://www.maklaro.de/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/mercedes-benz.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: f1352951-8235-4e2c-8814-9848530a9698
blueprint: client
title: Mercedes-Benz
url: 'https://www.mercedes-benz.com'
logo: clients/mercedes-benz.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725550946
logo: mercedes-benz
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081716
client_url: 'https://mercedes-benz.com'
---
7 changes: 4 additions & 3 deletions content/collections/clients/miniatur-wunderland.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 9485c457-26e6-4e52-bf32-e951b5c2079a
blueprint: client
title: 'Miniatur Wunderland'
url: 'https://www.miniatur-wunderland.de'
logo: clients/miniatur-wunderland.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542241
logo: miniatur-wunderland
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081800
client_url: 'https://www.miniatur-wunderland.de/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/peta.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: c8a78e94-5afc-4424-8734-1ff97e9fa716
blueprint: client
title: PETA
url: 'https://www.peta.org'
logo: clients/peta.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542251
logo: peta
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081822
client_url: 'https://www.gemeinsam-fuer-tierrechte.de/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/prokon.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 74bdba6d-1c52-4bda-a1c2-5cfb6e599f66
blueprint: client
title: Prokon
url: 'https://www.prokon.net'
logo: clients/prokon.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725554107
logo: prokon
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081841
client_url: 'https://www.prokon.energy/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/reeperbahn-festival.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 92048385-7a01-4d02-a48e-abb6c14bcaeb
blueprint: client
title: 'Reeperbahn Festival'
url: 'https://www.reeperbahnfestival.com'
logo: clients/reeperbahn-festival.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542259
logo: reeperbahn-festival
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081866
client_url: 'https://www.reeperbahnfestival.com/'
---
7 changes: 4 additions & 3 deletions content/collections/clients/schaeffler.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ id: 0711b0ac-5647-477a-9913-67a69a98266d
blueprint: client
title: Schaeffler
url: 'https://www.schaeffler.com'
logo: clients/schaeffler.svg
updated_by: b7c7f4d4-e810-47c4-8310-994d4d84346a
updated_at: 1725542270
logo: schaeffler
updated_by: 7b2bf1c2-0b8e-44d9-a774-98d3580bee37
updated_at: 1729081890
client_url: 'https://www.schaeffler.de/de/'
---
Loading
Loading