Skip to content

Commit

Permalink
Feat/slides (#29)
Browse files Browse the repository at this point in the history
* feat: slides

* fix: pre get posts slides archive
  • Loading branch information
xuliwenwenwen authored Aug 16, 2024
1 parent 5cf3e5f commit 102ca98
Show file tree
Hide file tree
Showing 17 changed files with 708 additions and 2 deletions.
243 changes: 243 additions & 0 deletions pingcap-jp/acf/acf-slides-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
<?php
use PingCAP\Constants;

$acf_group = Constants\ACF::SLIDES_SETTINGS_BASE;

acf_add_local_field_group(array (
'key' => 'group_' . $acf_group,
'title' => 'slides Settings',
'fields' => array (
/**
* Tab: slides Archive
*/
array (
'key' => 'field_' . $acf_group . '_tab_video_archive',
'label' => 'slides Archive',
'name' => 'tab_video_archive',
'type' => 'tab',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'placement' => 'top',
'endpoint' => 0, // end tabs to start a new group
),
array (
'key' => 'field_' . $acf_group . '_archive_title',
'label' => 'Archive Title',
'name' => $acf_group . '_archive_title',
'type' => 'text',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => 'slides',
'placeholder' => '',
'formatting' => 'none', // none | html
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_' . $acf_group . '_override_posts_per_page',
'label' => 'Override Default Posts Per Page Value',
'name' => $acf_group . '_override_posts_per_page',
'type' => 'true_false',
'instructions' => 'Enabling this option will allow you to override the default value under <a href="' . get_admin_url() . 'options-reading.php">Settings / Reading</a> for this archive.',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '50',
'class' => '',
'id' => '',
),
'message' => '',
'ui' => 1,
'ui_on_text' => 'Yes',
'ui_off_text' => 'No',
'default_value' => 0,
),
array (
'key' => 'field_' . $acf_group . '_custom_posts_per_page',
'label' => 'Custom Posts Per Page Count',
'name' => $acf_group . '_custom_posts_per_page',
'type' => 'number',
'instructions' => '',
'required' => 0,
'conditional_logic' => array (
array (
array (
'field' => 'field_' . $acf_group . '_override_posts_per_page',
'operator' => '==',
'value' => 1,
),
),
),
'wrapper' => array (
'width' => '50',
'class' => '',
'id' => '',
),
'default_value' => 12,
'placeholder' => '',
'prepend' => '',
'append' => '',
'min' => 1,
'max' => '',
'step' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_' . $acf_group . '_no_results_message',
'label' => 'No Results Message',
'name' => $acf_group . '_no_results_message',
'type' => 'text',
'instructions' => '',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => PingCAP\Constants\DefaultValues::ARCHIVE_NO_RESULTS_MESSAGE,
'placeholder' => '',
'formatting' => 'none', // none | html
'prepend' => '',
'append' => '',
'maxlength' => '',
'readonly' => 0,
'disabled' => 0,
),
array (
'key' => 'field_' . $acf_group . '_featured_post',
'label' => 'Featured Post',
'name' => $acf_group . '_featured_post',
'type' => 'post_object',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'post_type' => PingCAP\Constants\CPT::SLIDES,
'taxonomy' => array (),
'allow_null' => 1,
'multiple' => 0,
'return_format' => 'id', // object | id
'ui' => 1,
),
array (
'key' => 'field_' . $acf_group . '_video_archive_blocks',
'label' => 'slides Archive',
'name' => $acf_group . '_video_archive_blocks',
'type' => 'clone',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'clone' => array (
0 => 'group_grav_blocks',
),
'display' => 'seamless',
'layout' => 'block',
'prefix_label' => 1,
'prefix_name' => 1,
),

/**
* Tab: Images
*/
array (
'key' => 'field_' . $acf_group . '_tab_images',
'label' => 'Images',
'name' => $acf_group . '_tab_images',
'type' => 'tab',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'placement' => 'top',
'endpoint' => 0, // end tabs to start a new group
),
array (
'key' => 'field_' . $acf_group . '_default_featured_image',
'label' => 'Default Featured Image',
'name' => $acf_group . '_default_featured_image',
'instructions' => '',
'type' => 'image',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'object', // array | url | id
'preview_size' => 'medium',
'library' => 'all', // all | uploadedTo
'min_width' => '',
'min_height' => '',
'min_size' => '',
'max_width' => '',
'max_height' => '',
'max_size' => '',
'mime_types' => '',
)
),
'location' => array (
array (
array (
'param' => 'options_page', // post_type | post | page | page_template | post_category | taxonomy | options_page
'operator' => '==',
'value' => 'slides-settings', // if options_page then use: acf-options | if page_template then use: template-example.php
'order_no' => 0,
'group_no' => 1,
),
),
),
'menu_order' => 0,
'position' => 'normal', // side | normal | acf_after_title
'style' => 'seamless', // default | seamless
'label_placement' => 'top', // top | left
'instruction_placement' => 'label', // label | field
'hide_on_screen' => array (
// 0 => 'permalink',
// 1 => 'the_content',
// 2 => 'excerpt',
// 3 => 'custom_fields',
// 4 => 'discussion',
// 5 => 'comments',
// 6 => 'revisions',
// 7 => 'slug',
// 8 => 'author',
// 9 => 'format',
// 10 => 'featured_image',
// 11 => 'categories',
// 12 => 'tags',
// 13 => 'send-trackbacks',
),
'active' => 1,
'description' => '',
));
101 changes: 101 additions & 0 deletions pingcap-jp/acf/acf-slides.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

use PingCAP\Constants;

$acf_group = 'slides';

acf_add_local_field_group(array(
'key' => 'group_' . $acf_group,
'title' => 'Slides Settings',
'fields' => array_merge(
WPUtil\Vendor\BlueprintBlocks::safe_get_link_fields([
'label' => 'slides Download Link',
'name' => 'slides_url',
'key_modifier' => $acf_group . '_slides_url',
'includes' => [
'file' => 'File Download',
'url' => 'URL',
],
'show_text' => false,
'supports_button_styles' => false,
]),
array(
array(
'key' => 'field_' . $acf_group . '_slides_image',
'label' => 'Slides Image',
'name' => 'slides_image',
'instructions' => '',
'type' => 'image',
'required' => 1,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'return_format' => 'object', // array | url | id
'preview_size' => 'medium',
'library' => 'all', // all | uploadedTo
'min_width' => '',
'min_height' => '',
'min_size' => '',
'max_width' => '',
'max_height' => '',
'max_size' => '',
'mime_types' => '',
),
array(
'key' => 'field_' . $acf_group . '_slides_content',
'label' => 'Slides Content',
'name' => 'slides_content',
'type' => 'wysiwyg',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array(
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'tabs' => 'all', // all | visual | text
'toolbar' => 'full', // full | basic
'media_upload' => 0,
),
)
),
'location' => array(
array(
array(
'param' => 'post_type', // post_type | post | page | page_template | post_category | taxonomy | options_page
'operator' => '==',
'value' => Constants\CPT::SLIDES, // if options_page then use: acf-options | if page_template then use: template-example.php
'order_no' => 0,
'group_no' => 1
)
)
),
'menu_order' => 0,
'position' => 'normal', // side | normal | acf_after_title
'style' => 'default', // default | seamless
'label_placement' => 'top', // top | left
'instruction_placement' => 'label', // label | field
'hide_on_screen' => array(
// 0 => 'permalink',
// 1 => 'the_content',
// 2 => 'excerpt',
// 3 => 'custom_fields',
// 4 => 'discussion',
// 5 => 'comments',
// 6 => 'revisions',
// 7 => 'slug',
// 8 => 'author',
// 9 => 'format',
// 10 => 'featured_image',
// 11 => 'categories',
// 12 => 'tags',
// 13 => 'send-trackbacks'
),
'active' => 1,
'description' => ''
));
26 changes: 26 additions & 0 deletions pingcap-jp/bootstrap/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,19 @@
)
]);

/**
* Add a 'card_markup' field to the results returned by the
* /wp/v2/slides endpoint
*/
register_rest_field(Constants\CPT::SLIDES, 'card_markup', [
'get_callback' => fn ($post) => WPUtil\Component::render_to_string(
Components\Cards\CardSlides::class,
[
'post_id' => $post['id']
]
)
]);

/**
* Add a 'card_markup' field to the results returned by the
* /wp/v2/search endpoint
Expand Down Expand Up @@ -341,6 +354,19 @@
return $args;
}, 10, 2);

/**
* Add filters to slides post queries from the "load more" requests
*/
add_filter('rest_' . Constants\CPT::SLIDES . '_query', function ($args, $request) {
$args['posts_per_page'] = CPT\Slides::getPostsPerPageCount(); // phpcs:ignore

$args = CPT\Slides::modifyQueryWithFilters($args, [
'category' => $request->get_param('category_slug') ?? '',
]);

return $args;
}, 10, 2);

/**
* Add industry slug support to case studies endpoint
*/
Expand Down
Loading

0 comments on commit 102ca98

Please sign in to comment.