Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
fix: deprecated municipio function images gone
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasNorin committed Apr 5, 2024
1 parent 7a086bf commit 2f0a5f1
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 11 deletions.
3 changes: 2 additions & 1 deletion source/php/Controller/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ProjectManagerIntegration\Helper\Municipio;
use ProjectManagerIntegration\Helper\WP;
use ProjectManagerIntegration\UI\RelatedPosts;
use ProjectManagerIntegration\UI\FeaturedImage;

class Challenge
{
Expand Down Expand Up @@ -45,7 +46,7 @@ public function singleViewController($data)
{
$data['challenge'] = [
'hero' => [
'image' => municipio_get_thumbnail_source(null, array(1440, 416)),
'image' => FeaturedImage::getFeaturedImage(),
'meta' => get_post_type_object(get_post_type())->labels->singular_name,
'title' => get_the_title(),
],
Expand Down
5 changes: 3 additions & 2 deletions source/php/Controller/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ProjectManagerIntegration\Helper\WP;
use ProjectManagerIntegration\UI\RelatedPosts;
use ProjectManagerIntegration\UI\FeaturedImage;

class Platform
{
Expand All @@ -19,10 +20,10 @@ public function singleViewController($data)
if (!is_singular('platform')) {
return $data;
}

$data['platform'] = [
'hero' => [
'image' => municipio_get_thumbnail_source(null, array(1440,416)),
'image' => FeaturedImage::getFeaturedImage(),
'meta' => get_post_type_object(get_post_type())->labels->singular_name,
'title' => get_the_title(),
],
Expand Down
8 changes: 4 additions & 4 deletions source/php/Controller/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use ProjectManagerIntegration\UI\ProjectStatus;
use ProjectManagerIntegration\UI\RelatedPosts;
use ProjectManagerIntegration\UI\Gallery;
use ProjectManagerIntegration\UI\FeaturedImage;

class Project
{
Expand All @@ -21,8 +22,6 @@ public function __construct()

public function singleViewController($data)
{
$fields = get_fields();

$data['project'] = array_merge(
WP::getPostMeta(),
[
Expand All @@ -47,6 +46,7 @@ public function singleViewController($data)
'updated' => __('Last updated', PROJECTMANAGERINTEGRATION_TEXTDOMAIN),
],
'archive' => get_post_type_archive_link(get_post_type()),
'image' => FeaturedImage::getFeaturedImage(),

]
);
Expand All @@ -59,7 +59,7 @@ public function singleViewController($data)
public function mapProjectPostData(object $post): object
{
$post->project = (object) [
'statusBar' => ProjectStatus::create($post->id),
// 'statusBar' => ProjectStatus::create($post->id),
'category' => WP::getPostTermsJoined(['challenge_category'], $post->id) ?? '',
'taxonomies' => WP::getPostTermsJoined(['project_sector', 'project_technology'], $post->id)
];
Expand All @@ -77,7 +77,7 @@ protected static function createProjectCardPosts(array $posts): array
];

if (!$post->thumbnail) {
$post->thumbnail = municipio_get_thumbnail_source($post->id, "sm", '12:16');
$post->thumbnail = FeaturedImage::getFeaturedImage($post->id);
}

if (!$post->permalink) {
Expand Down
5 changes: 4 additions & 1 deletion source/php/Shortcodes/PostTypeLink/PostTypeLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ProjectManagerIntegration\Shortcodes\PostTypeLink;

use ProjectManagerIntegration\Helper\Blade;
use ProjectManagerIntegration\UI\FeaturedImage;

class PostTypeLink
{
Expand All @@ -25,12 +26,14 @@ public function shortcodeController($atts)
$post = get_post($atts['id']);

if ($post) {
$image = FeaturedImage::getFeaturedImage($post->ID, [75, 56]);

$atts = shortcode_atts(array(
'id' => 0,
'title' => $post->post_title,
'meta' => get_post_type_object($post->post_type)->labels->singular_name,
'url' => get_permalink($post->ID),
'imageUrl' => municipio_get_thumbnail_source($post->ID, array(75, 56), '3:2'),
'imageUrl' => !empty($image['src']) ? $image['src'] : false,
'buttonText' => __('Open', PROJECTMANAGERINTEGRATION_TEXTDOMAIN),
'blank' => 0
), $atts);
Expand Down
18 changes: 18 additions & 0 deletions source/php/UI/FeaturedImage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace ProjectManagerIntegration\UI;

class FeaturedImage
{
public static function getFeaturedImage(?int $id = null, array $size = [854, 480])
{
$id = $id ?? get_queried_object_id();
if (!empty($id) && class_exists('Municipio\Helper\Image')) {
$image = \Municipio\Helper\Image::getImageAttachmentData(get_post_thumbnail_id($id), $size);

return $image;
}

return false;
}
}
2 changes: 1 addition & 1 deletion views/partials/challenge/hero.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@hero([
'image' => $challenge['hero']['image'],
'image' => !empty($challenge['hero']['image']['src']) ? $challenge['hero']['image']['src'] : null,
'title' => $challenge['hero']['title'],
'meta' => $challenge['hero']['meta']
])
Expand Down
2 changes: 1 addition & 1 deletion views/partials/platform/hero.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@hero([
'image' => $platform['hero']['image'],
'image' => !empty($platform['hero']['image']['src']) ? $platform['hero']['image']['src'] : null,
'title' => $platform['hero']['title'],
'meta' => $platform['hero']['meta'],
])
Expand Down
2 changes: 1 addition & 1 deletion views/partials/project/hero.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@hero([
'image' => municipio_get_thumbnail_source($post->id, [456, 342], '4:3'),
'image' => !empty($project['image']['src']) ? $project['image']['src'] : null,
'heroView' => 'twoColumn',
'background' => '#f7f7f7',
'textColor' => 'black'
Expand Down

0 comments on commit 2f0a5f1

Please sign in to comment.