feat: global instance in the builder's format, deglobalize, library content rules
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -141,6 +141,30 @@ final class Block extends Container
|
||||
return clone $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A deep copy of this block under another name and attributes: opener and closer are
|
||||
* regenerated, children and the text between them are kept, the void flag too. Opaque exactly
|
||||
* when the Parser would make it so. GlobalInstance uses it to turn a library root into an
|
||||
* instance and back.
|
||||
*
|
||||
* @param array<string, mixed> $attrs
|
||||
*/
|
||||
public function copyAs(string $name, array $attrs): self
|
||||
{
|
||||
if (preg_match(self::NAME_PATTERN, $name) !== 1) {
|
||||
throw new InvalidArgumentException(sprintf('"%s" is not a valid block name.', $name));
|
||||
}
|
||||
|
||||
$copy = clone $this;
|
||||
$copy->name = $name;
|
||||
$copy->attrs = self::deepCloneAttrs($attrs);
|
||||
$copy->rawOpen = null;
|
||||
$copy->rawClose = null;
|
||||
$copy->opaque = $name === 'divi/global-layout' || array_key_exists('globalModule', $attrs);
|
||||
|
||||
return $copy;
|
||||
}
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
foreach ($this->parts as $position => $part) {
|
||||
|
||||
Reference in New Issue
Block a user