-
Notifications
You must be signed in to change notification settings - Fork 554
/
BlocksController.php
44 lines (37 loc) · 1.28 KB
/
BlocksController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace A17\Twill\Http\Controllers\Admin;
use A17\Twill\Helpers\BlockRenderer;
use Illuminate\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\View\Factory as ViewFactory;
class BlocksController extends Controller
{
/**
* Render an HTML preview of a single block.
* This is used by the full screen content editor.
*/
public function preview(
Application $app,
ViewFactory $viewFactory,
Request $request,
): string {
if ($request->has('activeLanguage')) {
$app->setLocale($request->get('activeLanguage'));
}
$data = $request->except('activeLanguage');
$mapping = config('twill.block_editor.block_views_mappings');
if ($viewFactory->exists(config('twill.block_editor.block_single_layout'))) {
$viewFactory->inject(
'content',
BlockRenderer::fromCmsArray($data)->render($mapping, [])
);
$result = view(config('twill.block_editor.block_single_layout'));
} else {
$result = view(
'twill::errors.block_layout',
['view' => config('twill.block_editor.block_single_layout')]
);
}
return html_entity_decode($result->render());
}
}