Replies: 2 comments 1 reply
-
You may be able to do that via the get method of a custom resolver class. More info here. |
Beta Was this translation helpful? Give feedback.
1 reply
-
I know this discussion is a little older, but I managed to force a layout by default using a Custom Resolver as @voidgraphics said. <?php
namespace App\Nova\Flexible\Resolvers;
use Illuminate\Support\Str;
use Whitecube\NovaFlexibleContent\Value\Resolver;
use Whitecube\NovaFlexibleContent\Value\ResolverInterface;
class LessonBodyResolver extends Resolver implements ResolverInterface
{
/**
* Resolve the Flexible field's content.
*
* @param mixed $resource
* @param string $attribute
* @param \Whitecube\NovaFlexibleContent\Layouts\Collection $layouts
* @return \Illuminate\Support\Collection<array-key, \Whitecube\NovaFlexibleContent\Layouts\Layout>
*/
public function get($resource, $attribute, $layouts)
{
if (is_null($resource->$attribute)) {
$value = json_decode('[{"layout":"textblock","key":"'. Str::random() .'","attributes":{}}]');
} else {
$value = $this->extractValueFromResource($resource, $attribute);
}
return collect($value)->map(function ($item) use ($layouts) {
$layout = $layouts->find($item->layout);
if (! $layout) {
return null;
}
return $layout->duplicateAndHydrate($item->key, (array) $item->attributes);
})->filter()->values();
}
} Of course, this could probably be improved, but at least I was able to set the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to force nova-flexible-content to start with some layouts already added to the field?
Beta Was this translation helpful? Give feedback.
All reactions