Tribe_Events
Class for Shortcode Tribe_Events.
Source
File: src/Tribe/Views/V2/Shortcodes/Tribe_Events.php
class Tribe_Events extends Shortcode_Abstract {
/**
* {@inheritDoc}
*/
protected $slug = 'tribe_events';
/**
* {@inheritDoc}
*/
protected $default_arguments = [
'view' => null,
// Legacy Params, registered for compatibility
'date' => null,
'tribe-bar' => true,
'category' => null,
'cat' => null,
'featured' => false,
'main-calendar' => false,
];
/**
* {@inheritDoc}
*/
protected $arguments_validate_map = [
'tribe-bar' => 'tribe_is_truthy',
'featured' => 'tribe_is_truthy',
'main-calendar' => 'tribe_is_truthy',
];
/**
* Toggles the filtering of URLs to match the place where.
* We tend to hook into P15 to allow other things to happen before shortcode.
*
* @since 4.7.5
*
* @param bool $toggle Whether to turn the hooks on or off.
*
* @return void
*/
protected function toggle_view_hooks( bool $toggle ) {
if ( $toggle ) {
add_filter( 'tribe_events_views_v2_view_url', [ $this, 'filter_view_url' ], 15, 3 );
} else {
remove_filter( 'tribe_events_views_v2_view_url', [ $this, 'filter_view_url' ], 15 );
}
}
/**
* Verifies if in this Shortcode we should allow view url managemet.
*
* @since 4.7.5
*
* @return bool
*/
public function should_manage_url() {
// Defaults to true due to old behaviors on Views V1
$should_manage_url = $this->get_argument( 'should_manage_url', true );
$disallowed_locations = [
'widget_text_content',
];
/**
* Allows filtering of the disallowed locations for URL management.
*
* @since 4.7.5
*
* @param mixed $disallowed_locations Which filters we dont allow URL management.
* @param static $instance Which instance of shortcode we are dealing with.
*/
$disallowed_locations = apply_filters( 'tribe_events_pro_shortcode_tribe_events_manage_url_disallowed_locations', $disallowed_locations, $this );
// Block certain locations
foreach ( $disallowed_locations as $location ) {
// If any we are in any of the disallowed locations
if ( doing_filter( $location ) ) {
$should_manage_url = false;
}
}
/**
* Allows filtering if a shortcode URL management is active.
*
* @since 4.7.5
*
* @param mixed $should_manage_url Should we manage the URL for this views shortcode instance.
* @param static $instance Which instance of shortcode we are dealing with.
*/
$should_manage_url = apply_filters( 'tribe_events_pro_shortcode_tribe_events_should_manage_url', $should_manage_url, $this );
return $should_manage_url;
}
/**
* Changes the URL to match the Shortcode if needed.
*
* @todo actually do the URL management.
*
* @since 4.7.5
*
* @param string $url Current URL for this view.
* @param bool $canonical Whether this url is canonical.
* @param View_Interface $view Which view we are dealign with.
*
* @return string
*/
public function filter_view_url( $url, $canonical, $view ) {
// Dont touch the URL in case we are not managing it.
if ( ! $this->should_manage_url() ) {
return $url;
}
return $url;
}
/**
* {@inheritDoc}
*/
public function get_html() {
$context = tribe_context();
$view_slug = $this->get_argument( 'view', $context->get( 'view' ) );
// Make sure to enqueue assets
tribe_asset_enqueue_group( Assets::$group_key );
// Toggle the shortcode required modifications
$this->toggle_view_hooks( true );
/**
* @todo modify the context based on arguments passed to the method.
*/
// Setup the view instance.
$view = View::make( $view_slug, $context );
// Setup wether this view should manage url or not.
$view->get_template()->set( 'should_manage_url', $this->should_manage_url() );
$html = $view->get_html();
// Toggle the shortcode required modifications
$this->toggle_view_hooks( false );
return $html;
}
}
Changelog
| Version | Description |
|---|---|
| 4.7.5 | Introduced. |
Methods
- alter_context — Alters the shortcode context with its arguments.
- args_to_repository — Translates shortcode arguments to their Repository argument counterpart.
- enqueue_assets_before_template — Allows us to print Scripts and Styles inside of the template but outside of the container.
- filter_context_locations — Filters the context locations to add the ones used by Shortcodes.
- filter_default_url — Filters the default view in the views manager for shortcodes navigation.
- filter_ff_link_next_event — Modify the events repository query for the fast-forward link.
- filter_skip_empty — Allows the user to specify that they want to skip empty views.
- filter_view_context — Alters the context of the view based on the shortcode params stored in the database based on the ID.
- filter_view_data — Filters the View data attributes to add some related to PRO features.
- filter_view_html_classes — Filters the View HTML classes to add some related to PRO features.
- filter_view_query_args — Changes the URL to match the Shortcode if needed.
- filter_view_repository_args — Filters the View repository args to add the ones required by shortcodes to work.
- filter_view_url — Filters the View URL to add the shortcode query arg, if required.
- filter_view_url_query_args — Filters the query arguments array and add the Shortcodes.
- filter_week_events_per_day — Modify the Week events per day of a given view based on arguments from Shortcode.
- filter_week_view_breakpoints — Filter the breakpoints for the week view widget based on layout.
- get_database_arguments — Fetches from the database the params of a given shortcode based on the ID created.
- get_html — {@inheritDoc}
- get_id — Based on the either a argument "id" of the shortcode definition or the 8 first characters of the hashed version of a string serialization of the params sent to the shortcode we will create/get an ID for this instance of the tribe_events shortcode
- get_validated_arguments_map
- maybe_toggle_hooks_for_rest — Maybe toggles the hooks for this shortcode class on a rest request.
- remove_request_based_context_locations — Should not be used carelessly this will remove all request based locations from the read of the context.
- set_database_params — Configures the Relationship between shortcode ID and their params in the database allowing us to pass the URL as the base for the Queries.
- should_display — Determines if we should display the shortcode in a given page.
- should_manage_url — Verifies if in this Shortcode we should allow View URL management.
- validate_array_html_classes — Cleans up an array of values as html classes.
- week_view_hide_weekends — Hide weekends on shortcode.