Replace a block by its nodes.

@param BlockElement $block
@param array        $children
504171
public function replaceBlock(BlockElement $block, array $children = null)
    {
        if ($parent = $block->getParent()) {
            foreach (array_reverse($children ?: $block->getChildren()) as $child) {
                $parent->insertAfter($block, $child);
            }
            $previous = $block->getPreviousSibling();
            if ($previous instanceof TextElement) {
                $previous->setEnd(true);
            }
            $block->remove();
        }
    }
80465
public function addBlock(Block $block)
	{
		if ($this->lock('block')) {
			$this->matchDiscriminator($block);
			if ($this->addUnique($this->blocks, $block)) {
				$block->setPlaceHolder($this);
			}
			$this->unlock('block');
		}
	}
1123196
protected function getBlocks($nodes) {
    // Each completed block.
    $blocks = array();
    // Container for any top-level inline elements.
    $block = '';
    // Add a completed block to $blocks.
    $add_block = function($string = NULL) use(&$blocks, &$block) {
      if (preg_match('/\S/u', $block)) {
        $blocks[] = trim($block, " \t");
      }
      if (preg_match('/\S/u', $string)) {
        $blocks[] = rtrim($string, " \t");
      }
      $block = '';
    };
    /** @var \DOMNode $node */
    foreach ($nodes as $node) {
      switch ($node->nodeType) {

        case XML_ELEMENT_NODE:
          /** @var \DOMElement $node */
          switch ($node->nodeName) {

            // Explicitly handle these elements.

            case 'p':
            case 'pre':
              $add_block($this->getBlock($node));
              break;

            case 'h1':
              $add_block('# ' . $this->getBlock($node));
              break;

            case 'h2':
              $add_block('## ' . $this->getBlock($node));
              break;

            case 'h3':
              $add_block('### ' . $this->getBlock($node));
              break;

            case 'h4':
              $add_block('#### ' . $this->getBlock($node));
              break;

            case 'h5':
              $add_block('##### ' . $this->getBlock($node));
              break;

            case 'h6':
              $add_block('###### ' . $this->getBlock($node));
              break;

            case 'hr':
              $add_block('***');
              break;

            case 'ul':
            case 'ol':
            case 'dl':
              $add_block($this->getBlockList($node));
              break;

            // Other block-level elements.
            case 'article':
            case 'aside':
            case 'blockquote':
            case 'dd':
            case 'div':
            case 'fieldset':
            case 'figcaption':
            case 'figure':
            case 'footer':
            case 'form':
            case 'header':
            case 'hgroup':
            case 'main':
            case 'nav':
            case 'output':
            case 'section':
              // Recursively handle any descendant elements we care about.
              foreach ($this->getBlocks($node->childNodes) as $b) {
                $add_block($b);
              }
              break;

            // Unsupported.
            case 'canvas':
            case 'noscript':
            case 'script':
            case 'table':
            case 'tfoot':
            case 'video':
              break;

            // Treat as inline element.
            default:
              // Append series of inline elements together, as if they were
              // inside a block-level element.
              $block .= $this->getBlock($node);
              break;

          }
          break;

        case XML_TEXT_NODE:
          /** @var \DOMText $node */
          $block .= self::escape($node->textContent);
          break;

      }
    }

    $add_block();
    return $blocks;
  }
753398
public void insertBlock(AbstractBaseDTNode<I, D> blockRoot) {
        blockRoot.removeFromBlockList();

        blockRoot.setNextElement(next);
        if (getNextElement() != null) {
            next.setPrevElement(blockRoot);
        }
        blockRoot.setPrevElement(this);
        next = blockRoot;
    }
838807
public function setChildren($children)
    {
        $this->clearChildren();
        foreach ($children as $child) {
            $this->addChild($child);
        }

        return $this;
    }
283371
public function replace(array $elements = array())
    {
        $this->elements = array();

        foreach ($elements as $element) {
            $this->add($element);
        }
    }
310110
public function addChild(Block $block)
    {
        $type = get_class($block);
        if (!isset($this->children[$type])) {
            $this->children[$type] = array();
        }
        $this->children[$type][] = $block;
    }
945429
private function copyBlockCollections(Block $block, Block $targetBlock): void
    {
        $collectionReferences = $this->loadCollectionReferences($block);

        foreach ($collectionReferences as $collectionReference) {
            $collection = $this->collectionHandler->loadCollection(
                $collectionReference->collectionId,
                $collectionReference->collectionStatus
            );

            $collection = $this->collectionHandler->copyCollection($collection);

            $newCollectionReference = CollectionReference::fromArray(
                [
                    'blockId' => $targetBlock->id,
                    'blockStatus' => $targetBlock->status,
                    'collectionId' => $collection->id,
                    'collectionStatus' => $collection->status,
                    'identifier' => $collectionReference->identifier,
                ]
            );

            $this->queryHandler->createCollectionReference($newCollectionReference);
        }
    }
1241490
public function setChildren(array $children)
    {

        $this->removeChildren();
        foreach ($children as $child)
            $this->appendChild($child);

        return $this;
    }
720887
protected function compileNestedBlock(Block $block, $selectors)
    {
        $this->pushEnv($block);

        $this->scope = $this->makeOutputBlock($block->type, $selectors);
        $this->scope->parent->children[] = $this->scope;

        $this->compileChildrenNoReturn($block->children, $this->scope);

        $this->scope = $this->scope->parent;

        $this->popEnv();
    }
906413
protected function processEmphasisBlock(array $block)
	{
		$this->emPos     = null;
		$this->strongPos = null;
		foreach ($block as list($matchPos, $matchLen))
		{
			$this->processEmphasisMatch($matchPos, $matchLen);
		}
	}
1237203
private function deleteChildren( $node ) {
		while ( isset( $node->firstChild ) ) {
			$this->deleteChildren( $node->firstChild );
			$node->removeChild( $node->firstChild );
		}
	}
416917
public function editBlockConfiguration(Tree $tree, int $block_id): void
    {
        $days      = (int) $this->getBlockSetting($block_id, 'days', self::DEFAULT_DAYS);
        $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', self::DEFAULT_INFO_STYLE);
        $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', self::DEFAULT_SORT_STYLE);
        $show_user = $this->getBlockSetting($block_id, 'show_user', self::DEFAULT_SHOW_USER);

        $info_styles = [
            /* I18N: An option in a list-box */
            'list'  => I18N::translate('list'),
            /* I18N: An option in a list-box */
            'table' => I18N::translate('table'),
        ];

        $sort_styles = [
            /* I18N: An option in a list-box */
            'name'      => I18N::translate('sort by name'),
            /* I18N: An option in a list-box */
            'date_asc'  => I18N::translate('sort by date, oldest first'),
            /* I18N: An option in a list-box */
            'date_desc' => I18N::translate('sort by date, newest first'),
        ];

        echo view('modules/recent_changes/config', [
            'days'        => $days,
            'infoStyle'   => $infoStyle,
            'info_styles' => $info_styles,
            'max_days'    => self::MAX_DAYS,
            'sortStyle'   => $sortStyle,
            'sort_styles' => $sort_styles,
            'show_user'   => $show_user,
        ]);
    }
632824
public function editBlockConfiguration(Tree $tree, int $block_id): void
    {
        $default_events = implode(',', self::DEFAULT_EVENTS);

        $days      = (int) $this->getBlockSetting($block_id, 'days', self::DEFAULT_DAYS);
        $filter    = $this->getBlockSetting($block_id, 'filter', self::DEFAULT_FILTER);
        $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', self::DEFAULT_STYLE);
        $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', self::DEFAULT_SORT);
        $events    = $this->getBlockSetting($block_id, 'events', $default_events);

        $event_array = explode(',', $events);

        $all_events = [];
        foreach (self::ALL_EVENTS as $event) {
            $all_events[$event] = GedcomTag::getLabel($event);
        }

        $info_styles = [
            /* I18N: An option in a list-box */
            'list'  => I18N::translate('list'),
            /* I18N: An option in a list-box */
            'table' => I18N::translate('table'),
        ];

        $sort_styles = [
            /* I18N: An option in a list-box */
            'alpha' => I18N::translate('sort by name'),
            /* I18N: An option in a list-box */
            'anniv' => I18N::translate('sort by date'),
        ];

        echo view('modules/upcoming_events/config', [
            'all_events'  => $all_events,
            'days'        => $days,
            'event_array' => $event_array,
            'filter'      => $filter,
            'infoStyle'   => $infoStyle,
            'info_styles' => $info_styles,
            'max_days'    => self::MAX_DAYS,
            'sortStyle'   => $sortStyle,
            'sort_styles' => $sort_styles,
        ]);
    }
993334
protected function loadBlocks(array $blocks, ContainerBuilder $container)
    {
        foreach ($blocks as $blockName => $block) {
            $container
                ->register(
                    'elcodi.sitemap_element_provider.entity_' . $blockName,
                    'Elcodi\Component\Sitemap\Element\EntitySitemapElementProvider'
                )
                ->addArgument(new Reference($block['repository_service']))
                ->addArgument($block['method'])
                ->addArgument($block['arguments'])
                ->setPublic(false);

            $container
                ->register(
                    'elcodi.sitemap_element_generator.entity_' . $blockName,
                    'Elcodi\Component\Sitemap\Element\EntitySitemapElementGenerator'
                )
                ->addArgument(new Reference('elcodi.factory.sitemap_element'))
                ->addArgument(new Reference($block['transformer']))
                ->addArgument(new Reference('elcodi.sitemap_element_provider.entity_' . $blockName))
                ->addArgument($block['changeFrequency'])
                ->addArgument($block['priority'])
                ->setPublic(false);
        }

        return $this;
    }
333242
protected function blockChildren(OutputBlock $block)
    {
        foreach ($block->children as $child) {
            $this->block($child);
        }
    }
830911
public function replaceChild($childId, AbstractNode $newChild)
    {
        $oldChild                        = $this->getChild($childId);
        $keys                            = array_keys($this->children);
        $index                           = array_search($childId, $keys, true);
        $keys[$index]                    = $newChild->id();
        $this->children                  = array_combine($keys, $this->children);
        $this->children[$newChild->id()] = $newChild;
        unset($oldChild);
    }