Skip to content

Commit

Permalink
Merge branch 'TMS-950' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Oct 24, 2023
2 parents 19ef751 + 0623387 commit 9862e9d
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 44 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

- TMS-970: Add image caption text to call-to-action and content-columns blocks.
- TMS-950: Empty check for phone repeater.
- TMS-950:
- Empty check for phone repeater.
- Place of business posts to block
- Contacts styles & accessibility

## [1.49.0] - 2023-09-15

Expand All @@ -17,8 +20,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [1.48.0] - 2023-09-13

- TMS-973: Fix manual event sorting
>>>>>>> TMS-950

## [1.47.0] - 2023-09-04

Expand Down
11 changes: 6 additions & 5 deletions lib/ACF/Fields/ContactsFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,21 @@ 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_wrapper_width( 50 )
->set_instructions( $strings['title']['instructions'] );

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

$api_contacts_field = ( new Field\Select( $strings['api_contacts']['label'] ) )
->set_key( "${key}_api_contacts" )
->set_key( "{$key}_api_contacts" )
->set_name( 'api_contacts' )
->allow_multiple()
->allow_null()
Expand All @@ -125,14 +125,15 @@ protected function sub_fields() : array {
->set_instructions( $strings['api_contacts']['instructions'] );

$contacts_field = ( new Field\Relationship( $strings['contacts']['label'] ) )
->set_key( "${key}_contacts" )
->set_key( "{$key}_contacts" )
->set_name( 'contacts' )
->set_filters( [ 'search' ] )
->set_post_types( [ Contact::SLUG ] )
->set_return_format( 'id' )
->set_instructions( $strings['contacts']['instructions'] );

$fields_field = ( new Field\Checkbox( $strings['fields']['label'] ) )
->set_key( "${key}_fields" )
->set_key( "{$key}_fields" )
->set_name( 'fields' )
->set_choices( $strings['fields']['choices'] )
->set_default_value( $strings['fields']['default_value'] )
Expand Down
32 changes: 29 additions & 3 deletions lib/ACF/Fields/PlaceOfBusinessFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,63 @@ protected function sub_fields() : array {
'label' => 'Tampere-sivuston toimipaikat',
'instructions' => '',
],
'place_of_business_post' => [
'label' => 'Toimipaikat',
'instructions' => '',
],
];

$key = $this->get_key();

$title_field = ( new Field\Text( $strings['title']['label'] ) )
->set_key( "${key}_title" )
->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_key( "{$key}_description" )
->set_name( 'description' )
->set_rows( 4 )
->set_new_lines( 'wpautop' )
->set_wrapper_width( 50 )
->set_instructions( $strings['description']['instructions'] );

$place_of_business_field = ( new Field\Select( $strings['place_of_business']['label'] ) )
->set_key( "${key}_place_of_business" )
->set_key( "{$key}_place_of_business" )
->set_name( 'place_of_business' )
->allow_multiple()
->allow_null()
->use_ajax()
->use_ui()
->set_instructions( $strings['place_of_business']['instructions'] );

$place_of_business_post_field = ( new Field\Relationship( $strings['place_of_business_post']['label'] ) )
->set_key( "{$key}_place_of_business_post" )
->set_name( 'place_of_business_post' )
->set_filters( [ 'search' ] )
->redipress_include_search( function ( $places ) {
if ( empty( $places ) ) {
return '';
}

$results = [];

foreach ( $places as $place_id ) {
$results[] = get_field( 'title', $place_id );
}

return implode( ' ', $results );
} )
->set_post_types( [ 'placeofbusiness-cpt' ] )
->set_return_format( 'id' )
->set_instructions( $strings['place_of_business_post']['instructions'] );

return [
$title_field,
$description_field,
$place_of_business_field,
$place_of_business_post_field,
];
}

Expand Down
1 change: 0 additions & 1 deletion lib/ACF/PageContactsGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ protected function get_contacts_fields( string $key ) : Field\Tab {
$fields = new ContactsFields( 'Yhteystiedot', $key );
$fields->remove_field( 'title' );
$fields->remove_field( 'description' );
$fields->remove_field( 'contacts' );

$tab->add_fields( $fields->get_fields() );

Expand Down
55 changes: 51 additions & 4 deletions lib/Formatters/PlaceOfBusinessFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,40 @@ public function hooks() : void {
* @return array
*/
public function format( array $data ) {
if ( empty( $data['place_of_business'] ) ) {
if ( empty( $data['place_of_business'] ) && empty( $data['place_of_business_post'] ) ) {
return $data;
}

$data['items'] = $this->map_api_results(
$data['place_of_business'],
if ( ! empty( $data['place_of_business_post'] ) ) {
$the_query = new \WP_Query( [
'post_type' => 'placeofbusiness-cpt',
'posts_per_page' => 100,
'post__in' => array_map( 'absint', $data['place_of_business_post'] ),
'no_found_rows' => true,
'meta_key' => 'title',
'orderby' => [
'menu_order' => 'ASC',
'meta_value' => 'ASC', // phpcs:ignore
],
] );

$filled_places = $this->map_keys(
$the_query->posts,
);
}

if ( ! empty( $data['place_of_business'] ) ) {
$filled_api_places = $this->map_api_results(
$data['place_of_business'],
);
}

$data['items'] = array_merge(
$filled_places ?? [],
$filled_api_places ?? [],
);

$data['column_class'] = 'is-12-mobile is-6-tablet is-4-desktop';
$data['column_class'] = 'is-12-mobile is-6-tablet';

return $data;
}
Expand Down Expand Up @@ -80,4 +105,26 @@ public function map_api_results( array $ids = [] ) : array {
return in_array( $result['id'], $ids, true );
} );
}

/**
* Map fields to posts
*
* @param array $posts Array of WP_Post instances.
*
* @return array
*/
public function map_keys( array $posts ) : array {
if( ! \is_plugin_active( 'tms-plugin-place-of-business-sync/plugin.php' ) ) {
return [];
}

return array_map( function ( $id ) {

foreach( \get_field_objects($id) as $field ) {
$item[ $field['name'] ] = \get_field( $field['name'], $id );
}

return $item;
}, $posts );
}
}
11 changes: 9 additions & 2 deletions models/page-contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,26 @@ public function search() : array {
* @return array
*/
protected function get_contacts() : array {
$selected_contacts = \get_field( 'contacts' );
if ( empty( $selected_contacts ) ) {
return [];
}

$args = [
'post_type' => Contact::SLUG,
'posts_per_page' => 200, // phpcs:ignore
'post_status' => 'publish',
'fields' => 'ids',
'post__in' => array_map( 'absint', $selected_contacts ),
'no_found_rows' => true,
'meta_key' => 'last_name',
'orderby' => [
'menu_order' => 'ASC',
'meta_value' => 'ASC', // phpcs:ignore
],
];

$s = get_query_var( self::SEARCH_QUERY_VAR, false );
$s = \get_query_var( self::SEARCH_QUERY_VAR, false );

if ( ! empty( $s ) ) {
$args['s'] = $s;
Expand All @@ -79,7 +86,7 @@ public function contacts() : array {

$contacts = $formatter->map_keys(
$contacts,
get_field( 'fields' ) ?? [],
\get_field( 'fields' ) ?? [],
$default_image
);

Expand Down
56 changes: 30 additions & 26 deletions partials/shared/contact-item.dust
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@

<div class="column">
{?additional_info_top}
<div class="h6 mb-3 keep-vertical-spacing">
{additional_info_top|s}
</div>
<p class="h6 mb-3 mt-0 keep-vertical-spacing">
{additional_info_top|kses}
</p>
{/additional_info_top}

{?title}
<div class="mb-3">
{title|s}
</div>
<p class="mb-3 mt-0 hyphenate">
{title|html}
</p>
{/title}

{@isset key1=first_name key2=last_name method="OR" }
<div class="has-text-weight-bold mb-3">
{first_name|s} {last_name|s}
</div>
<p class="has-text-weight-bold mb-3 mt-0">
{first_name|html} {last_name|html}
</p>
{/isset}

{?phone_repeater}
Expand All @@ -35,7 +35,7 @@
</div>

<div>
<div>{phone_text|html}</div>
<span>{phone_text|html}</span>
<div>
<a href="tel:{phone_number|html}"
class="has-text-paragraph hyphenate">
Expand Down Expand Up @@ -66,9 +66,9 @@
{>"ui/icon" icon="building" class="icon--large is-primary" /}
</div>

<div>
{office|s}
</div>
<p class="m-0">
{office|html}
</p>
</div>
{/office}

Expand All @@ -78,9 +78,9 @@
{>"ui/icon" icon="location" class="icon--large is-primary" /}
</div>

<div>
{domain|s}
</div>
<p class="m-0">
{domain|html}
</p>
</div>
{/domain}

Expand All @@ -90,9 +90,9 @@
{>"ui/icon" icon="location" class="icon--large is-primary" /}
</div>

<div>
{unit|s}
</div>
<p class="m-0">
{unit|html}
</p>
</div>
{/unit}

Expand All @@ -102,9 +102,11 @@
{>"ui/icon" icon="location" class="icon--large is-primary" /}
</div>

{visiting_address_street|s}
{visiting_address_zip_code|s}
{visiting_address_city|s}
<p class="m-0">
{visiting_address_street|html}
{visiting_address_zip_code|html}
{visiting_address_city|html}
</p>
</div>
{/isset}

Expand All @@ -114,15 +116,17 @@
{>"ui/icon" icon="location" class="icon--large is-primary" /}
</div>

{mail_address_street|s}
{mail_address_zip_code|s}
{mail_address_city|s}
<p class="m-0">
{mail_address_street|html}
{mail_address_zip_code|html}
{mail_address_city|html}
</p>
</div>
{/isset}

{?additional_info_bottom}
<div>
{additional_info_bottom|s}
{additional_info_bottom|kses}
</div>
{/additional_info_bottom}
</div>
Expand Down

0 comments on commit 9862e9d

Please sign in to comment.