Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing navigation links #366

Merged
merged 11 commits into from
Nov 19, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace Wporg\TranslationEvents\Theme_2024;

use Wporg\TranslationEvents\Translation_Events;
use Wporg\TranslationEvents\Urls;

register_block_type(
'wporg-translate-events-2024/event-edit-link',
array(
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
'render_callback' => function ( array $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$event_id = $block->context['postId'];
$event = Translation_Events::get_event_repository()->get_event( $event_id );
if ( ! $event ) {
return '';
}

ob_start();
if ( ! current_user_can( 'edit_translation_event', $event->id() ) ) {
return '';
}
?>
<a href="<?php echo esc_url( Urls::event_edit( $event->id() ) ); ?>"
class="event-list-item-button"
title="<?php echo esc_attr__( 'Edit', 'gp-translation-events' ); ?>">
<span class="dashicons dashicons-edit"></span>
</a>
<?php
return ob_get_clean();
},
)
);
10 changes: 9 additions & 1 deletion themes/wporg-translate-events-2024/blocks/event-form/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@

ob_start();
?>

<?php
if ( ! $is_create_form && current_user_can( 'edit_translation_event_attendees', $event->id() ) ) :
?>
<!-- wp:button {"align":"center"} -->
<div class="wp-block-button" style="text-align: right;">
<a class="wp-block-button__link" href="<?php echo esc_url( Urls::event_attendees( $event->id() ) ); ?>">Manage Attendees</a>
</div>
<!-- /wp:button -->
<?php endif; ?>
<!-- wp:columns -->
<div class="wp-block-columns">
<!-- wp:column {"width":"64%"} -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<?php
endif;
?>
<!-- wp:wporg-translate-events-2024/event-edit-link /-->
<!-- wp:wporg-translate-events-2024/event-trash-link /-->
</div>
<!-- wp:wporg-translate-events-2024/event-attendance-mode /-->
<!-- wp:wporg-translate-events-2024/event-start /-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace Wporg\TranslationEvents\Theme_2024;

use Wporg\TranslationEvents\Urls;

register_block_type(
'wporg-translate-events-2024/event-nav-links',
array(
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
'render_callback' => function ( $attributes ) {
$page_block_name = esc_html( $attributes['page_block_name'] );
ob_start();
?>
<!-- wp:group {"align":"right","layout":{"type":"flex","justifyContent":"right"}} -->
<div class="wp-block-group alignright" style="width: 35%; margin-left: auto; padding-right:var(--wp--preset--spacing--edge-space);">
<div class="wp-block-group__inner-container" style="display: flex; justify-content: flex-end; gap: 10px; align-items: center;">
<?php if ( is_user_logged_in() ) : ?>
<?php
$show_separator = false;
if ( current_user_can( 'manage_translation_events' ) ) :
$show_separator = true;
?>
<a class="event-nav-link" href="<?php echo esc_url( Urls::events_trashed() ); ?>">Deleted Events</a>
<?php endif; ?>

<?php if ( 'my-events' !== $page_block_name ) : ?>
<?php if ( $show_separator ) : ?>
<span class="separator">|</span>
<?php endif; ?>
<a class="event-nav-link" href="<?php echo esc_url( Urls::my_events() ); ?>">My Events</a>
<?php endif; ?>

<?php if ( current_user_can( 'create_translation_event' ) ) : ?>
<!-- wp:button {"className":"is-style-outline"} -->
<div class="wp-block-button is-style-outline">
<a class="wp-block-button__link wp-element-button" href="<?php echo esc_url( Urls::event_create() ); ?>">Create Event</a>
</div>
<!-- /wp:button -->
<?php endif; ?>
<?php endif; ?>
</div>
</div>
<!-- /wp:group -->
<?php
return ob_get_clean();
},
)
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace Wporg\TranslationEvents\Theme_2024;

use Wporg\TranslationEvents\Translation_Events;
use Wporg\TranslationEvents\Urls;

register_block_type(
'wporg-translate-events-2024/event-trash-link',
array(
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
'render_callback' => function ( array $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
}
$event_id = $block->context['postId'];
$event = Translation_Events::get_event_repository()->get_event( $event_id );
if ( ! $event ) {
return '';
}

ob_start();
if ( ! current_user_can( 'trash_translation_event', $event->id() ) ) {
return '';
}
if ( $event->is_trashed() ) :
?>
<a href="<?php echo esc_url( Urls::event_trash( $event->id() ) ); ?>"
class="button is-small"
title="<?php echo esc_attr__( 'Restore', 'gp-translation-events' ); ?>">
<?php echo esc_attr__( 'Restore', 'gp-translation-events' ); ?>
</a>
<?php else : ?>
<a href="<?php echo esc_url( Urls::event_trash( $event->id() ) ); ?>"
class="event-list-item-button is-destructive"
title="<?php echo esc_attr__( 'Move to trash', 'gp-translation-events' ); ?>">
<span class="dashicons dashicons-trash"></span>
</a>
<?php
endif;
return ob_get_clean();
},
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
<!-- wp:wporg/site-breadcrumbs {"fontSize":"small"} /-->
</div>
<!-- /wp:group -->
<div id="gp-js-message" class="gp-js-message"></div>
<!-- wp:wporg-translate-events-2024/event-nav-links <?php echo wp_json_encode( array( 'page_block_name' => $attributes['page_block_name'] ) ); ?> /-->
<div id="gp-js-message" class="gp-js-message"></div>
13 changes: 11 additions & 2 deletions themes/wporg-translate-events-2024/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ function register_blocks(): void {
include_once __DIR__ . '/blocks/event-form/index.php';
include_once __DIR__ . '/blocks/pages/events/event-edit/index.php';
include_once __DIR__ . '/blocks/remote-attendance-icon/index.php';
include_once __DIR__ . '/blocks/event-edit-link/index.php';
include_once __DIR__ . '/blocks/event-trash-link/index.php';
include_once __DIR__ . '/blocks/event-nav-links/index.php';
}

function register_patterns(): void {
Expand Down Expand Up @@ -196,8 +199,14 @@ function render_page( string $template_path, string $title, array $attributes ):
<!-- /wp:group -->
BLOCKS
);

$header_json = wp_json_encode( array( 'title' => $title ) );
// get block name from template path.
$page_block_name = basename( dirname( $template_path ) ) === 'events' ? pathinfo( $template_path, PATHINFO_FILENAME ) : basename( dirname( $template_path ) );
$header_json = wp_json_encode(
array(
'title' => $title,
'page_block_name' => $page_block_name,
)
);
echo do_blocks( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
<<<BLOCKS
<!-- wp:wporg-translate-events-2024/header $header_json /-->
Expand Down
13 changes: 13 additions & 0 deletions themes/wporg-translate-events-2024/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ select.wp-block-form-input__input {
color: #fff;
background-color: #46b450;
}
a.event-list-item-button:any-link {
text-decoration: none;
vertical-align: text-top;
}
.event-list-item-button.is-destructive {
color: var(--wp--preset--color--vivid-red);
}
.event-nav-link {
text-decoration: none;
}

span.user-remote-icon.dashicons-video-alt2 {
margin-left: -8.8%;
Expand Down Expand Up @@ -194,6 +204,9 @@ span.user-remote-icon.dashicons-video-alt2 {
margin: 5px 3px 0 0;
}

.event-nav-link:hover {
text-decoration: underline;
}
@media (min-width: 960px) {

.wporg-marker-list__container .wporg-marker-list-item {
Expand Down
Loading