Skip to content

Commit

Permalink
Merge pull request #198 from biglotteryfund/allow-external-links
Browse files Browse the repository at this point in the history
Allow external links to be used for flexible content related items
  • Loading branch information
mattandrews authored Oct 31, 2019
2 parents 75defc7 + c8fd707 commit 31b421b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
30 changes: 24 additions & 6 deletions config/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ categoryGroups:
structure:
maxLevels: '1'
uid: a0dbb9d0-734d-4e43-a0d5-56e09ff07075
dateModified: 1572521575
dateModified: 1572539557
email:
fromEmail: [email protected]
fromName: 'The National Lottery Community Fund Digital'
Expand Down Expand Up @@ -3071,7 +3071,7 @@ matrixBlockTypes:
0e47e9ca-df73-41e1-83a7-f333ec5fc1b2:
name: 'Related items'
handle: relatedItems
instructions: 'Choose some items to appear below the heading'
instructions: 'Choose some items to appear below the heading. You can choose either an Entry to link to, or an external URL instead. If you don''t choose either then the item won''t appear.'
searchable: false
translationMethod: site
translationKeyFormat: null
Expand All @@ -3085,6 +3085,8 @@ matrixBlockTypes:
columns:
259:
width: ''
265:
width: ''
260:
width: ''
258:
Expand Down Expand Up @@ -5827,7 +5829,7 @@ superTableBlockTypes:
9e3ed77a-cb3c-491b-b2ad-503715cbf99b:
name: Entry
handle: entry
instructions: 'Choose the entry to link to'
instructions: 'Choose the entry to link to. If you don''t choose one you must supply an External Link instead.'
searchable: false
translationMethod: site
translationKeyFormat: null
Expand Down Expand Up @@ -5872,6 +5874,19 @@ superTableBlockTypes:
columnType: text
contentColumnType: text
fieldGroup: null
b3ea3f1a-27d9-4c1e-b903-3ae96acc74b9:
name: 'External Link'
handle: externalLink
instructions: 'Optional – if you supply a link then this will be used instead of the entry. Use this to add a piece of content from an external, third-party website.'
searchable: false
translationMethod: site
translationKeyFormat: null
type: craft\fields\Url
settings:
placeholder: ''
maxLength: '255'
contentColumnType: string(255)
fieldGroup: null
fieldLayouts:
c352ef75-2b80-4c0e-8505-4164a11a4a65:
tabs:
Expand All @@ -5881,14 +5896,17 @@ superTableBlockTypes:
fields:
2184906d-f2b9-4d39-a094-bfa50ccf8271:
required: false
sortOrder: 3
sortOrder: 4
2dbee670-c961-4ea7-b503-cf23bce9541e:
required: false
sortOrder: 4
sortOrder: 5
9e3ed77a-cb3c-491b-b2ad-503715cbf99b:
required: true
required: false
sortOrder: 1
ab94c548-6f17-4790-b6dd-4c766143bee5:
required: false
sortOrder: 3
b3ea3f1a-27d9-4c1e-b903-3ae96acc74b9:
required: false
sortOrder: 2
aba74ecd-5c81-4302-90e6-f7e62956af82:
Expand Down
10 changes: 7 additions & 3 deletions lib/ContentHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,20 @@ public static function extractFlexibleContent(Entry $entry, $locale, $children =
'heading' => $block->heading
];
if (!empty($block->relatedItems->all())) {
$gridBlocks = array_map(function ($gridBlock) use ($locale) {
$gridBlocks = array_filter(array_map(function ($gridBlock) use ($locale) {
$externalUrl = $gridBlock->externalLink;
$entry = $gridBlock->entry->one();
if (!$entry && !$externalUrl) {
return false;
}
$entryBlock = [
'title' => $gridBlock->entryTitle ? $gridBlock->entryTitle : $entry->title,
'summary' => $gridBlock->entryDescription ?? null,
'linkUrl' => EntryHelpers::uriForLocale($entry->uri, $locale),
'linkUrl' => $externalUrl ? $externalUrl : EntryHelpers::uriForLocale($entry->uri, $locale),
'trailImage' => $gridBlock->entryImage ? self::buildTrailImage($gridBlock->entryImage) : null,
];
return $entryBlock;
}, $block->relatedItems->all());
}, $block->relatedItems->all()));
}
$data['content'] = $gridBlocks;
array_push($parts, $data);
Expand Down

0 comments on commit 31b421b

Please sign in to comment.