Skip to content

Commit

Permalink
refactor: render posts module segment from municipio
Browse files Browse the repository at this point in the history
  • Loading branch information
thorbrink committed Nov 11, 2024
1 parent 106928c commit c6515a5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
19 changes: 12 additions & 7 deletions source/php/Module/Posts/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,20 @@ private function renderPostObject(PostObjectInterface $postObject, PostObjectRen
* @return array
*/
protected function getRendererConfig(Appearance $appearance):array {

if($appearance === Appearance::CollectionItem) {
return [
return match($appearance) {
Appearance::CollectionItem => [
'displayFeaturedImage' => in_array('image', $this->fields['posts_fields'] ?? []),
'gridColumnClass' => $this->fields['posts_columns'] ?? [],
];
}

return [];
],
Appearance::SegmentGridItem => [
'reveseColumns' => (bool)(int)$this->fields['image_position'] ?? true,
'gridColumnClass' => $this->fields['posts_columns'] ?? [],
],
Appearance::SegmentSliderItem => [
'reveseColumns' => (bool)(int)$this->fields['image_position'] ?? true,
],
default => [],
};
}

/**
Expand Down
6 changes: 1 addition & 5 deletions source/php/Module/Posts/views/segment.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
@if($posts)
<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>
@foreach ($posts as $post)
<div class="{{ $posts_columns }}">
@include('partials.post.segment')
</div>
@endforeach
{!! $renderPosts(\Municipio\PostObject\PostObjectRenderer\Appearances\Appearance::SegmentGridItem) !!}
</div>

@include('partials.more')
Expand Down
29 changes: 18 additions & 11 deletions source/php/Module/Posts/views/slider.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,24 @@
]
])
@foreach ($posts as $key => $post)
@slider__item([
'classList' => ['c-slider__item--post']
])
@if ($postsDisplayAs === 'index' || $postsDisplayAs === 'items' || $postsDisplayAs === 'news')
@include('partials.slider.item.index')
@else
@include('partials.slider.item.' . $postsDisplayAs, [
'display_reading_time' => $display_reading_time,
])
@endif
@endslider__item

@if($postsDisplayAs === 'segment')
{!! $renderPosts(\Municipio\PostObject\PostObjectRenderer\Appearances\Appearance::SegmentSliderItem) !!}
@else

@slider__item([
'classList' => ['c-slider__item--post']
])
@if ($postsDisplayAs === 'index' || $postsDisplayAs === 'items' || $postsDisplayAs === 'news')
@include('partials.slider.item.index')
@else
@include('partials.slider.item.' . $postsDisplayAs, [
'display_reading_time' => $display_reading_time,
])
@endif
@endslider__item

@endif
@endforeach
@endslider

Expand Down

0 comments on commit c6515a5

Please sign in to comment.