-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #698 from waynestate/feature/extending-repository-…
…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
Showing
6 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
]; | ||
*/ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters