Skip to content

Commit

Permalink
Adding page-content and heading components to styleguide components area
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdancingcat committed Jan 23, 2024
1 parent ea52c58 commit 346a9b3
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/Repositories/ModularPageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public function getModularComponents(array $data): array
}
$modularComponents[$name]['data'] = $articles['articles'] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name];
} elseif(Str::startsWith($name, 'page-content') || Str::startsWith($name, 'page-heading')) {
} elseif(Str::startsWith($name, 'page-content') || Str::startsWith($name, 'heading')) {
// If there's JSON but no news, events or promo data, assign the component array as data
// Page-content and page-heading components
// Page-content and heading components
$modularComponents[$name]['data'][] = $components['components'][$name] ?? [];
$modularComponents[$name]['component'] = $components['components'][$name] ?? [];
unset($modularComponents[$name]['component']['heading']);
Expand Down
10 changes: 10 additions & 0 deletions resources/views/components/heading.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{--
Label: "heading-1"
Data: {
"heading": "My heading"
}
--}}

@foreach ($data as $item)
<h2 class="mt-0 -mb-3" id="{{ Str::slug($item['heading']) }}">{{ $item['heading'] }}</h2>
@endforeach
10 changes: 0 additions & 10 deletions resources/views/components/page-heading.blade.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,14 @@ public function index(Request $request): View
],
],

'page-heading-1' => [
'heading-1' => [
'data' => [
0 => [
'heading' => 'News',
],
],
'component' => [
'filename' => 'page-heading',
'filename' => 'heading',
],
],

Expand All @@ -189,14 +189,14 @@ public function index(Request $request): View
],
],

'page-heading-2' => [
'heading-2' => [
'data' => [
0 => [
'heading' => 'Events',
],
],
'component' => [
'filename' => 'page-heading',
'filename' => 'heading',
],
],

Expand Down
68 changes: 68 additions & 0 deletions styleguide/Http/Controllers/ComponentsPageContentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Styleguide\Http\Controllers;

use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class ComponentsPageContentController extends Controller
{
/**
* Display page content from a page field
*/
public function index(Request $request): View
{
$request->data['base']['page']['content']['main'] = '
<p style="margin-top: -1rem;">Move the CMS page content to the location of the <code>modular-page-content</code> page field.</p>
';

$component_configuration = '
<table class="mt-2">
<thead>
<tr>
<th>Page field</th>
<th>Data</th>
</tr>
</thead>
<tr>
<td>
<pre class="w-full">modular-page-content</pre>
</td>
<td>
<pre class="w-full" tabindex="0">
{}
</pre>
</td>
</tr>
</table>
';

$components['components'] = [
'page-content' => [
'data' => [
0 => [
'filename' => 'page-content',
],
],
'component' => [
'filename' => 'page-content',
],
],
'accordion-1' => [
'data' => [
0 => [
'title' => 'Component configuration',
'promo_item_id' => 'componentConfiguration',
'description' => $component_configuration,
],
],
'component' => [
'filename' => 'accordion',
],
],
];

return view('childpage', merge($request->data, $components));
}
}
91 changes: 91 additions & 0 deletions styleguide/Http/Controllers/HeadingComponentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace Styleguide\Http\Controllers;

use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Factories\GenericPromo;
use Factories\Event;

class HeadingComponentController extends Controller
{
/**
* Display a page heading from a page field
*/
public function index(Request $request): View
{
$request->data['base']['page']['content']['main'] = '
<p>Add a page heading that spans an entire row. Suggested to use over two related columns, like an "Events" heading over a promo-column featured image, and an events-column. You would not use this when you can add a heading to an individual component.</p>
';

$component_configuration = '
<table class="mt-2">
<thead>
<tr>
<th>Page field</th>
<th>Data</th>
</tr>
</thead>
<tr>
<td>
<pre class="w-full">modular-heading</pre>
</td>
<td>
<pre class="w-full" tabindex="0">
{
"heading": "My heading"
}
</pre>
</td>
</tr>
</table>
';

$components['components'] = [
'accordion-1' => [
'data' => [
0 => [
'title' => 'Component configuration',
'promo_item_id' => 'componentConfiguration',
'description' => $component_configuration,
],
],
'component' => [
'filename' => 'accordion',
],
],
'heading-1' => [
'data' => [
0 => [
'heading' => 'My example heading',
],
],
'component' => [
'filename' => 'heading',
],
],
'events-column' => [
'data' => app(Event::class)->create(4, false),
'component' => [
'filename' => 'events-column',
'calendar_url' => '/myurl'
],
],
'promo-column-2' => [
'data' => app(GenericPromo::class)->create(1, false, [
'title' => 'Featured event (promo column)',
'filename_url' => '/styleguide/image/600x600',
'description' => '',
]),
'component' => [
'heading' => '',
'filename' => 'promo-column',
'gradientOverlay' => true,
],
],
];

return view('childpage', merge($request->data, $components));
}
}
25 changes: 25 additions & 0 deletions styleguide/Pages/ComponentsPageContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Styleguide\Pages;

use Factories\Page as PageFactory;

class ComponentsPageContent extends Page
{
/**
* {@inheritdoc}
*/
public function getPageData()
{
return app(PageFactory::class)->create(1, true, [
'page' => [
'controller' => 'ComponentsPageContentController',
'title' => 'Page content',
'id' => 123100,
'content' => [
'main' => '',
],
],
]);
}
}
25 changes: 25 additions & 0 deletions styleguide/Pages/HeadingComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Styleguide\Pages;

use Factories\Page as PageFactory;

class HeadingComponent extends Page
{
/**
* {@inheritdoc}
*/
public function getPageData()
{
return app(PageFactory::class)->create(1, true, [
'page' => [
'controller' => 'HeadingComponentController',
'title' => 'Heading',
'id' => 122100,
'content' => [
'main' => '',
],
],
]);
}
}
20 changes: 20 additions & 0 deletions styleguide/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@
"relative_url": "/styleguide/eventlisting",
"submenu": []
},
"122100": {
"menu_item_id": 122100,
"is_active": 1,
"page_id": 122100,
"target": "",
"display_name": "Heading",
"class_name": "",
"relative_url": "/styleguide/headingcomponent",
"submenu": []
},
"105100": {
"menu_item_id": 105100,
"is_active": 1,
Expand Down Expand Up @@ -281,6 +291,16 @@
"relative_url": "/styleguide/iconscomponent",
"submenu": []
},
"123100": {
"menu_item_id": 123100,
"is_active": 1,
"page_id": 123100,
"target": "",
"display_name": "Page content",
"class_name": "",
"relative_url": "/styleguide/components/pagecontent",
"submenu": []
},
"108100": {
"menu_item_id": 108100,
"is_active": 1,
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Repositories/ModularPageRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ public function get_modular_page_components_page_heading_and_page_content(): voi
],
'data' => [
'modular-page-content' => '{}',
'modular-page-heading' => '{"heading": "Test"}',
'modular-heading' => '{"heading": "Test"}',
],
]);

// Run the promos through the repository
$components = app(ModularPageRepository::class)->getModularComponents($data);

$this->assertArrayHasKey('data', $components['page-content']);
$this->assertArrayHasKey('heading', $components['page-heading']['data'][0]);
$this->assertTrue(empty($components['page-heading']['component']['heading']));
$this->assertArrayHasKey('heading', $components['heading']['data'][0]);
$this->assertTrue(empty($components['heading']['component']['heading']));
}

#[Test]
Expand Down

0 comments on commit 346a9b3

Please sign in to comment.