Skip to content

Commit

Permalink
Merge pull request #698 from waynestate/feature/extending-repository-…
Browse files Browse the repository at this point in the history
…framework

Feature/extending-repository - Created the framework for extending the promo repository for global promos, so we do not have to edit the promo repository file and upgrades are cleaner.
  • Loading branch information
breakdancingcat committed Feb 26, 2024
2 parents 7e0ec5f + dffde4b commit fc89cb6
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/Http/Controllers/ChildpageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public function index(Request $request): View

$request->data['base']['hero'] = $components['components'][$hero_key]['data'];

config(['base.hero_full_controllers' => ['ChildpageController']]);

unset($components['components'][$hero_key]);
}

Expand Down
16 changes: 16 additions & 0 deletions app/Repositories/PromoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ public function getBackToPromoPage($referer = null, $scheme = null, $host = null
*/
public function getRequestData(array $data)
{
/*
|--------------------------------------------------------------------------
| Do not edit this file!
|--------------------------------------------------------------------------
|
| Add to config/base.app Global Data => $global['all']['promos']['new_promo']
| - or -
| Extend this repository; copy and edit these stubs:
| stubs/extend-repository.stub => app/Repositories/PromosExtendedRepository.php
| stubs/extend-repository-styleguide.stub => styleguide/Repositories/PromosExtendedRepository.php
|
| Update config/base.app Global Data 'callbacks' and replace:
| '\Repositories\PromoRepository@getRequestData' => '\Repositories\PromosExtendedRepository@getRequestData'
|
*/

// Get the global promos config
$config = config('base.global');

Expand Down
6 changes: 5 additions & 1 deletion resources/views/components/hero.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
@if(!empty($base['layout']) && $base['layout'] === 'contained-hero')
@include('components/hero/banner-large')
@else
@include('components/hero/banner-small')
@if(config('base.layout') === 'contained-hero')
@include('components/hero/banner-contained')
@else
@include('components/hero/banner-small')
@endif
@endif
@endif
@endif
Expand Down
58 changes: 58 additions & 0 deletions stubs/extend-repository-styelguide.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Styleguide\Repositories;

use App\Repositories\PromosExtendedRepository as Repository;
use Faker\Factory;
use Factories\GenericPromo;

class PromosExtendedRepository extends Repository
{
/**
* Construct the factory.
*/
public function __construct(Factory $faker)
{
$this->faker = $faker->create();
}

/**
* {@inheritdoc}
*/
public function getRequestData(array $data)
{
/*
// Extend a Styleguide repository
$promoRepoRequestData = app()->make(PromoRepository::class)->getRequestData($data);

// Example page specific Hero
if(!empty($data['page']['id']) && $data['page']['id'] === 99999) {
$exampleHero = app(HeroImage::class)->create(1, false, [
'option' => 'Half',
'relative_url' => '/styleguide/image/1600x580?text=1920x1080',
'filename_url' => '/styleguide/image/1600x580?text=1920x1080',
]);
} else {
$hero = $promoRepoRequestdata['hero'];
}

$page_field_label = [];
// Example addition to the Global Promos data
if(!empty($data['page']['id']) && $data['page']['id'] === 99998) {
$page_field_label = app(GenericPromo::class)->create(3, false, [
'relative_url' => '/styleguide/image/800x600',
'secondary_relative_url' => '/styleguide/image/100x100',
]);
}

/*
return [
'contact' => $promoRepoRequestData['contact'],
'social' => $promoRepoRequestData['social'],
'hero' => $hero,
'under_menu' => $promoRepoRequestData['under_menu'],
'page_field_label' => $page_field_label,
];
*/
}
}
35 changes: 35 additions & 0 deletions stubs/extend-repository.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace App\Repositories;

use Contracts\Repositories\PromosExtendedRepositoryContract;

class PromosExtendedRepository extends PromoRepository implements PromosExtendedRepositoryContract
{
/**
* {@inheritdoc}
*/
public function createGlobalPromoGroupReference(array $data, array $config, array $groups)
{
$group_reference = parent::createGlobalPromoGroupReference($data, $config, $groups);

// Custom page field
if (!empty($data['data']['page_field_promo_group_id']) && ! array_key_exists($data['data']['page_field_promo_group_id'], $group_reference)) {
$group_reference[$data['data']['page_field_promo_group_id']] = 'page_field_label';
}

return $group_reference;
}

/**
* {@inheritdoc}
*/
public function createGlobalPromoGroupConfig(array $data, array $config, array $groups)
{
$group_config = parent::createGlobalPromoGroupConfig($data, $config, $groups);

$group_config['page_field_label'] = 'randomize|limit:4|{$page_id}';

return $group_config;
}
}
18 changes: 18 additions & 0 deletions styleguide/Repositories/PromoRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ public function __construct(Factory $faker)
*/
public function getRequestData(array $data)
{
/*
|--------------------------------------------------------------------------
| Do not edit this file!
|--------------------------------------------------------------------------
|
| Add to config/base.app Global Data => $global['all']['promos']['new_promo']
| - or -
| Extend this repository; copy and edit these stubs:
| stubs/extend-repository.stub => app/Repositories/PromosExtendedRepository.php
| stubs/extend-repository-styleguide.stub => styleguide/Repositories/PromosExtendedRepository.php
|
| Update config/base.app Global Data 'callbacks' and replace:
| '\Repositories\PromoRepository@getRequestData' => '\Repositories\PromosExtendedRepository@getRequestData'
|
*/

// Define the pages that have under menu promos: page_id => quanity
$under_menu_page_ids = [
114100 => 3, // Styleguide
Expand Down Expand Up @@ -71,6 +87,8 @@ public function getRequestData(array $data)
'option' => 'Half',
'relative_url' => '/styleguide/image/1920x1080',
]),
// Childpage
101100 => app(HeroImage::class)->create(1, false),
];

// Only pull hero promos if they match the page ids that are specificed
Expand Down

0 comments on commit fc89cb6

Please sign in to comment.