Skip to content

Commit

Permalink
Merge branch 'master' into TMS-1013
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi authored Mar 26, 2024
2 parents 0cf91e2 + 13eaf95 commit d9e38bb
Show file tree
Hide file tree
Showing 58 changed files with 495 additions and 136 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [1.54.7] - 2024-03-26

- TMS-914:
- Add new anchor-links block & functionalities
- Add anchor id-elements to blocks & components
- TMS-1013: Add entries fetching to Eventz event-integration

## [1.54.6] - 2024-03-18

- TMS-996: Change bold image-caption text to normal
- TMS-1009: Fix error when fetching Eventz response with languages other than fi & en
- TMS-1015: Header accessibility fixes
- TMS-1017: Add image alt-text to imported news
- TMS-1018: Remove external-link icons from imported news image links

## [1.54.5] - 2024-02-01

- TMS-977: Add 'clear form' button to event-search
Expand Down
34 changes: 34 additions & 0 deletions assets/scripts/anchor-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2024. Hion Digital
*/

// Use jQuery as $ within this file scope.
const $ = jQuery; // eslint-disable-line no-unused-vars

/**
* Class AnchorLinks
*/
export default class AnchorLinks {

/**
* Scroll to anchor element
*
* @param {Object} event The click event object.
*
* @return {void}
*/
scrollToDiv( event ) {
$( 'html, body' ).animate( {
scrollTop: $( $( event.target ).attr( 'href' ) ).offset().top,
}, 200 );
}

/**
* Run when the document is ready.
*
* @return {void}
*/
docReady() {
$( '.anchor-links__list a' ).on( 'click', this.scrollToDiv.bind( this ) );
}
}
2 changes: 1 addition & 1 deletion assets/scripts/external-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ExternalLinks {
};

// Links in regular context
$( '#main-content a[href*="//"]:not(.button, .logo-wall__link, .link-list a, [href*="' + domain + '"])' ).append( icon ); // eslint-disable-line
$( '#main-content a[href*="//"]:not(.figure__link, .button, .logo-wall__link, .link-list a, [href*="' + domain + '"])' ).append( icon ); // eslint-disable-line

// Links with icons (replace current icon with "opens in new window" -icon)
$( '#main-content a[href*="//"]:has(.icon):not(.link-list a, [href*="' + domain + '"])' ).each( function() {
Expand Down
2 changes: 2 additions & 0 deletions assets/scripts/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Common from './common';
import Accordion from './accordion';
import AnchorLinks from './anchor-links';
import MapLayout from './map-layout';
import CopyToClipboard from './copy-to-clipboard';
import Hero from './hero';
Expand Down Expand Up @@ -32,6 +33,7 @@ import FocusOnSearch from './focus-on-search';
const globalControllers = {
Common,
Accordion,
AnchorLinks,
MapLayout,
CopyToClipboard,
Hero,
Expand Down
6 changes: 6 additions & 0 deletions assets/styles/blocks/custom/_anchor-links.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.anchor-links {
&__list {
padding-left: $theme-spacing;
border-left: 2px solid $primary;
}
}
1 change: 1 addition & 0 deletions assets/styles/blocks/custom/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@import "accordion";
@import "grid";
@import "image-gallery";
@import "anchor-links";
@import "subpages";
@import "notice-banner";
@import "contacts";
Expand Down
19 changes: 14 additions & 5 deletions lib/ACF/DynamicEventGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,19 @@ protected function get_choices_by_name( string $name, array $field ) : array {
return $field;
}

$cache_key = 'events-' . $name;
$response = wp_cache_get( $cache_key );
$cache_key = 'events-' . $name;
$response = wp_cache_get( $cache_key );
$lang_key = Localization::get_current_language();
$request_allowed_langs = [
'fi',
'en',
];

if ( ! $response ) {
if (
! $response &&
in_array( $lang_key, $request_allowed_langs, true )
) {
try {
$lang_key = Localization::get_current_language();
$client = new EventzClient( PIRKANMAA_EVENTZ_API_URL, PIRKANMAA_EVENTZ_API_KEY );
$response = $client->{'get_' . $name }( $lang_key );

Expand All @@ -307,7 +314,9 @@ protected function get_choices_by_name( string $name, array $field ) : array {

if ( ! empty( $response ) ) {
foreach ( $response as $item ) {
$field['choices'][ $item->_id ] = $item->name;
if ( isset( $item->_id ) ) {
$field['choices'][ $item->_id ] = $item->name;
}
}
}

Expand Down
100 changes: 100 additions & 0 deletions lib/ACF/Fields/AnchorLinksFields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* Copyright (c) 2023. Hion Digital
*/

namespace TMS\Theme\Base\ACF\Fields;

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

/**
* Class AnchorLinksFields
*
* @package TMS\Theme\Base\ACF\Fields
*/
class AnchorLinksFields extends 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 Exception In case of invalid ACF option.
*/
protected function sub_fields() : array {
$strings = [
'title' => [
'label' => 'Otsikko',
'instructions' => '',
],
'description' => [
'label' => 'Kuvaus',
'instructions' => '',
],
'anchor_links' => [
'label' => 'Ankkurilinkit',
'instructions' => '',
'button' => 'Lisää linkki',
],
'anchor_link' => [
'label' => 'Ankkurilinkki',
'instructions' => 'Kirjoita URL-kenttään "#" ja haluamasi lohkon tai komponentin HTML-ankkuri, esim. #lohkon-ankkuri',
],
];

$key = $this->get_key();

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

$description_field = ( new Field\ExtendedWysiwyg( $strings['description']['label'] ) )
->set_key( "{$key}_description" )
->set_name( 'description' )
->set_tabs( 'visual' )
->set_toolbar( 'tms-minimal' )
->disable_media_upload()
->set_height( 100 )
->set_instructions( $strings['description']['instructions'] );

$anchor_links_field = ( new Field\Repeater( $strings['anchor_links']['label'] ) )
->set_key( "{$key}_anchor_links" )
->set_name( 'anchor_links' )
->set_layout( 'block' )
->set_button_label( $strings['anchor_links']['button'] )
->set_instructions( $strings['anchor_links']['instructions'] );

$anchor_link_field = ( new Field\Link( $strings['anchor_link']['label'] ) )
->set_key( "{$key}_anchor_link" )
->set_name( 'anchor_link' )
->set_instructions( $strings['anchor_link']['instructions'] );

$anchor_links_field->add_field( $anchor_link_field );

return [
$title_field,
$description_field,
$anchor_links_field,
];
}
}
8 changes: 4 additions & 4 deletions lib/ACF/Fields/LinkListFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ protected function sub_fields() : array {
$key = $this->get_key();

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

$description_field = ( new Field\ExtendedWysiwyg( $strings['description']['label'] ) )
->set_key( "${key}_description" )
->set_key( "{$key}_description" )
->set_name( 'description' )
->set_tabs( 'visual' )
->set_toolbar( 'tms-minimal' )
Expand All @@ -78,14 +78,14 @@ protected function sub_fields() : array {
->set_instructions( $strings['description']['instructions'] );

$links_field = ( new Field\Repeater( $strings['links']['label'] ) )
->set_key( "${key}_links" )
->set_key( "{$key}_links" )
->set_name( 'links' )
->set_layout( 'block' )
->set_button_label( $strings['links']['button'] )
->set_instructions( $strings['links']['instructions'] );

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

Expand Down
66 changes: 61 additions & 5 deletions lib/ACF/PageGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class PageGroup {
* PageGroup constructor.
*/
public function __construct() {
add_action(
\add_action(
'init',
\Closure::fromCallable( [ $this, 'register_fields' ] ),
100
);

$this->add_anchor_fields();
}

/**
Expand Down Expand Up @@ -106,15 +108,15 @@ protected function register_fields() : void {
);

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

$field_group = apply_filters(
$field_group = \apply_filters(
'tms/acf/group/' . $field_group->get_key(),
$field_group
);
Expand Down Expand Up @@ -143,11 +145,11 @@ protected function get_components_field( string $key ) : Field\FlexibleContent {
];

$components_field = ( new Field\FlexibleContent( $strings['components']['title'] ) )
->set_key( "${key}_components" )
->set_key( "{$key}_components" )
->set_name( 'components' )
->set_instructions( $strings['components']['instructions'] );

$component_layouts = apply_filters(
$component_layouts = \apply_filters(
'tms/acf/field/' . $components_field->get_key() . '/layouts',
[
Layouts\ImageBannerLayout::class,
Expand Down Expand Up @@ -182,6 +184,60 @@ protected function get_components_field( string $key ) : Field\FlexibleContent {

return $components_field;
}

/**
* Add HTML-anchor field to layout fields.
*/
private function add_anchor_fields() : void {
$keys = [
'image_banner',
'call_to_action',
'content_columns',
'logo_wall',
'map',
'icon_links',
'social_media',
'image_carousel',
'subpages' ,
'textblock',
'grid',
'events',
'articles',
'blog_articles',
'sitemap',
'notice_banner',
'gravityform',
'contacts',
'acc_icon_links',
'share_links',
'countdown',
'video',
];

foreach ( $keys as $component ) {
if ( empty( $component ) ) {
continue;
}

\add_filter(
"tms/acf/layout/fg_page_components_$component/fields",
function ( $fields ) use ( $component ) {
$anchor_field = ( new Field\Text( 'HTML-ankkuri' ) )
->set_key( $component . '_anchor' )
->set_name( 'anchor' )
->set_instructions( 'Kirjoita sana tai pari, ilman välilyöntejä,
luodaksesi juuri tälle lohkolle uniikki verkko-osoite, jota kutsutaan "ankkuriksi".
Sen avulla voit luoda linkin suoraan tähän osioon sivullasi.' );

array_unshift( $fields, $anchor_field );

return $fields;
},
10,
1
);
}
}
}

( new PageGroup() );
Loading

0 comments on commit d9e38bb

Please sign in to comment.