Skip to content

Commit

Permalink
TMS-1054: Add 'remove hero overlay' -field to default page template
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Jun 19, 2024
1 parent 2037e9b commit b7beb89
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- TMS-1054: Add "remove hero overlay" -field to default page template

## [1.56.0] - 2024-06-12

- TMS-1050: Add if-statements into accordion script to prevent breaking other elements functionality
Expand Down
Binary file modified lang/fi.mo
Binary file not shown.
29 changes: 22 additions & 7 deletions lang/fi.po
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
msgid ""
msgstr ""
"Project-Id-Version: TMS Theme Base\n"
"POT-Creation-Date: 2024-05-29 12:01+0300\n"
"PO-Revision-Date: 2024-05-29 12:01+0300\n"
"POT-Creation-Date: 2024-06-18 15:17+0300\n"
"PO-Revision-Date: 2024-06-18 15:17+0300\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fi\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 3.4.2\n"
"X-Generator: Poedit 3.4.4\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: style.css\n"
Expand Down Expand Up @@ -75,13 +75,13 @@ msgid "Open map"
msgstr "Avaa kartta"

#: lib/ACF/FrontPageGroup.php:39 lib/ACF/OnepagerGroup.php:73
#: lib/ACF/PageGroup.php:41
#: lib/ACF/PageGroup.php:42
msgctxt "theme ACF"
msgid "Page Components"
msgstr "Sivun komponentit"

#: lib/ACF/FrontPageGroup.php:91 lib/ACF/OnepagerGroup.php:126
#: lib/ACF/PageGroup.php:142 lib/ACF/PostGroup.php:173
#: lib/ACF/PageGroup.php:194 lib/ACF/PostGroup.php:173
msgctxt "theme ACF"
msgid "Components"
msgstr "Komponentit"
Expand All @@ -101,6 +101,21 @@ msgctxt "theme ACF"
msgid "Asetukset"
msgstr ""

#: lib/ACF/PageGroup.php:43
msgctxt "theme ACF"
msgid "Page settings"
msgstr "Sivun asetukset"

#: lib/ACF/PageGroup.php:169
msgctxt "theme ACF"
msgid "Remove hero-image overlay"
msgstr "Poista herokuvan tummennus"

#: lib/ACF/PageGroup.php:170
msgctxt "theme ACF"
msgid "Remove hero-image overlay and move the heading under the hero-element"
msgstr "Poista herokuvan tummennus ja siirrä otsikkoteksti hero-elementin alle"

#: lib/ACF/PostGroup.php:129 models/single.php:161
msgid "Related posts"
msgstr "Liittyvät sisällöt"
Expand Down Expand Up @@ -301,11 +316,11 @@ msgstr ""
msgid "Links"
msgstr "Linkit"

#: lib/Eventz.php:314
#: lib/Eventz.php:354
msgid "Additional information"
msgstr "Lisätiedot"

#: lib/Eventz.php:331
#: lib/Eventz.php:371
msgid "Free"
msgstr "Maksuton"

Expand Down
27 changes: 21 additions & 6 deletions lang/tms-theme-base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
msgid ""
msgstr ""
"Project-Id-Version: TMS Theme Base\n"
"POT-Creation-Date: 2024-05-29 12:01+0300\n"
"POT-Creation-Date: 2024-06-18 15:17+0300\n"
"PO-Revision-Date: 2022-01-12 10:08+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"X-Generator: Poedit 3.4.2\n"
"X-Generator: Poedit 3.4.4\n"
"X-Poedit-Basepath: ..\n"
"X-Poedit-Flags-xgettext: --add-comments=translators:\n"
"X-Poedit-WPHeader: style.css\n"
Expand Down Expand Up @@ -75,13 +75,13 @@ msgid "Open map"
msgstr ""

#: lib/ACF/FrontPageGroup.php:39 lib/ACF/OnepagerGroup.php:73
#: lib/ACF/PageGroup.php:41
#: lib/ACF/PageGroup.php:42
msgctxt "theme ACF"
msgid "Page Components"
msgstr ""

#: lib/ACF/FrontPageGroup.php:91 lib/ACF/OnepagerGroup.php:126
#: lib/ACF/PageGroup.php:142 lib/ACF/PostGroup.php:173
#: lib/ACF/PageGroup.php:194 lib/ACF/PostGroup.php:173
msgctxt "theme ACF"
msgid "Components"
msgstr ""
Expand All @@ -101,6 +101,21 @@ msgctxt "theme ACF"
msgid "Asetukset"
msgstr ""

#: lib/ACF/PageGroup.php:43
msgctxt "theme ACF"
msgid "Page settings"
msgstr ""

#: lib/ACF/PageGroup.php:169
msgctxt "theme ACF"
msgid "Remove hero-image overlay"
msgstr ""

#: lib/ACF/PageGroup.php:170
msgctxt "theme ACF"
msgid "Remove hero-image overlay and move the heading under the hero-element"
msgstr ""

#: lib/ACF/PostGroup.php:129 models/single.php:161
msgid "Related posts"
msgstr ""
Expand Down Expand Up @@ -301,11 +316,11 @@ msgstr ""
msgid "Links"
msgstr ""

#: lib/Eventz.php:314
#: lib/Eventz.php:354
msgid "Additional information"
msgstr ""

#: lib/Eventz.php:331
#: lib/Eventz.php:371
msgid "Free"
msgstr ""

Expand Down
122 changes: 120 additions & 2 deletions lib/ACF/PageGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public function __construct() {
100
);

\add_action(
'init',
\Closure::fromCallable( [ $this, 'register_page_settings' ] ),
100
);

$this->add_anchor_fields();
}

Expand All @@ -44,7 +50,7 @@ protected function register_fields() : void {
$field_group = ( new Group( $group_title ) )
->set_key( $key );

$rules = apply_filters(
$rules = \apply_filters(
'tms/acf/group/' . $key . '/rules',
[
[
Expand Down Expand Up @@ -128,6 +134,118 @@ protected function register_fields() : void {
}
}

/**
* Register page settings fields
*/
protected function register_page_settings() : void {
try {
$group_title = \_x( 'Page settings', 'theme ACF', 'tms-theme-base' );
$key = 'fg_page_settings';

$field_group = ( new Group( $group_title ) )
->set_key( $key );

$rules = \apply_filters(
'tms/acf/group/' . $key . '/rules',
[
[
'param' => 'post_type',
'operator' => '==',
'value' => PostType\Page::SLUG,
],
[
'param' => 'page_template',
'operator' => '!=',
'value' => \PageFrontPage::TEMPLATE,
],
[
'param' => 'page_template',
'operator' => '!=',
'value' => \PageEventsCalendar::TEMPLATE,
],
[
'param' => 'page_template',
'operator' => '!=',
'value' => \PageOnepager::TEMPLATE,
],
[
'param' => 'page_template',
'operator' => '!=',
'value' => \PageEventsCalendar::TEMPLATE,
],
[
'param' => 'page_template',
'operator' => '!=',
'value' => \PageEventsSearch::TEMPLATE,
],
[
'param' => 'page_type',
'operator' => '!=',
'value' => 'posts_page',
],
]
);

$rule_group = new RuleGroup();

foreach ( $rules as $rule ) {
$rule_group->add_rule(
$rule['param'],
$rule['operator'],
$rule['value'],
);
}

$field_group
->add_rule_group( $rule_group )
->set_position( 'side' );

$field_group->add_fields(
\apply_filters(
'tms/acf/group/' . $field_group->get_key() . '/fields',
[
$this->get_overlay_field( $field_group->get_key() ),
]
)
);

$field_group = \apply_filters(
'tms/acf/group/' . $field_group->get_key(),
$field_group
);

$field_group->register();
}
catch ( Exception $e ) {
( new Logger() )->error( $e->getMessage(), $e->getTraceAsString() );
}
}

/**
* Get overlay field
*
* @param string $key Field group key.
*
* @return Field\FlexibleContent
* @throws Exception In case of invalid option.
*/
protected function get_overlay_field( string $key ) : Field\TrueFalse {
$strings = [
'remove_overlay' => [
'title' => \_x( 'Remove hero-image overlay', 'theme ACF', 'tms-theme-base' ),
'instructions' => \_x( 'Remove hero-image overlay and move the heading under the hero-element', 'theme ACF', 'tms-theme-base' ),
],
];

$overlay_field = ( new Field\TrueFalse( $strings['remove_overlay']['title'] ) )
->set_key( "{$key}_remove_overlay" )
->set_name( 'remove_overlay' )
->use_ui()
->set_instructions( $strings['remove_overlay']['instructions'] );

return $overlay_field;
}

/**
* Get components fields
*
Expand All @@ -139,7 +257,7 @@ protected function register_fields() : void {
protected function get_components_field( string $key ) : Field\FlexibleContent {
$strings = [
'components' => [
'title' => _x( 'Components', 'theme ACF', 'tms-theme-base' ),
'title' => \_x( 'Components', 'theme ACF', 'tms-theme-base' ),
'instructions' => '',
],
];
Expand Down
16 changes: 8 additions & 8 deletions models/page-extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PageExtend extends BaseModel {
* Hooks
*/
public function hooks() : void {
add_filter( 'tms/theme/breadcrumbs/show_breadcrumbs_in_header', fn() => false );
\add_filter( 'tms/theme/breadcrumbs/show_breadcrumbs_in_header', fn() => false );
}

/**
Expand All @@ -26,8 +26,8 @@ public function hooks() : void {
* @return int|null
*/
public function hero_image() : ?int {
return has_post_thumbnail()
? get_post_thumbnail_id()
return \has_post_thumbnail()
? \get_post_thumbnail_id()
: null;
}

Expand All @@ -37,8 +37,8 @@ public function hero_image() : ?int {
* @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 );
$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;
Expand All @@ -55,14 +55,14 @@ public function post_siblings() {
'order' => 'ASC',
];

$wp_query = new WP_Query( $query_args );
$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->permalink = \get_the_permalink( $post->ID );
$post->is_current = $post->ID === $current_post_id;

return $post;
Expand All @@ -75,6 +75,6 @@ public function post_siblings() {
* @return bool
*/
public function use_overlay() {
return true;
return \get_field( 'remove_overlay' ) === true ? false : true;
}
}
6 changes: 6 additions & 0 deletions partials/page.dust
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
</div>
{/Header.breadcrumbs}

{^Page.use_overlay}
<section class="page__hero-heading section pt-5-desktop pt-0 pb-0">
{>"ui/entry-title" class="mt-0 has-text-centered" /}
</section>
{/Page.use_overlay}

<section class="section {?Header.hero_image}pt-7{:else}{?Header.breadcrumbs}pt-0{:else}pt-10{/Header.breadcrumbs}{/Header.hero_image}">
<div class="container">
<div class="columns">
Expand Down
14 changes: 7 additions & 7 deletions partials/views/page/page-hero.dust
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<section class="page__hero section is-relative pt-0 pb-0 has-background-cover" {@inlinebg id=Page.hero_image size="fullhd" /}>
{?Page.use_overlay}
<div class="overlay overlay--dark-50"></div>
{/Page.use_overlay}

<div class="is-absolute has-top-50 has-right-0 has-left-0 has-transform-y--50">
<div class="container">
<div class="columns">
<div class="column is-8 is-offset-2">
{>"ui/entry-title" class="mt-0 has-text-centered has-text-white" /}
<div class="is-absolute has-top-50 has-right-0 has-left-0 has-transform-y--50">
<div class="container">
<div class="columns">
<div class="column is-8 is-offset-2">
{>"ui/entry-title" class="mt-0 has-text-centered has-text-white" /}
</div>
</div>
</div>
</div>
</div>
{/Page.use_overlay}
</section>

0 comments on commit b7beb89

Please sign in to comment.