Skip to content

Commit

Permalink
Merge pull request #505 from devgeniem/TMS-1033
Browse files Browse the repository at this point in the history
TMS-1033: Add new optional hero-museum component
  • Loading branch information
eebbi authored May 7, 2024
2 parents c081eea + 38b022c commit 718257e
Show file tree
Hide file tree
Showing 9 changed files with 454 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- TMS-1033: Add new optional hero-museum component
- TMS-1038: Fix theme-mustavalkoinen lang-menu styles

## [1.54.9] - 2024-04-18
Expand Down
18 changes: 18 additions & 0 deletions assets/styles/layouts/_hero-museum.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.hero-museum {
height: auto !important;

&__background-container {
@include hero-height;
}

&__inner {
position: static;
transform: none;
}

h1 {
@include from($desktop) {
font-size: 4.41rem !important; // sass-lint:disable-line no-important
}
}
}
1 change: 1 addition & 0 deletions assets/styles/layouts/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

@import "hero";
@import "hero-museum";
@import "icon-links";
@import "image-banner";
@import "image-carousel";
Expand Down
223 changes: 223 additions & 0 deletions lib/ACF/Fields/HeroMuseumFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
<?php

namespace TMS\Theme\Base\ACF\Fields;

use Geniem\ACF\Field;
use TMS\Theme\Base\Logger;

/**
* Class HeroMuseumFields
*
* @package TMS\Theme\Base\ACF\Fields
*/
class HeroMuseumFields extends \Geniem\ACF\Field\Group {

/**
* The constructor for field.
*
* @param string $label Label.
* @param null $key Key.
* @param null $name Name.
*/
public function __construct( $label = '', $key = null, $name = null ) {
parent::__construct( $label, $key, $name );

try {
$this->add_fields( $this->sub_fields() );
}
catch ( \Exception $e ) {
( new Logger() )->error( $e->getMessage(), $e->getTrace() );
}
}

/**
* This returns all sub fields of the parent groupable.
*
* @return array
* @throws \Geniem\ACF\Exception In case of invalid ACF option.
*/
protected function sub_fields() : array {
$strings = [
'image' => [
'label' => 'Kuva',
'instructions' => '',
],
'title' => [
'label' => 'Otsikko',
'instructions' => '',
],
'description' => [
'label' => 'Kuvaus',
'instructions' => '',
],
'link' => [
'label' => 'Painike',
'instructions' => '',
],
'align' => [
'label' => 'Tekstin tasaus',
'instructions' => '',
],
'opening_times' => [
'label' => 'Aukioloajat',
'title' => [
'label' => 'Otsikko',
'instructions' => '',
],
'text' => [
'label' => 'Teksti',
'instructions' => '',
],
'button' => [
'label' => 'Painike',
'instructions' => '',
],
],
'tickets' => [
'label' => 'Liput',
'title' => [
'label' => 'Otsikko',
'instructions' => '',
],
'text' => [
'label' => 'Teksti',
'instructions' => '',
],
'button' => [
'label' => 'Painike',
'instructions' => '',
],
'image' => [
'label' => 'Kuva',
'instructions' => '',
],
],
'find_us' => [
'label' => 'Löydä meille',
'title' => [
'label' => 'Otsikko',
'instructions' => '',
],
'text' => [
'label' => 'Teksti',
'instructions' => '',
],
'button' => [
'label' => 'Painike',
'instructions' => '',
],
],
];

$key = $this->get_key();

$image_field = ( new Field\Image( $strings['image']['label'] ) )
->set_key( "{$key}_image" )
->set_name( 'image' )
->set_return_format( 'id' )
->set_wrapper_width( 50 )
->set_required()
->set_instructions( $strings['image']['instructions'] );

$title_field = ( new Field\Text( $strings['title']['label'] ) )
->set_key( "{$key}_title" )
->set_name( 'title' )
->set_wrapper_width( 50 )
->set_instructions( $strings['title']['instructions'] );

$description_field = ( new Field\Textarea( $strings['description']['label'] ) )
->set_key( "{$key}_description" )
->set_name( 'description' )
->set_rows( 4 )
->set_new_lines( 'wpautop' )
->set_wrapper_width( 50 )
->set_instructions( $strings['description']['instructions'] );

$link_field = ( new Field\Link( $strings['link']['label'] ) )
->set_key( "{$key}_link" )
->set_name( 'link' )
->set_wrapper_width( 40 )
->set_instructions( $strings['link']['instructions'] );

$opening_times_tab = ( new Field\Group( $strings['opening_times']['label'] ) )
->set_key( "{$key}_opening_times" )
->set_name( 'opening_times' );

$opening_times_tab->add_fields(
$this->get_hero_group_fields( $key, 'opening_times', $strings['opening_times'] )
);

$fields[] = $opening_times_tab;

$ticket_tab = ( new Field\Group( $strings['tickets']['label'] ) )
->set_key( "{$key}_tickets" )
->set_name( 'tickets' );

$ticket_image_field = ( new Field\Image( $strings['tickets']['image']['label'] ) )
->set_key( "{$key}_tickets_image" )
->set_name( 'tickets_image' )
->set_return_format( 'id' )
->set_wrapper_width( 50 )
->set_instructions( $strings['tickets']['image']['instructions'] );

$ticket_tab_fields = $this->get_hero_group_fields( $key, 'tickets', $strings['tickets'] );
$ticket_tab_fields[] = $ticket_image_field;

$ticket_tab->add_fields( $ticket_tab_fields );

$find_us_tab = ( new Field\Group( $strings['find_us']['label'] ) )
->set_key( "{$key}_find_us" )
->set_name( 'find_us' );

$find_us_tab->add_fields(
$this->get_hero_group_fields( $key, 'find_us', $strings['find_us'] )
);

return [
$image_field,
$title_field,
$description_field,
$link_field,
$opening_times_tab,
$ticket_tab,
$find_us_tab,
];
}

/**
* Get hero group fields.
*
* @param string $key Layout key.
* @param string $group Group name.
* @param array $strings Field strings.
*
* @return array
* @throws Exception In case of invalid ACF option.
*/
protected function get_hero_group_fields( string $key, string $group, array $strings ) : array {
$title_field = ( new Field\Text( $strings['title']['label'] ) )
->set_key( "{$key}_{$group}_title" )
->set_name( "{$group}_title" )
->set_wrapper_width( 50 )
->set_instructions( $strings['title']['instructions'] );

$text_field = ( new Field\Textarea( $strings['text']['label'] ) )
->set_key( "{$key}_{$group}_text" )
->set_name( "{$group}_text" )
->set_wrapper_width( 50 )
->set_instructions( $strings['text']['instructions'] )
->set_new_lines( 'br' );

$button_field = ( new Field\Link( $strings['button']['label'] ) )
->set_key( "{$key}_{$group}_button" )
->set_name( "{$group}_button" )
->set_wrapper_width( 50 )
->set_instructions( $strings['button']['instructions'] );

return [
$title_field,
$text_field,
$button_field,
];
}
}
15 changes: 13 additions & 2 deletions lib/ACF/Fields/Settings/ThemeColorTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class ThemeColorTab extends \Geniem\ACF\Field\Tab {
'title' => 'Oletuskuva',
'instructions' => '',
],
'use_hero_museum' => [
'title' => 'Ota käyttöön museosivustojen hero',
'instructions' => 'Tällä valinnalla saat otettua käyttöön museosivustojen heron etusivulle.',
],
];

/**
Expand Down Expand Up @@ -86,21 +90,28 @@ public function sub_fields( $key ) : void {
);

$color_theme_select = ( new Field\Select( $this->strings['color_selection']['title'] ) )
->set_key( $key . '_theme_color' )
->set_key( "{$key}_theme_color" )
->set_name( 'theme_color' )
->set_choices( $theme_colors )
->set_default_value( $theme_default_color )
->set_instructions( $this->strings['color_selection']['instructions'] );

$image_field = ( new Field\Image( $this->strings['default_image']['title'] ) )
->set_key( "${key}_default_image" )
->set_key( "{$key}_default_image" )
->set_name( 'default_image' )
->set_return_format( 'id' )
->set_instructions( $this->strings['default_image']['instructions'] );

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

$this->add_fields( [
$color_theme_select,
$image_field,
$use_hero_museum,
] );
}
catch ( \Exception $e ) {
Expand Down
6 changes: 6 additions & 0 deletions lib/ACF/FrontPageGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use TMS\Theme\Base\ACF\Layouts;
use TMS\Theme\Base\Logger;
use TMS\Theme\Base\PostType;
use TMS\Theme\Base\Settings;

/**
* Class FrontPageGroup
Expand Down Expand Up @@ -130,6 +131,11 @@ protected function get_components_field( string $key ) : Field\FlexibleContent {
$components_field->add_layout( new $component_layout( $key ) );
}

// Add Museum hero to components if settings field is turned on
if ( ! empty( Settings::get_setting( 'use_hero_museum' ) ) ) {
$components_field->add_layout( new Layouts\HeroMuseumLayout( $key ) );
}

return $components_field;
}
}
Expand Down
57 changes: 57 additions & 0 deletions lib/ACF/Layouts/HeroMuseumLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace TMS\Theme\Base\ACF\Layouts;

use Geniem\ACF\Exception;
use TMS\Theme\Base\ACF\Fields\HeroMuseumFields;
use TMS\Theme\Base\Logger;

/**
* Class HeroMuseumLayout
*
* @package TMS\Theme\Base\ACF\Layouts
*/
class HeroMuseumLayout extends BaseLayout {

/**
* Layout key
*/
const KEY = '_hero_museum';

/**
* Create the layout
*
* @param string $key Key from the flexible content.
*/
public function __construct( string $key ) {
parent::__construct(
'Hero - museosivustot',
$key . self::KEY,
'hero_museum'
);

$this->add_layout_fields();
}

/**
* Add layout fields
*
* @return void
*/
private function add_layout_fields() : void {
$fields = new HeroMuseumFields(
$this->get_label(),
$this->get_key(),
$this->get_name()
);

try {
$this->add_fields(
$this->filter_layout_fields( $fields->get_fields(), $this->get_key(), self::KEY )
);
}
catch ( Exception $e ) {
( new Logger() )->error( $e->getMessage(), $e->getTrace() );
}
}
}
Loading

0 comments on commit 718257e

Please sign in to comment.