public function getPlaceholdersAttribute()
{
if (!strlen($this->code)) {
return [];
}
if ($placeholders = array_get($this->attributes, 'placeholders')) {
return $placeholders;
}
$bodyNode = $this->getTwigNodeTree($this->code)->getNode('body')->getNode(0);
if ($bodyNode instanceof \Cms\Twig\PutNode) {
$bodyNode = [$bodyNode];
}
$result = [];
foreach ($bodyNode as $node) {
if (!$node instanceof \Cms\Twig\PutNode) {
continue;
}
$bodyNode = $node->getNode('body');
$result[$node->getAttribute('name')] = trim($bodyNode->getAttribute('data'));
}
$this->attributes['placeholders'] = $result;
return $result;
}