Skip to content

Commit

Permalink
PLANET-7239 Unify Tag listing pages UI and refactor template code
Browse files Browse the repository at this point in the history
This is to comply with the new IA
  • Loading branch information
mleray authored and comzeradd committed Oct 19, 2023
1 parent 5a55072 commit 198ecc8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 151 deletions.
50 changes: 0 additions & 50 deletions src/Campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ public function add_taxonomy_form_fields($wp_tag): void
$image_attributes = wp_get_attachment_image_src($attachment_id, 'full');
$attachment_url = $image_attributes ? $image_attributes[0] : '';

$happypoint_attachment_id = get_term_meta($wp_tag->term_id, 'happypoint_attachment_id', true);
$happypoint_image_attributes = wp_get_attachment_image_src($happypoint_attachment_id, 'full');
$happypoint_attachment_url = $happypoint_image_attributes ? $happypoint_image_attributes[0] : '';

$happypoint_bg_opacity = get_term_meta($wp_tag->term_id, 'happypoint_bg_opacity', true);
$happypoint_bg_opacity = $happypoint_bg_opacity ?? '30';

$redirect_page = get_term_meta($wp_tag->term_id, 'redirect_page', true);
$dropdown_args = [
'show_option_none' => ' ',
Expand Down Expand Up @@ -167,30 +160,6 @@ public function add_taxonomy_form_fields($wp_tag): void
<i class="dashicons dashicons-dismiss <?php echo $image_attributes ? '' : 'hidden'; ?>" style="cursor: pointer;"></i>
</td>
</tr>
<tr class="form-field edit-wrap term-happypoint-wrap">
<th>
<label><?php esc_html_e('Image Subscribe', 'planet4-master-theme-backend'); ?></label>
</th>
<td>
<input type="hidden" name="happypoint_attachment_id" id="happypoint_attachment_id" class="happypoint-attachment-id field-id" value="<?php echo esc_attr($happypoint_attachment_id); ?>" />
<input type="hidden" name="happypoint_attachment" id="happypoint_attachment" class="happypoint-attachment-url field-url" value="<?php echo esc_url($happypoint_attachment_url); ?>" />
<button class="button insert-media add_media" name="insert_happypoint_image_button" id="insert_happypoint_image_button" type="button">
<?php esc_html_e('Select/Upload Image', 'planet4-master-theme-backend'); ?>
</button>
<p class="description"><?php esc_html_e('Choose a background image for the Subscribe block.', 'planet4-master-theme-backend'); ?></p>
<img class="attachment-thumbnail size-thumbnail" src="<?php echo esc_url($happypoint_attachment_url); ?>"/>
<i class="dashicons dashicons-dismiss <?php echo $happypoint_image_attributes ? '' : 'hidden'; ?>" style="cursor: pointer;"></i>
</td>
</tr>
<tr class="form-field edit-wrap term-happypoint-opacity-wrap">
<th>
<label><?php esc_html_e('Happy Point Opacity', 'planet4-master-theme-backend'); ?></label>
</th>
<td>
<input type="number" name="happypoint_bg_opacity" id="happypoint_bg_opacity" class="happypoint-opacity-id field-id" value="<?php echo esc_attr($happypoint_bg_opacity); ?>" min="1" max="100"/>
<p class="description"><?php esc_html_e('We use an overlay to fade the image back. Use a number between 1 and 100, the higher the number, the more faded the image will look. If you leave this empty, the default of 30 will be used.', 'planet4-master-theme-backend'); ?></p>
</td>
</tr>
<?php
} else {
$dropdown_args = [
Expand Down Expand Up @@ -255,25 +224,6 @@ public function save_taxonomy_meta(int $term_id): void
update_term_meta($term_id, $field_url, $attachment_url);
}

$field_id = 'happypoint_attachment_id';
$field_url = 'happypoint_attachment';
$attachment_id = filter_input(INPUT_POST, $field_id, FILTER_VALIDATE_INT);
$attachment_url = filter_input(INPUT_POST, $field_url, FILTER_VALIDATE_URL);

if ($attachment_id && $this->validate($attachment_id)) {
update_term_meta($term_id, $field_id, $attachment_id);
update_term_meta($term_id, $field_url, $attachment_url);
}

$field_id = 'happypoint_bg_opacity';
$happypoint_bg_opacity = filter_input(INPUT_POST, $field_id, FILTER_VALIDATE_INT);

if ($happypoint_bg_opacity && $this->validate($happypoint_bg_opacity)) {
update_term_meta($term_id, $field_id, $happypoint_bg_opacity);
} else {
$happypoint_bg_opacity = 30;
}

$redirect_page = filter_input(INPUT_POST, 'redirect_page', FILTER_VALIDATE_INT) ?? 0;
if ($redirect_page) {
update_term_meta($term_id, 'redirect_page', $redirect_page);
Expand Down
112 changes: 11 additions & 101 deletions tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

use P4\MasterTheme\Context;
use P4\MasterTheme\Features\Dev\ListingPageGridView;
use P4GBKS\Blocks\Articles;
use P4GBKS\Blocks\HappyPoint;
use P4\MasterTheme\Post;
use P4\MasterTheme\TaxonomyCampaign;
use Timber\Timber;
Expand Down Expand Up @@ -51,102 +49,14 @@
$context['canonical_link'] = home_url($wp->request);
$context['og_type'] = 'website';

if (!empty(planet4_get_option('new_ia'))) {
// Temporary fix with rewind, cf. https://github.com/WordPress/gutenberg/issues/53593
rewind_posts();
$context['page_category'] = 'Listing Page';
$view = ListingPageGridView::is_active() ? 'grid' : 'list';
$query_template = file_get_contents(get_template_directory() . "/parts/query-$view.html");
$content = do_blocks($query_template);
$context['query_loop'] = $content;

$templates = ['tag.twig', 'archive.twig', 'index.twig'];
$campaign = new TaxonomyCampaign($templates, $context);
$campaign->view();
} else {
$context['page_category'] = 'Tag Page';
$context['custom_body_classes'] = 'white-bg page-issue-page';
$context['category_name'] = '';
$context['category_link'] = '';

$templates = ['tag.twig', 'archive.twig', 'index.twig'];
$campaign = new TaxonomyCampaign($templates, $context);

$campaign->add_block(
'covers',
[
'title' => __('Things you can do', 'planet4-master-theme'),
'description' => __(
'We want you to take action because together we\'re strong.',
'planet4-master-theme'
),
'tags' => [$tag->term_id],
'cover_type' => '1', // Show Take Action Cover.
]
);

$campaign->add_block(
Articles::BLOCK_NAME,
[
'tags' => [$tag->term_id],
]
);

// Convert old CFC block to Covers block [Content Cover].
$cfc_args = [
'tags' => [$tag->term_id],
'cover_type' => '3',
'title' => __('Publications', 'planet4-master-theme'),
];

// Get the selected page types for this campaign so that we add posts in the CFC block
// only for those page types.
$selected_page_types = get_term_meta($tag->term_id, 'selected_page_types');

if (isset($selected_page_types[0]) && $selected_page_types[0]) {
foreach ($selected_page_types[0] as $selected_page_type) {
$p4_page_type = get_term_by('name', $selected_page_type, 'p4-page-type');
if (!($p4_page_type instanceof \WP_Term)) {
continue;
}

$cfc_args['post_types'] = $p4_page_type->term_id;
}
} else {
// If none is selected, then display Publications by default (for backwards compatibility).
$p4_page_type = get_term_by('slug', 'publication', 'p4-page-type');
if ($p4_page_type instanceof \WP_Term) {
$cfc_args['post_types'] = $p4_page_type->term_id;
}
}

$campaign->add_block('covers', $cfc_args);

// Convert old CampaignThumbnail block to Covers block[Campaign covers].
$campaign->add_block(
'covers',
[
'title' => __('Related Campaigns', 'planet4-master-theme'),
'category_id' => $category->term_id
?? __('This Campaign is not assigned to an Issue', 'planet4-master-theme'),
'cover_type' => '2', // Show Campaign covers.
]
);

// Get the image selected as background for the Subscribe section (HappyPoint block) inside the current Tag.
$background = get_term_meta($tag->term_id, 'happypoint_attachment_id', true);
$opacity = get_term_meta($tag->term_id, 'happypoint_bg_opacity', true);
$options = get_option('planet4_options');

$campaign->add_block(
HappyPoint::BLOCK_NAME,
[
'mailing_list_iframe' => true,
'id' => $background,
'engaging_network_id' => $options['engaging_network_form_id'] ?? '',
'opacity' => $opacity,
]
);

$campaign->view();
}
// Temporary fix with rewind, cf. https://github.com/WordPress/gutenberg/issues/53593
rewind_posts();
$context['page_category'] = 'Listing Page';
$view = ListingPageGridView::is_active() ? 'grid' : 'list';
$query_template = file_get_contents(get_template_directory() . "/parts/query-$view.html");
$content = do_blocks($query_template);
$context['query_loop'] = $content;

$templates = ['tag.twig', 'archive.twig', 'index.twig'];
$campaign = new TaxonomyCampaign($templates, $context);
$campaign->view();

0 comments on commit 198ecc8

Please sign in to comment.