Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: post module news item #732

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions source/php/AcfFields/json/mod-posts-displau.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@
"field": "field_628e0ffba7da4",
"operator": "==",
"value": "1"
},
{
"field": "field_571dfd4c0d9d9",
"operator": "!=",
"value": "news"
}
]
],
Expand All @@ -289,10 +294,10 @@
"card": "Card"
},
"default_value": "block",
"allow_null": 0,
"return_format": "value",
"multiple": 0,
"allow_null": 0,
"ui": 0,
"return_format": "value",
"ajax": 0,
"placeholder": "",
"allow_custom": 0,
Expand Down Expand Up @@ -422,7 +427,8 @@
"allow_custom": 0,
"layout": "horizontal",
"toggle": 0,
"save_custom": 0
"save_custom": 0,
"custom_choice_button_text": "L\u00e4gg till nytt val"
},
{
"key": "field_62387e4b55b75",
Expand Down Expand Up @@ -789,4 +795,4 @@
"acfe_meta": "",
"acfe_note": ""
}]

2 changes: 1 addition & 1 deletion source/php/AcfFields/json/mod-posts-source.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
},
"choices": [],
"default_value": [],
"return_format": "value",
"return_format": "array",
"multiple": 1,
"allow_null": 0,
"ui": 0,
Expand Down
59 changes: 31 additions & 28 deletions source/php/AcfFields/php/mod-posts-displau.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php


if (function_exists('acf_add_local_field_group')) {

acf_add_local_field_group(array(

if (function_exists('acf_add_local_field_group')) {
acf_add_local_field_group(array(
'key' => 'group_571dfd3c07a77',
'title' => __('Data display', 'modularity'),
'fields' => array(
Expand Down Expand Up @@ -32,7 +30,7 @@
'segment' => __('Segment', 'modularity'),
'collection' => __('Collection', 'modularity'),
),
'default_value' => __('list', 'modularity'),
'default_value' => 'list',
'return_format' => 'value',
'allow_null' => 0,
'other_choice' => 0,
Expand Down Expand Up @@ -282,6 +280,11 @@
'operator' => '==',
'value' => '1',
),
1 => array(
'field' => 'field_571dfd4c0d9d9',
'operator' => '!=',
'value' => 'news',
),
),
),
'wrapper' => array(
Expand All @@ -293,11 +296,11 @@
'block' => __('Block', 'modularity'),
'card' => __('Card', 'modularity'),
),
'default_value' => __('block', 'modularity'),
'allow_null' => 0,
'default_value' => 'block',
'return_format' => 'value',
'multiple' => 0,
'allow_null' => 0,
'ui' => 0,
'return_format' => 'value',
'ajax' => 0,
'placeholder' => '',
'allow_custom' => 0,
Expand Down Expand Up @@ -373,7 +376,7 @@
'grid-md-4' => __('3', 'modularity'),
'grid-md-3' => __('4', 'modularity'),
),
'default_value' => __('grid-md-12', 'modularity'),
'default_value' => 'grid-md-12',
'return_format' => 'value',
'multiple' => 0,
'allow_null' => 0,
Expand All @@ -383,7 +386,7 @@
'allow_custom' => 0,
'search_placeholder' => '',
),
8 => array(
7 => array(
'key' => 'field_571e01e7f246c',
'label' => __('Fields', 'modularity'),
'name' => 'posts_fields',
Expand Down Expand Up @@ -418,18 +421,19 @@
'reading_time' => __('Show reading time', 'modularity'),
),
'default_value' => array(
0 => __('date', 'modularity'),
1 => __('excerpt', 'modularity'),
2 => __('title', 'modularity'),
3 => __('image', 'modularity'),
0 => 'date',
1 => 'excerpt',
2 => 'title',
3 => 'image',
),
'return_format' => 'value',
'allow_custom' => 0,
'layout' => 'horizontal',
'toggle' => 0,
'save_custom' => 0,
'custom_choice_button_text' => 'Lägg till nytt val',
),
9 => array(
8 => array(
'key' => 'field_62387e4b55b75',
'label' => __('Date source', 'modularity'),
'name' => 'posts_date_source',
Expand Down Expand Up @@ -465,7 +469,7 @@
'allow_custom' => 0,
'search_placeholder' => '',
),
10 => array(
9 => array(
'key' => 'field_591176fff96d6',
'label' => __('Hide the title column', 'modularity'),
'name' => 'posts_hide_title_column',
Expand Down Expand Up @@ -493,7 +497,7 @@
'ui_on_text' => '',
'ui_off_text' => '',
),
11 => array(
10 => array(
'key' => 'field_57e3bcae3826e',
'label' => __('Title column label', 'modularity'),
'name' => 'title_column_label',
Expand Down Expand Up @@ -526,7 +530,7 @@
'prepend' => '',
'append' => '',
),
12 => array(
11 => array(
'key' => 'field_571f5776592e6',
'label' => __('List column labels', 'modularity'),
'name' => 'posts_list_column_titles',
Expand Down Expand Up @@ -581,7 +585,7 @@
),
),
),
13 => array(
12 => array(
'key' => 'field_59197c6dafb31',
'label' => __('Allow freetext filtering', 'modularity'),
'name' => 'allow_freetext_filtering',
Expand Down Expand Up @@ -609,7 +613,7 @@
'ui_on_text' => '',
'ui_off_text' => '',
),
14 => array(
13 => array(
'key' => 'field_5be480e163246',
'label' => __('Highlight post', 'modularity'),
'name' => 'posts_highlight',
Expand Down Expand Up @@ -637,7 +641,7 @@
'ui_on_text' => __('Enabled', 'modularity'),
'ui_off_text' => __('Disabled', 'modularity'),
),
15 => array(
14 => array(
'key' => 'field_5bdb0d4217e91',
'label' => __('Date format', 'modularity'),
'name' => 'posts_date_format',
Expand Down Expand Up @@ -668,7 +672,7 @@
'default' => __('Default timestamp', 'modularity'),
'readable' => __('Readable timestamp', 'modularity'),
),
'default_value' => __('default', 'modularity'),
'default_value' => 'default',
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
Expand All @@ -678,7 +682,7 @@
'allow_custom' => 0,
'search_placeholder' => '',
),
16 => array(
15 => array(
'key' => 'field_5bd8575106176',
'label' => __('Placeholder image', 'modularity'),
'name' => 'posts_placeholder',
Expand Down Expand Up @@ -718,7 +722,7 @@
'uploader' => '',
'acfe_thumbnail' => 0,
),
17 => array(
16 => array(
'key' => 'field_628e0f242aa5f',
'label' => __('Ratio', 'modularity'),
'name' => 'ratio',
Expand Down Expand Up @@ -752,7 +756,7 @@
'4:3' => __('4:3', 'modularity'),
'12:16' => __('12:16', 'modularity'),
),
'default_value' => __('4:3', 'modularity'),
'default_value' => '4:3',
'allow_null' => 0,
'multiple' => 0,
'ui' => 0,
Expand Down Expand Up @@ -794,5 +798,4 @@
'acfe_meta' => '',
'acfe_note' => '',
));

}
}
Expand Down
2 changes: 1 addition & 1 deletion source/php/AcfFields/php/mod-posts-source.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
),
'default_value' => array(
),
'return_format' => 'value',
'return_format' => 'array',
'multiple' => 1,
'allow_null' => 0,
'ui' => 0,
Expand Down
6 changes: 4 additions & 2 deletions source/php/Module/Posts/Helper/GetPosts.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ private function getPostsFromSelectedSites(array $fields, int $page):array {
if(!empty($fields['posts_data_network_sources'])) {
$posts = [];
$maxNumPages = 0;

foreach($fields['posts_data_network_sources'] as $site) {
switch_to_blog($site);
switch_to_blog($site['value']);
$wpQuery = new \WP_Query($this->getPostArgs($fields, $page));
$postsFromSite = $wpQuery->get_posts();

array_walk($postsFromSite, function($post) {
array_walk($postsFromSite, function($post) use ($site) {
// Add the original permalink to the post object for reference in network sources.
$post->originalPermalink = get_permalink($post->ID);
$post->originalSite = $site['label'];
});

$posts = array_merge($posts, $postsFromSite);
Expand Down
12 changes: 6 additions & 6 deletions source/php/Module/Posts/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ public function data(): array
$data['display_reading_time'] = !empty($this->fields['posts_fields']) && in_array('reading_time', $this->fields['posts_fields']) ?? false;

// Posts
$data['preamble'] = $this->fields['preamble'] ?? false;
$data['posts_fields'] = $this->fields['posts_fields'] ?? false;
$data['posts_date_source'] = $this->fields['posts_date_source'] ?? false;
$data['posts_data_post_type'] = $this->fields['posts_data_post_type'] ?? false;
$data['posts_data_source'] = $this->fields['posts_data_source'] ?? false;
$data['preamble'] = $this->fields['preamble'] ?? false;
$data['posts_fields'] = $this->fields['posts_fields'] ?? false;
$data['posts_date_source'] = $this->fields['posts_date_source'] ?? false;
$data['posts_data_post_type'] = $this->fields['posts_data_post_type'] ?? false;
$data['posts_data_source'] = $this->fields['posts_data_source'] ?? false;
$data['postsSources'] = $this->fields['posts_data_network_sources'] ?? [];

$postsAndPaginationData = $this->getPostsAndPaginationData();
$data['posts'] = $postsAndPaginationData['posts'];
Expand Down Expand Up @@ -420,7 +421,6 @@ public function replaceDeprecatedTemplate($templateSlug)
// Add deprecated template/replacement slug to array.
$deprecatedTemplates = [
'items' => 'index',
'news' => 'index'
];

if (array_key_exists($templateSlug, $deprecatedTemplates)) {
Expand Down
23 changes: 23 additions & 0 deletions source/php/Module/Posts/TemplateController/NewsTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Modularity\Module\Posts\TemplateController;

/**
* Class NewsTemplate
*
* Template controller for rendering posts as an index.
*
* @package Modularity\Module\Posts\TemplateController
*/
class NewsTemplate extends AbstractController
{
/**
* NewsTemplate constructor.
*
* @param \Modularity\Module\Posts\Posts $module Instance of the Posts module.
*/
public function __construct(\Modularity\Module\Posts\Posts $module)
{
parent::__construct($module);
}
}
14 changes: 14 additions & 0 deletions source/php/Module/Posts/views/news.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@includeWhen(!$hideTitle && !empty($postTitle), 'partials.post-title')
@includeWhen($preamble, 'partials.preamble')

<div class="o-grid{{ !empty($stretch) ? ' o-grid--stretch' : '' }}{{ !empty($noGutter) ? ' o-grid--no-gutter' : '' }}{{ (!empty($preamble)||(!$hideTitle && !empty($postTitle))) ? ' u-margin__top--4' : '' }}"
@if (!$hideTitle && !empty($postTitle)) aria-labelledby="{{ 'mod-posts-' . $ID . '-label' }}" @endif>
@if (!empty($posts))
@foreach ($posts as $post)
@include('partials.post.news-item', [
'posts_columns' => $loop->first && $highlight_first_column ? $highlight_first_column : $posts_columns,
'standing' => $loop->first && $highlight_first_column ? true : false
])
@endforeach
@endif
</div>
35 changes: 35 additions & 0 deletions source/php/Module/Posts/views/partials/post/news-item.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@newsItem([
'heading' => $post->postTitle,
'content' => $post->excerpt,
'image' => $post->image,
'date' => $post->postDateFormatted,
'readTime' => $post->readingTime,
'link' => $post->permalink,
'context' => ['module.posts.news-item'],
'hasPlaceholderImage' => $post->hasPlaceholderImage,
'classList' => [
$posts_columns
],
'standing' => $standing
])
@slot('headerLeftArea')
@if (count($postsSources) > 1 && !empty($post->originalSite))
@typography([
'element' => 'span',
'variant' => 'bold',
'classList' => ['u-margin__y--0', 'u-padding__right--1'],
])
{{ $post->originalSite }}
@endtypography

@endif
@if($post->termsUnlinked)
@tags([
'compress' => 4,
'tags' => $post->termsUnlinked,
'format' => false,
])
@endtags
@endif
@endslot
@endnewsItem
Loading