Skip to content

Commit

Permalink
TMS-950: Code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Nov 2, 2023
1 parent 0623387 commit 97059b3
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/ACF/Fields/PlaceOfBusinessFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected function sub_fields() : array {
return implode( ' ', $results );
} )
->set_post_types( [ 'placeofbusiness-cpt' ] )
->set_return_format( 'id' )
->set_return_format( 'object' )
->set_instructions( $strings['place_of_business_post']['instructions'] );

return [
Expand Down
15 changes: 1 addition & 14 deletions lib/Formatters/ContactFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,8 @@ public function format( array $data ) {
$default_image = Settings::get_setting( 'contacts_default_image' );

if ( ! empty( $data['contacts'] ) ) {
$the_query = new \WP_Query( [
'post_type' => Contact::SLUG,
'posts_per_page' => 100,
'fields' => 'ids',
'post__in' => array_map( 'absint', $data['contacts'] ),
'no_found_rows' => true,
'meta_key' => 'last_name',
'orderby' => [
'menu_order' => 'ASC',
'meta_value' => 'ASC', // phpcs:ignore
],
] );

$filled_contacts = $this->map_keys(
$the_query->posts,
$data['contacts'],
$field_keys,
$default_image
);
Expand Down
21 changes: 2 additions & 19 deletions lib/Formatters/PlaceOfBusinessFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,8 @@ public function format( array $data ) {
}

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,
$data['place_of_business_post'],
);
}

Expand Down Expand Up @@ -119,12 +107,7 @@ public function map_keys( array $posts ) : array {
}

return array_map( function ( $id ) {

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

return $item;
return \get_fields( $id );
}, $posts );
}
}
16 changes: 9 additions & 7 deletions models/page-contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ protected function get_contacts() : array {
return [];
}

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

// Return all selected contacts if no search was performed.
if ( empty( $s ) ) {
return $selected_contacts;
}

$args = [
'post_type' => Contact::SLUG,
'posts_per_page' => 200, // phpcs:ignore
Expand All @@ -62,15 +69,10 @@ protected function get_contacts() : array {
'menu_order' => 'ASC',
'meta_value' => 'ASC', // phpcs:ignore
],
's' => $s,
];

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

if ( ! empty( $s ) ) {
$args['s'] = $s;
}

$the_query = new WP_Query( $args );
$the_query = new \WP_Query( $args );

return $the_query->posts;
}
Expand Down
2 changes: 1 addition & 1 deletion models/shared/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public function menu_item_classes( $classes, $item ) : array {
}

$current_page = \get_queried_object();
if ( (int) $item->object_id === $current_page->ID ) {
if ( ! empty( $current_page->ID ) && (int) $item->object_id === $current_page->ID ) {
$classes['is_current'] = 'is-current';
}

Expand Down
4 changes: 2 additions & 2 deletions partials/blocks/block-contacts.dust
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<div class="column is-12">
{?title}
<h2>
{title|s}
{title|html}
</h2>
{/title}

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

0 comments on commit 97059b3

Please sign in to comment.