| @@ -30,8 +30,50 @@ | ||
| 30 | 30 | add_action('wp_enqueue_scripts', [$this, 'enqueueAssets']); |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | + * Resolve the effective trip-listing card layout for one listing. | |
| 35 | + * | |
| 36 | + * The site-wide Design setting (`frontend_listing_card_layout`) is the | |
| 37 | + * default; a shortcode/block may pass a per-instance override. Anything that | |
| 38 | + * is not a concrete layout (empty, "inherit", or an unknown value) falls | |
| 39 | + * back to the global setting, so existing shortcodes/blocks are unchanged. | |
| 40 | + * | |
| 41 | + * @param string $override Per-instance override (card_layout / cardLayout). | |
| 42 | + * @return string One of: standard | compact_mobile | compact_all. | |
| 43 | + */ | |
| 44 | + public static function resolveListingLayout(string $override = ''): string | |
| 45 | + { | |
| 46 | + $override = strtolower(trim($override)); | |
| 47 | + if (in_array($override, ['standard', 'compact_mobile', 'compact_all'], true)) { | |
| 48 | + return $override; | |
| 49 | + } | |
| 50 | + | |
| 51 | + $global = \Yatra\Services\SettingsService::getString('frontend_listing_card_layout', 'standard'); | |
| 52 | + return in_array($global, ['standard', 'compact_mobile', 'compact_all'], true) ? $global : 'standard'; | |
| 53 | + } | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Map a resolved layout to the container CSS class(es) the listing CSS keys | |
| 57 | + * off. Placed on the listing container (archive .yatra-listing-page, or the | |
| 58 | + * shortcode/block wrapper) so each listing can carry its own layout and an | |
| 59 | + * override never leaks into other listings on the same page. | |
| 60 | + * | |
| 61 | + * @param string $layout standard | compact_mobile | compact_all | |
| 62 | + * @return string Space-separated class list ('' for standard). | |
| 63 | + */ | |
| 64 | + public static function listingLayoutClasses(string $layout): string | |
| 65 | + { | |
| 66 | + if ($layout === 'compact_mobile') { | |
| 67 | + return 'yatra-listing-compact'; | |
| 68 | + } | |
| 69 | + if ($layout === 'compact_all') { | |
| 70 | + return 'yatra-listing-compact yatra-listing-compact--all'; | |
| 71 | + } | |
| 72 | + return ''; | |
| 73 | + } | |
| 74 | + | |
| 75 | + /** | |
| 34 | 76 | * Register Font Awesome (optional) and common.css so block editor + shortcode styles can |
| 35 | 77 | * depend on `yatra-common` (shared @keyframes: yatra-spin, yatra-shimmer, etc.). |
| 36 | 78 | */ |
| 37 | 79 | /** |