Skip to content

Commit

Permalink
fix(blocks): Fix block registration
Browse files Browse the repository at this point in the history
  • Loading branch information
Log1x authored Mar 31, 2020
1 parent 99d9b3d commit cb8f1fe
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/Poet.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,28 @@ protected function registerTaxonomies()
*/
protected function registerBlocks()
{
return $this->config->only('block')->each(function ($config, $key) {
$config = collect($config);
return $this->config->only('block')->each(function ($block) {
foreach ($block as $key => $value) {
if (empty($key)) {
$key = $value;
}

if (! Str::contains($key, '/')) {
$key = Str::start($key, $this->namespace());
}
$value = collect($value);

return register_block_type($key, [
'attributes' => $config->get('attributes', []),
'render_callback' => function ($data, $content) use ($key, $config) {
return view($config->get('view', 'blocks.' . Str::after($key, '/')), [
'data' => (object) $data,
'content' => $config->get('strip', true) && $this->isEmpty($content) ? false : $content
]);
},
]);
if (! Str::contains($key, '/')) {
$key = Str::start($key, $this->namespace());
}

return register_block_type($key, [
'attributes' => $value->get('attributes', []),
'render_callback' => function ($data, $content) use ($key, $value) {
return view($value->get('view', 'blocks.' . Str::after($key, '/')), [
'data' => (object) $data,
'content' => $value->get('strip', true) && $this->isEmpty($content) ? false : $content
]);
},
]);
}
});
}

Expand Down

0 comments on commit cb8f1fe

Please # to comment.