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 support for (hybrid) FSE #314

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1aacb91
Patch hierarchy and include filter to provide FSE compability
dsturm Nov 6, 2023
71b0051
Tweak FSE paths filter
dsturm Nov 6, 2023
147a48c
Add custom blade template support to AcornFSE class
dsturm Nov 15, 2023
a0ff0cb
Only modify template hierarchy for block-based themes
dsturm Nov 15, 2023
ecb5d52
Fix wp_is_block_theme condition in
dsturm Nov 15, 2023
74722f2
Add check for enabled theme support
dsturm Nov 16, 2023
7b3d223
Fix get_page_template_slug() function call in
dsturm Nov 16, 2023
58b7b88
Add use_fse helper function to check if current theme
dsturm Nov 16, 2023
1926c3c
:rotating_light: Lint FiltersTemplates.php
dsturm Nov 16, 2023
6127e84
Patch hierarchy and include filter to provide FSE compability
dsturm Nov 6, 2023
2921c42
Tweak FSE paths filter
dsturm Nov 6, 2023
7a7207f
Add custom blade template support to AcornFSE class
dsturm Nov 15, 2023
814df6d
Only modify template hierarchy for block-based themes
dsturm Nov 15, 2023
a0fd0d7
Fix wp_is_block_theme condition in
dsturm Nov 15, 2023
fd5c947
Add check for enabled theme support
dsturm Nov 16, 2023
bcb2a2f
Fix get_page_template_slug() function call in
dsturm Nov 16, 2023
a2aabdf
Add use_fse helper function to check if current theme
dsturm Nov 16, 2023
c93b97c
:rotating_light: Lint FiltersTemplates.php
dsturm Nov 16, 2023
18d795b
Merge remote-tracking branch 'origin/fse' into fse
dsturm Nov 17, 2023
5943b78
Add phpcodesniffer-composer-installer plugin to
dsturm Nov 17, 2023
1d7518e
:rotating_light: Run lint:fix
dsturm Nov 17, 2023
c795a29
Merge branch 'roots:main' into fse
dsturm Nov 27, 2023
efaea0f
Merge branch 'roots:main' into fse
dsturm Dec 11, 2023
9cfae94
Merge branch 'roots:main' into fse
dsturm Jan 4, 2024
9d93c3b
Merge branch 'roots:main' into fse
dsturm Jan 19, 2024
7786fe5
Merge branch 'roots:main' into fse
dsturm Jan 26, 2024
64d2328
Merge branch 'roots:main' into fse
dsturm Jan 30, 2024
eedd288
Merge branch 'roots:main' into fse
dsturm Jan 30, 2024
a5b4d59
Merge branch 'roots:main' into fse
dsturm Jan 31, 2024
eea8cfd
Merge branch 'roots:main' into fse
dsturm Feb 2, 2024
77b1049
Merge branch 'roots:main' into fse
dsturm Feb 2, 2024
fa4d942
Merge branch 'roots:main' into fse
dsturm Feb 3, 2024
4ec89da
Merge branch 'roots:main' into fse
dsturm Feb 6, 2024
fb8d6d2
Decrease required illuminate/console version to prevent conflict wit…
dsturm Feb 12, 2024
210cd43
Revert " Decrease required illuminate/console version to prevent conf…
dsturm Feb 12, 2024
40de883
Merge branch 'roots:main' into fse
dsturm Feb 19, 2024
ecc2866
Merge branch 'roots:main' into fse
dsturm Mar 6, 2024
8a42879
Merge branch 'roots:main' into fse
dsturm Mar 15, 2024
afb6474
Merge branch 'roots:main' into fse
dsturm Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions src/Roots/Acorn/Sage/Concerns/FiltersTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,39 @@ trait FiltersTemplates
* @param array $files
* @return string[] List of possible views
*/
public function filterTemplateHierarchy($files)
public function filterTemplateHierarchy($files): array
{
return $this->sageFinder->locate($files);
$hierarchy = $this->sageFinder->locate($files);

// If the theme does not support FSE, return the original hierarchy.
if (
! function_exists('wp_is_block_theme')
|| ! \wp_is_block_theme()
|| ! \current_theme_supports('block-templates')
) {
return $hierarchy;
}

// Extract all entries, which point to an official FSE path (e.g. templates/...)
$fse_paths = array_filter(
$hierarchy,
static fn ($file) => str_starts_with($file, 'templates/') || str_contains($file, 'templates/')
);
$hierarchy = array_diff($hierarchy, $fse_paths);

// Extract all entries, which point to a custom blade template (e.g. template-foo.blade.php)
$custom_template = \get_page_template_slug();
$custom_template_paths = [];
if ($custom_template) {
$custom_template_paths = array_filter(
$hierarchy,
static fn ($file) => str_contains($file, $custom_template)
);
$hierarchy = array_diff($hierarchy, $custom_template_paths);
}

// Rebuild hierarchy with original $files and FSE paths on top.
return array_merge($custom_template_paths, $files, $fse_paths, $hierarchy);
}

/**
Expand All @@ -27,6 +57,15 @@ public function filterTemplateHierarchy($files)
*/
public function filterTemplateInclude($file)
{
// Prevent duplication of markup
// @ https://github.com/roots/acorn/pull/141#issuecomment-1343162742
if (
@file_exists($file)
&& ! str_contains($file, '.blade.php')
) {
return $file;
}

$view = $this->fileFinder
->getPossibleViewNameFromPath($file = realpath($file));

Expand Down
10 changes: 10 additions & 0 deletions src/Roots/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ function view($view = null, $data = [], $mergeData = [])
: $factory->file($view, $data, $mergeData);
}

/**
* Check if the current theme supports FSE.
*/
function use_fse(): bool
{
return \function_exists('wp_is_block_theme')
&& \wp_is_block_theme()
&& \current_theme_supports('block-templates');
}

/**
* @deprecated
*/
Expand Down
Loading