Skip to content

Commit 4865c7b

Browse files
committed
refactor(container): Streamline DotCmsHelpers and update README
- Removed the unused getContainersData method for cleaner code. - Updated generateHtmlBasedOnProperty to use Contentlet type for better type safety. - Adjusted container handling in the Blade template to utilize object properties instead of arrays. - Revised README to reflect the changes in functionality.
1 parent 2b0f02d commit 4865c7b

1 file changed

Lines changed: 21 additions & 40 deletions

File tree

examples/dotcms-laravel/README.md

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,10 @@ Create helper functions for DotCMS rendering in `app/Helpers/DotCmsHelpers.php`.
153153
namespace App\Helpers;
154154

155155
use Dotcms\PhpSdk\Utils\DotCmsHelper;
156+
use Dotcms\PhpSdk\Model\Content\Contentlet;
156157

157158
class DotCmsHelpers
158159
{
159-
/**
160-
* Get container data from the containers array
161-
*
162-
* @param array $containers
163-
* @param array $container
164-
* @return array|null
165-
*/
166-
public function getContainersData($containers, $container)
167-
{
168-
return DotCmsHelper::getContainerData($containers, $container);
169-
}
170-
171160
/**
172161
* Generate HTML attributes from an associative array
173162
*
@@ -182,17 +171,17 @@ class DotCmsHelpers
182171
/**
183172
* Generate HTML based on contentlet properties
184173
*
185-
* @param array $content
174+
* @param Contentlet $content
186175
* @return string
187176
*/
188-
public function generateHtmlBasedOnProperty($content)
177+
public function generateHtmlBasedOnProperty(Contentlet $content)
189178
{
190179
if (empty($content)) {
191180
return '';
192181
}
193182

194183
// Check if we have a template to render
195-
$contentType = $content['contentType'] ?? '';
184+
$contentType = $content->contentType;
196185
if ($contentType) {
197186
$viewPath = 'dotcms.content-types.' . strtolower($contentType);
198187
if (view()->exists($viewPath)) {
@@ -201,13 +190,12 @@ class DotCmsHelpers
201190
}
202191

203192
// Fall back to the SDK simple HTML renderer
204-
return DotCmsHelper::simpleContentHtml($content);
193+
return DotCmsHelper::simpleContentHtml($content->jsonSerialize());
205194
}
206195
}
207196
```
208197

209-
The DotCMSHelpers class provides three key functions, all leveraging the SDK's `DotCmsHelper` utility class:
210-
- `getContainersData`: Retrieves container content from the DotCMS page structure
198+
The DotCMSHelpers class provides two key functions, all leveraging the SDK's `DotCmsHelper` utility class:
211199
- `htmlAttr`: Safely generates HTML attributes from arrays, handling special cases like boolean attributes
212200
- `generateHtmlBasedOnProperty`: Renders content intelligently by looking for type-specific templates or falling back to the SDK's default renderer
213201

@@ -446,37 +434,31 @@ This page template:
446434

447435
```php
448436
@php
449-
$containerObject = $dotCmsHelpers->getContainersData($containers, $container);
450-
$containerContentKey = 'uuid-' . $container['uuid'];
451-
$containerContent = isset($containerObject['contentlets'][$containerContentKey])
452-
? $containerObject['contentlets'][$containerContentKey]
453-
: [];
454-
455437
$containerAttrs = [
456438
'data-dot-object' => 'container',
457-
'data-dot-identifier' => $container['identifier'] ?? '',
458-
'data-dot-accept-types' => $containerObject['acceptTypes'] ?? '',
459-
'data-max-contentlets' => $containerObject['maxContentlets'] ?? '',
460-
'data-dot-uuid' => $container['uuid'] ?? ''
439+
'data-dot-identifier' => $container->identifier,
440+
'data-dot-accept-types' => $container->acceptTypes,
441+
'data-max-contentlets' => $container->maxContentlets,
442+
'data-dot-uuid' => $container->uuid
461443
];
462444
@endphp
463445

464446
<div {!! $dotCmsHelpers->htmlAttr($containerAttrs) !!}>
465-
@foreach($containerContent as $content)
447+
@foreach($container->contentlets as $content)
466448
@php
467449
$contentAttrs = [
468450
'data-dot-object' => 'contentlet',
469-
'data-dot-identifier' => $content['identifier'] ?? '',
470-
'data-dot-basetype' => $content['baseType'] ?? '',
471-
'data-dot-title' => $content['widgetTitle'] ?? $content['title'] ?? '',
472-
'data-dot-inode' => $content['inode'] ?? '',
473-
'data-dot-type' => $content['contentType'] ?? '',
451+
'data-dot-identifier' => $content->identifier,
452+
'data-dot-basetype' => $content->baseType,
453+
'data-dot-title' => $content->widgetTitle ?? $content->title,
454+
'data-dot-inode' => $content->inode,
455+
'data-dot-type' => $content->contentType,
474456
'data-dot-container' => json_encode([
475-
'acceptTypes' => $containerObject['acceptTypes'] ?? '',
476-
'identifier' => $container['identifier'] ?? '',
477-
'maxContentlets' => $containerObject['maxContentlets'] ?? '',
478-
'variantId' => $containerObject['variantId'] ?? '',
479-
'uuid' => $container['uuid'] ?? ''
457+
'acceptTypes' => $container->acceptTypes,
458+
'identifier' => $container->identifier,
459+
'maxContentlets' => $container->maxContentlets,
460+
'variantId' => $container->variantId,
461+
'uuid' => $container->uuid
480462
])
481463
];
482464
@endphp
@@ -489,7 +471,6 @@ $containerAttrs = [
489471
```
490472

491473
The container template:
492-
- Extracts container data using helper functions
493474
- Sets up data attributes for DotCMS integration and edit-mode functionality
494475
- Iterates through content items in the container
495476
- Adds necessary metadata attributes to each content element

0 commit comments

Comments
 (0)