-
-
Notifications
You must be signed in to change notification settings - Fork 226
Add blade support for cms/backend partials #1431
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,8 @@ class Partial extends CmsCompoundObject | |
| */ | ||
| protected $dirName = 'partials'; | ||
|
|
||
| protected $allowedExtensions = ['htm', 'blade']; | ||
|
|
||
| /** | ||
| * Returns name of a PHP class to us a parent for the PHP class created for the object's PHP section. | ||
| * @return string Returns the class name. | ||
|
|
@@ -21,4 +23,29 @@ public function getCodeClassParent() | |
| { | ||
| return PartialCode::class; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the base file name and extension. Applies a default extension, if none found. | ||
| */ | ||
| public function getFileNameParts($fileName = null) | ||
| { | ||
| if ($fileName === null) { | ||
| $fileName = $this->fileName; | ||
| } | ||
|
|
||
| if (!strlen($extension = pathinfo($fileName, PATHINFO_EXTENSION))) { | ||
| $extension = $this->defaultExtension; | ||
| $baseFile = $fileName; | ||
| } | ||
| elseif (($extension = pathinfo($fileName, PATHINFO_EXTENSION)) === 'blade') { | ||
| $extension = 'php'; | ||
| $baseFile = $fileName; | ||
| } | ||
| else { | ||
| $pos = strrpos($fileName, '.'); | ||
| $baseFile = substr($fileName, 0, $pos); | ||
| } | ||
|
|
||
| return [$baseFile, $extension]; | ||
| } | ||
|
Comment on lines
+27
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify getFileNameParts usage, CMS loading system, and Blade partial handling
# 1. Search for usage of getFileNameParts
echo "=== Searching for getFileNameParts usage ==="
rg -n "getFileNameParts" --type=php
# 2. Search for file loading logic
echo -e "\n=== Searching for load() method in CMS classes ==="
rg -n -A 3 "function load\(" --type=php modules/cms/classes/ 2>/dev/null || echo "No matches found or directory not accessible"
# 3. Search for Partial class definition and its inheritance
echo -e "\n=== Searching for Partial class definition ==="
rg -n "class Partial" --type=php -A 5
# 4. Check for .blade files or .blade.php files in themes
echo -e "\n=== Searching for blade template files ==="
find . -name "*blade.php" -o -name "*.blade" 2>/dev/null | head -20 || echo "No blade files found"Repository: wintercms/winter Length of output: 4032 🏁 Script executed: #!/bin/bash
# Read the Partial.php file to understand the code context
echo "=== Reading modules/cms/classes/Partial.php (lines 25-55) ==="
if [ -f "modules/cms/classes/Partial.php" ]; then
sed -n '25,55p' modules/cms/classes/Partial.php | cat -n
else
echo "File not found"
fiRepository: wintercms/winter Length of output: 1078 Remove redundant pathinfo() call. The code has a minor inefficiency: line 40 calls - if (!strlen($extension = pathinfo($fileName, PATHINFO_EXTENSION))) {
+ $extension = pathinfo($fileName, PATHINFO_EXTENSION);
+
+ if (!strlen($extension)) {
$extension = $this->defaultExtension;
$baseFile = $fileName;
}
- elseif (($extension = pathinfo($fileName, PATHINFO_EXTENSION)) === 'blade') {
+ elseif ($extension === 'blade') {
$extension = 'php';
$baseFile = $fileName;
}🤖 Prompt for AI Agents |
||
| } | ||
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.
Critical: Blade rendering path missing component variables.
The Blade rendering at line 1070 only passes
$this->vars, while the Twig rendering at line 1075 passesarray_merge($parameters, $this->vars). This inconsistency is problematic because:$parametersarray (see line 1045:$parameters[$alias] = ... = $componentObj)🔎 Proposed fix
if (str_ends_with($partial->fileName, '.blade.php')) { - $partialContent = Blade::render($partial->content, $this->vars); + $partialContent = Blade::render($partial->content, array_merge($parameters, $this->vars)); } else { $this->getLoader()->setObject($partial); $template = $this->getTwig()->load($partial->getFilePath()); $partialContent = $template->render(array_merge($parameters, $this->vars)); }📝 Committable suggestion
🤖 Prompt for AI Agents