generated from devgeniem/tms-plugin-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TMS-977: Add combined events search page-template (#19)
* TMS-977: Add combined events search page-template * TMS-977: Update changelog * TMS-977: No results if no search terms * Update pr-template * TMS-977: phpcs fix * 1.2.0
- Loading branch information
Showing
8 changed files
with
425 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2023. Geniem Oy | ||
*/ | ||
|
||
namespace TMS\Plugin\ManualEvents\Fields; | ||
|
||
use Geniem\ACF\Exception; | ||
use Geniem\ACF\Group; | ||
use Geniem\ACF\RuleGroup; | ||
use Geniem\ACF\Field; | ||
use TMS\Theme\Base\ACF\Field\TextEditor; | ||
use TMS\Theme\Base\ACF\Fields\EventsFields; | ||
use TMS\Theme\Base\Logger; | ||
|
||
/** | ||
* Class PageCombinedEventsSearchGroup. | ||
* | ||
* @package TMS\Plugin\ManualEvents\Fields | ||
*/ | ||
class PageCombinedEventsSearchGroup { | ||
|
||
/** | ||
* ManualEventGroup constructor. | ||
*/ | ||
public function __construct() { | ||
add_action( | ||
'init', | ||
\Closure::fromCallable( [ $this, 'register_fields' ] ) | ||
); | ||
} | ||
|
||
/** | ||
* Register fields | ||
*/ | ||
protected function register_fields() : void { | ||
try { | ||
$field_group = ( new Group( 'Sivun asetukset' ) ) | ||
->set_key( 'fg_page_combined_events_search' ); | ||
|
||
$rule_group = ( new RuleGroup() ) | ||
->add_rule( 'page_template', '==', \PageCombinedEventsSearch::TEMPLATE ); | ||
|
||
$field_group | ||
->add_rule_group( $rule_group ) | ||
->set_position( 'normal' ) | ||
->set_hidden_elements( | ||
[ | ||
'discussion', | ||
'comments', | ||
'format', | ||
'send-trackbacks', | ||
] | ||
); | ||
|
||
$field_group->add_fields( | ||
apply_filters( | ||
'tms/acf/group/' . $field_group->get_key() . '/fields', | ||
[ | ||
$this->get_page_fields( $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 page fields | ||
* | ||
* @param string $key Field group key. | ||
* | ||
* @return Field\Tab | ||
* @throws Exception In case of invalid option. | ||
*/ | ||
protected function get_page_fields( string $key ) : Field\Tab { | ||
$strings = [ | ||
'tab' => 'Tapahtumat', | ||
'description' => [ | ||
'title' => 'Kuvausteksti', | ||
'instructions' => '', | ||
], | ||
]; | ||
|
||
$tab = ( new Field\Tab( $strings['tab'] ) ) | ||
->set_placement( 'left' ); | ||
|
||
$description_field = ( new TextEditor( $strings['description']['title'] ) ) | ||
->set_key( "{$key}_description" ) | ||
->set_name( 'description' ) | ||
->redipress_include_search() | ||
->set_instructions( $strings['description']['instructions'] ); | ||
|
||
$search_fields = ( new EventsFields( 'Tapahtumahaku', $key ) ) | ||
->remove_field( 'title' ) | ||
->remove_field( 'start' ) | ||
->remove_field( 'end' ) | ||
->remove_field( 'starts_today' ) | ||
->remove_field( 'area' ) | ||
->remove_field( 'tag' ) | ||
->remove_field( 'target' ) | ||
->remove_field( 'text' ) | ||
->remove_field( 'page_size' ) | ||
->remove_field( 'all_events_link' ); | ||
|
||
$fields = [ | ||
$description_field, | ||
]; | ||
$fields = array_merge( $fields, $search_fields->get_fields() ); | ||
|
||
$tab->add_fields( $fields ); | ||
|
||
return $tab; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.