Skip to content

Commit

Permalink
Merge pull request #677 from biglotteryfund/climate-action-fund
Browse files Browse the repository at this point in the history
Key initiatives section created
  • Loading branch information
joshgriff465 authored Jul 27, 2021
2 parents 18caa25 + e2554ee commit 14ebae5
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
27 changes: 27 additions & 0 deletions config/element-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Biglotteryfund\ResearchDocument;
use Biglotteryfund\StrategicProgrammes;
use Biglotteryfund\Updates;
use Biglotteryfund\KeyInitiatives;
use craft\elements\Category;
use craft\elements\Entry;
use craft\elements\Tag;
Expand Down Expand Up @@ -541,6 +542,31 @@ function getStrategicProgrammes($locale)
];
}

/**
* API Endpoint: Get Strategic Programme
* Get full details of a single strategic programme
* or one of its children
*/
function getKeyInitiatives($locale, $slug, $childPageSlug = null)
{
normaliseCacheHeaders();

return [
'serializer' => 'jsonApi',
'elementType' => Entry::class,
'criteria' => [
'slug' => $childPageSlug ? $childPageSlug : $slug,
'section' => 'keyInitiatives',
'site' => $locale,
'status' => EntryHelpers::getVersionStatuses(),
],
'one' => true,
'transformer' => new KeyInitiatives($locale),
'flexibleContent' => ContentHelpers::extractFlexibleContent($entry, $locale),

];
}

/**
* API Endpoint: Get Strategic Programme
* Get full details of a single strategic programme
Expand Down Expand Up @@ -872,6 +898,7 @@ function getMerchandise($locale)
'api/v1/<locale:en|cy>/strategic-programmes/<slug:{slug}>/<childPageSlug:{slug}>' => getStrategicProgramme,
'api/v1/<locale:en|cy>/hero-image/<slug>' => getHeroImage,
'api/v1/<locale:en|cy>/homepage' => getHomepage,
'api/v1/<locale:en|cy>/key-initiatives' => getKeyInitiatives,
'api/v1/<locale:en|cy>/listing' => getListing,
'api/v1/<locale:en|cy>/data' => getDataPage,
'api/v1/<locale:en|cy>/aliases' => getAliases,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
fieldLayouts:
e80349e0-75c6-4245-80cd-e4bf4d9f2b4b:
tabs:
-
elements:
-
autocapitalize: true
autocomplete: false
autocorrect: true
class: null
disabled: false
id: null
instructions: null
label: null
max: null
min: null
name: null
orientation: null
placeholder: null
readonly: false
requirable: false
size: null
step: null
tip: null
title: null
type: craft\fieldlayoutelements\EntryTitleField
warning: null
width: 100
-
fieldUid: 1620ec3b-4d1d-4929-bd17-68cf9f224a53
instructions: ''
label: ''
required: '1'
tip: null
type: craft\fieldlayoutelements\CustomField
warning: null
width: 100
-
fieldUid: 40755bc8-380a-49b7-9f5b-786c5e1e6bbe
instructions: ''
label: ''
required: ''
tip: null
type: craft\fieldlayoutelements\CustomField
warning: null
width: 100
name: Content
sortOrder: 1
handle: contentPage
hasTitleField: true
name: 'Content Page'
section: 0be940dc-4e56-43bb-909f-910e8a7a287e
sortOrder: 1
titleFormat: null
titleTranslationKeyFormat: null
titleTranslationMethod: site
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
enableVersioning: true
handle: keyInitiatives
name: 'Key initiatives'
previewTargets:
-
__assoc__:
-
- label
- 'Primary entry page'
-
- urlFormat
- '{url}'
-
- refresh
- '1'
propagationMethod: all
siteSettings:
81de1ac6-1a0b-40e6-b99c-42b99e5dc777:
enabledByDefault: true
hasUrls: true
template: null
uriFormat: '{parent.uri ? parent.uri : ''key-initiatives''}/{slug}'
d0635f95-a563-4f66-9195-33da0eb644d5:
enabledByDefault: true
hasUrls: true
template: null
uriFormat: '{parent.uri ? parent.uri : ''key-initiatives''}/{slug}'
structure:
maxLevels: null
uid: baa873bc-41df-4153-997f-cc269b6e350a
type: structure
26 changes: 26 additions & 0 deletions lib/KeyInitiatives.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Biglotteryfund;

use Biglotteryfund\EntryHelpers;
use Biglotteryfund\Images;
use craft\elements\Entry;
use League\Fractal\TransformerAbstract;

class KeyInitiatives extends TransformerAbstract
{
public function __construct($locale)
{
$this->locale = $locale;
}

public function transform(Entry $entry)
{
$commonFields = ContentHelpers::getCommonFields($entry, $this->locale);

if ($entry->type->handle === 'contentPage') {
return ContentHelpers::getFlexibleContentPage($entry, $this->locale);
}

}
}

0 comments on commit 14ebae5

Please sign in to comment.