Skip to content

Commit dafea34

Browse files
committed
php style fixes
1 parent b8dc98b commit dafea34

3 files changed

Lines changed: 32 additions & 30 deletions

File tree

src/Laravel/DotCmsHelpers.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Dotcms\PhpSdk\Laravel;
44

5-
use Dotcms\PhpSdk\Utils\DotCmsHelper;
65
use Dotcms\PhpSdk\Model\Content\Contentlet;
76
use Dotcms\PhpSdk\Model\Layout\ContainerRef;
7+
use Dotcms\PhpSdk\Utils\DotCmsHelper;
88

99
/**
1010
* DotCMS Laravel Helper for empty container support
@@ -62,6 +62,7 @@ public function rewriteContainerIdentifier(ContainerRef $containerRef, string $n
6262
if (isset($containerRef->identifier)) {
6363
$containerRef->identifier = str_replace('//demo.dotcms.com/', "//$newHost/", $containerRef->identifier);
6464
}
65+
6566
return $containerRef;
6667
}
67-
}
68+
}

src/Twig/DotCMSExtension.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace Dotcms\PhpSdk\Twig;
44

5-
use Dotcms\PhpSdk\Utils\DotCmsHelper;
65
use Dotcms\PhpSdk\Model\Content\Contentlet;
76
use Dotcms\PhpSdk\Model\Layout\ContainerRef;
7+
use Dotcms\PhpSdk\Utils\DotCmsHelper;
8+
use Twig\Environment;
89
use Twig\Extension\AbstractExtension;
910
use Twig\TwigFunction;
10-
use Twig\Environment;
1111

1212
/**
1313
* DotCMS Twig Extension for empty container support
@@ -24,7 +24,7 @@ public function getFunctions(): array
2424
return [
2525
new TwigFunction('renderContainer', [$this, 'renderContainer'], ['is_safe' => ['html']]),
2626
new TwigFunction('getEmptyContainerCSS', [$this, 'getEmptyContainerCSS'], ['is_safe' => ['html']]),
27-
new TwigFunction('htmlAttr', [$this, 'htmlAttr'], ['is_safe' => ['html']])
27+
new TwigFunction('htmlAttr', [$this, 'htmlAttr'], ['is_safe' => ['html']]),
2828
];
2929
}
3030

@@ -46,22 +46,23 @@ public function renderContainer(
4646
// If no custom renderer provided, use the existing Twig content rendering logic
4747
if ($contentRenderer === null) {
4848
$twig = $this->twig; // Capture for closure
49-
$contentRenderer = function(Contentlet $content) use ($twig) {
49+
$contentRenderer = function (Contentlet $content) use ($twig) {
5050
$contentType = $content->contentType;
5151
if ($contentType) {
5252
$template = 'dotcms/content-types/' . strtolower($contentType) . '.twig';
5353
if ($twig->getLoader()->exists($template)) {
5454
return $twig->render($template, [
5555
'content' => $content,
56-
'dotcms_host' => $_ENV['DOTCMS_HOST'] ?? 'https://demo.dotcms.com'
56+
'dotcms_host' => $_ENV['DOTCMS_HOST'] ?? 'https://demo.dotcms.com',
5757
]);
5858
}
5959
}
60+
6061
// Fall back to the SDK simple HTML renderer
6162
return DotCmsHelper::simpleContentHtml($content->jsonSerialize());
6263
};
6364
}
64-
65+
6566
return DotCmsHelper::renderContainer($containerRef, $contentlets, $mode, $contentRenderer);
6667
}
6768

@@ -85,4 +86,4 @@ public function htmlAttr(array $attrs): string
8586
{
8687
return DotCmsHelper::htmlAttributes($attrs);
8788
}
88-
}
89+
}

src/Utils/DotCmsHelper.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static function getContainerAttributes(ContainerRef $containerRef): array
9090
'data-dot-identifier' => $containerRef->identifier ?? '',
9191
'data-dot-accept-types' => $containerRef->acceptTypes ?? '',
9292
'data-max-contentlets' => $containerRef->maxContentlets ?? '',
93-
'data-dot-uuid' => $containerRef->uuid ?? ''
93+
'data-dot-uuid' => $containerRef->uuid ?? '',
9494
];
9595
}
9696

@@ -115,8 +115,8 @@ public static function getContentletAttributes(Contentlet $content, ContainerRef
115115
'identifier' => $containerRef->identifier ?? '',
116116
'maxContentlets' => $containerRef->maxContentlets ?? '',
117117
'variantId' => $containerRef->variantId ?? '',
118-
'uuid' => $containerRef->uuid ?? ''
119-
])
118+
'uuid' => $containerRef->uuid ?? '',
119+
]),
120120
];
121121
}
122122

@@ -140,8 +140,8 @@ public static function getGhostContentletAttributes(ContainerRef $containerRef):
140140
'identifier' => $containerRef->identifier ?? '',
141141
'maxContentlets' => $containerRef->maxContentlets ?? '',
142142
'variantId' => $containerRef->variantId ?? '',
143-
'uuid' => $containerRef->uuid ?? ''
144-
])
143+
'uuid' => $containerRef->uuid ?? '',
144+
]),
145145
];
146146
}
147147

@@ -153,8 +153,8 @@ public static function getGhostContentletAttributes(ContainerRef $containerRef):
153153
*/
154154
public static function generateEmptyContainerPlaceholder(string $message = 'This container is empty.'): string
155155
{
156-
return '<div class="empty-container-placeholder">' .
157-
htmlspecialchars($message, ENT_QUOTES, 'UTF-8') .
156+
return '<div class="empty-container-placeholder">' .
157+
htmlspecialchars($message, ENT_QUOTES, 'UTF-8') .
158158
'</div>';
159159
}
160160

@@ -179,55 +179,55 @@ public static function isEditMode(?string $mode): bool
179179
* @return string Complete container HTML
180180
*/
181181
public static function renderContainer(
182-
ContainerRef $containerRef,
183-
array $contentlets,
182+
ContainerRef $containerRef,
183+
array $contentlets,
184184
?string $mode = null,
185185
?callable $contentRenderer = null
186186
): string {
187187
$containerAttrs = self::getContainerAttributes($containerRef);
188188
$containerAttrsHtml = self::htmlAttributes($containerAttrs);
189-
$hasContentlets = !empty($contentlets);
189+
$hasContentlets = ! empty($contentlets);
190190
$isEditMode = self::isEditMode($mode);
191-
192-
$html = '';
193-
191+
192+
$html = '';
193+
194194
// Auto-inject CSS for empty containers if we're in edit mode and need it
195-
if ($isEditMode && !$hasContentlets) {
195+
if ($isEditMode && ! $hasContentlets) {
196196
static $cssInjected = false;
197-
if (!$cssInjected) {
197+
if (! $cssInjected) {
198198
$html .= '<style>' . self::getEmptyContainerCSS() . '</style>';
199199
$cssInjected = true;
200200
}
201201
}
202-
202+
203203
$html .= "<div{$containerAttrsHtml}>";
204204

205205
if ($hasContentlets) {
206206
// Render contentlets
207207
foreach ($contentlets as $content) {
208208
$contentAttrs = self::getContentletAttributes($content, $containerRef);
209209
$contentAttrsHtml = self::htmlAttributes($contentAttrs);
210-
210+
211211
$contentHtml = '';
212212
if ($contentRenderer && is_callable($contentRenderer)) {
213213
$contentHtml = $contentRenderer($content);
214214
} else {
215215
$contentHtml = self::simpleContentHtml($content->jsonSerialize());
216216
}
217-
217+
218218
$html .= "<div{$contentAttrsHtml}>{$contentHtml}</div>";
219219
}
220220
} elseif ($isEditMode) {
221221
// Render empty container with ghost contentlet for UVE
222222
$ghostAttrs = self::getGhostContentletAttributes($containerRef);
223223
$ghostAttrsHtml = self::htmlAttributes($ghostAttrs);
224224
$placeholder = self::generateEmptyContainerPlaceholder();
225-
225+
226226
$html .= "<div{$ghostAttrsHtml} class=\"uve-ghost-contentlet\">{$placeholder}</div>";
227227
}
228-
228+
229229
$html .= '</div>';
230-
230+
231231
return $html;
232232
}
233233

0 commit comments

Comments
 (0)