Skip to content

Commit

Permalink
Merge branch 'TMS-1098' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Jan 24, 2025
2 parents e482e03 + a9153c5 commit abbc0d4
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

- TMS-1097: Change navigation style
- TMS-1098: Add image-shape choices for pages hero-image

## [1.0.0] - 2025-01-22

Expand Down
2 changes: 1 addition & 1 deletion assets/styles/views/_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
content: '';
display: block;
position: absolute;
bottom: 0;
bottom: -10%;
left: 50%;
transform: translateX(-50%);
height: 50%;
Expand Down
11 changes: 2 additions & 9 deletions lib/ACF/AlterImageFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,8 @@ public function alter_fields( array $fields ): array {
$image_shape = ( new \Geniem\ACF\Field\Select( $s['image_shape']['title'] ) )
->set_key( 'image_image_shape' )
->set_name( 'image_shape' )
->set_choices( [
'default' => 'Ei muotoa',
'shape shape--summertime-sadness' => 'Apila',
'shape shape--drop' => 'Pisara',
'shape shape--soft-flower' => 'Nelireunainen kukka',
'shape shape--flower' => 'Kukka',
'shape shape--polygon' => 'Monikulmio',
'shape shape--rainbow' => 'Sateenkaari',
] );
->set_instructions( $s['image_shape']['instructions'] )
->set_choices( \apply_filters( 'tms_afc_image_shape_choices', [] ) );

$fields[] = $image_shape;
}
Expand Down
15 changes: 15 additions & 0 deletions lib/ACF/AlterPageSettingsFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ public function __construct() {
public function remove_hero_overlay_setting( $group ) {
try {
if ( $group->get_key() === 'fg_page_settings' ) {
$s = [
'image_shape' => [
'title' => 'Kuvan muoto',
'instructions' => 'Valitse kuvan muoto',
],
];

$image_shape = ( new \Geniem\ACF\Field\Select( $s['image_shape']['title'] ) )
->set_key( 'fg_page_settings_image_shape' )
->set_name( 'image_shape' )
->set_instructions( $s['image_shape']['instructions'] )
->set_choices( \apply_filters( 'tms_afc_image_shape_choices', [] ) );

$group->add_field( $image_shape );

$group->remove_field( 'fg_page_settings_remove_overlay' );
}
}
Expand Down
22 changes: 22 additions & 0 deletions lib/ThemeSupports.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,27 @@ public function hooks(): void {
'tms/theme/remove_custom_links',
'__return_false'
);

\add_filter( 'tms_afc_image_shape_choices', \Closure::fromCallable( [
$this,
'acf_image_shape_choices',
] ), 10, 3 );
}

/**
* ACF layout brand color field choices

Check failure on line 35 in lib/ThemeSupports.php

View workflow job for this annotation

GitHub Actions / phpcs-check

Expected 9 spaces before asterisk; 5 found
*

Check failure on line 36 in lib/ThemeSupports.php

View workflow job for this annotation

GitHub Actions / phpcs-check

Expected 9 spaces before asterisk; 5 found
* @return string[]

Check failure on line 37 in lib/ThemeSupports.php

View workflow job for this annotation

GitHub Actions / phpcs-check

Expected 9 spaces before asterisk; 5 found
*/
private function acf_image_shape_choices() : array {
return [
'default' => 'Ei muotoa',
'shape shape--summertime-sadness' => 'Apila',
'shape shape--drop' => 'Pisara',
'shape shape--soft-flower' => 'Nelireunainen kukka',
'shape shape--flower' => 'Kukka',
'shape shape--polygon' => 'Monikulmio',
'shape shape--rainbow' => 'Sateenkaari',
];
}
}
89 changes: 89 additions & 0 deletions models/page-extend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* Define the generic Page class.
*/

use TMS\Theme\Base\Traits\Components;
use TMS\Theme\Base\Settings;

/**
* The Page class.
*/
class PageExtend extends BaseModel {

use Components;

/**
* Hooks
*/
public function hooks() : void {

Check failure on line 19 in models/page-extend.php

View workflow job for this annotation

GitHub Actions / phpcs-check

There must not be a space before the colon in a return type declaration
\add_filter( 'tms/theme/breadcrumbs/show_breadcrumbs_in_header', fn() => false );
}

/**
* Hero image
*
* @return int|null
*/
public function hero_image() : ?int {

Check failure on line 28 in models/page-extend.php

View workflow job for this annotation

GitHub Actions / phpcs-check

There must not be a space before the colon in a return type declaration
return \has_post_thumbnail()
? \get_post_thumbnail_id()
: null;
}

/**
* Get post siblings.
*
* @return array|array[]|false
*/
public function post_siblings() {
$current_post_id = \get_the_ID();
$parent_post_id = \wp_get_post_parent_id( $current_post_id );

if ( ! Settings::get_setting( 'enable_sibling_navigation' ) || $parent_post_id === 0 ) {
return false;
}

$query_args = [
'post_type' => 'page',
'posts_per_page' => 100,
'post_parent' => $parent_post_id,
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'no_found_rows' => true,
'orderby' => 'menu_order title',
'order' => 'ASC',
];

$wp_query = new \WP_Query( $query_args );

if ( 1 >= count( $wp_query->posts ) ) {
return false;
}

return array_map( function ( $post ) use ( $current_post_id ) {
$post->permalink = \get_the_permalink( $post->ID );
$post->is_current = $post->ID === $current_post_id;

return $post;
}, $wp_query->posts );
}

/**
* Use overlay
*
* @return bool
*/
public function use_overlay() {
return \get_field( 'remove_overlay' ) === true ? false : true;
}

/**
* Use overlay
*
* @return bool
*/
public function image_shape() {
return \get_field( 'image_shape' ) ?? 'shape shape--rainbow';
}
}
2 changes: 1 addition & 1 deletion partials/views/page/page-hero.dust
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<section class="page__hero section is-relative pt-0 pb-0 has-width-100">
<div class="image-container">
{@image id=Page.hero_image size="large" class="shape shape--rainbow" /}
{@image id=Page.hero_image size="large" class="{Page.image_shape|attr}" /}
</div>
</section>

0 comments on commit abbc0d4

Please sign in to comment.