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
Consolidate URL generation #228
Conversation
It should contain the /glotpress prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Could you also find a way to add unit tests that use define( 'GP_URL_BASE', '/' );
which we have on translate.wordpress.org?
Probably the Urls
class fits our current plugin design but I was wondering if another option might have been to introduce a gp_url_event()
similar to gp_url_project()
in GlotPress.
$event_title = $event->title(); | ||
$event_description = $event->description(); | ||
$event_status = $event->status(); | ||
$event_url = Urls::event_details_absolute( $event_id ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about introducing an alias $event->url()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this one because there's Urls::event_details_absolute()
and Urls::event_details()
. So we'd need to choose one to use in the $event->url()
method.
I think then it could become confusing because you'd need to remember whether $event->url()
returns the absolute or relative URL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe all functions in Urls
should return the absolute URL?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's certainly not bad to always return absolute URLs, thus probably preferrable indeed, now that we have it unified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just in this context it's preferrable to avoid id juggling but maybe it's one-off enough to be ok? Don't have a strong opinion.
I think in practice the two approaches are similar, it's just that GlotPress defines those functions globally, and namespaces by prefixing the functions with # GlotPress/gp-includes/url.php
function gp_url_project( $project_or_path = '', $path = '', $query = null ) {} # wporg-gp-translation-events/includes/urls.php
namespace Wporg\TranslationEvents;
class Urls {
public static function event_details( int $event_id ): string {}
} Personally I like the PHP namespaces approach better, but I can change it to # wporg-gp-translation-events/includes/urls.php
namespace Wporg\TranslationEvents;
function event_details_url( int $event_id ): string {} # somefile.php
use function Wporg\TranslationEvents\event_details_url;
echo event_details_url( $event_id ); Let me know which approach you prefer. |
As I said earlier, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks! I think it's ok to address my feedback in an follow-up PR if we want to do them, I'm happy to get this over the finish line already in this state.
Cool, merging! |
This PR makes it so that all URLs of the plugin are generated through a new
Urls
class, so whenever there's a need to generate a URL you can simply do something like:This PR also fixes an issue where the URL was wrong in the event edit page (it would be correct when post is draft, and incorrect when post is published).