Deletes the block.

@param Model\BlockInterface $block

@return Model\BlockInterface The removed block.
@throws InvalidOperationException
547601
public function delete(Model\BlockInterface $block)
    {
        // Ensure not named / alone
        if ($block->isAlone() || $block->isNamed()) {
            throw new InvalidOperationException(
                "The block can't be removed because it is named or the parent row does not have enough children."
            );
        }

        if (null === $row = $block->getRow()) {
            throw new InvalidOperationException(
                "This block does not belong to a row and therefore can't be removed."
            );
        }

        // Plugin remove
        $this->editor
            ->getBlockPlugin($block->getType())
            ->remove($block);

        // Remove from row
        $row->removeBlock($block);

        // Fix row's blocks positions
        $this->editor
            ->getRowManager()
            ->fixBlocksPositions($row);

        return $block;
    }
1275317
private function loadBlockDefaults(BlockInterface $block)
    {
        $service = $this->blockManager->get($block);

        $resolver = new OptionsResolver();
        // use new interface method whenever possible
        // NEXT_MAJOR: Remove this check and legacy setDefaultSettings method call
        if (method_exists($service, 'configureSettings')) {
            $service->configureSettings($resolver);
        } else {
            $service->setDefaultSettings($resolver);
        }

        try {
            $block->setSettings($resolver->resolve($block->getSettings()));
        } catch (InvalidOptionsException $e) {
            // @TODO : add a logging error or a flash message
        }

        $service->load($block);

        return $block;
    }
1283523
public function render(AbstractBlock $block, CliRenderer $renderer)
    {
        if (!($block instanceof Paragraph)) {
            throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
        }

        return $renderer->renderInlines($block->children()) . "\n";
    }
544038
public function getBlockParameter(ReadBlockInterface $block)
    {
        $strategy = $this->getStrategy($block);
        if (null === $strategy) {
            throw new DisplayBlockStrategyNotFoundException($block->getComponent());
        }

        return $strategy->getBlockParameter();
    }
234647
public function moveDown(Model\ContainerInterface $container)
    {
        $sibling = $this->editor->getRepository()->findSiblingContainer($container, true);
        if (null === $sibling) {
            throw new InvalidOperationException(
                "The container can't be moved down as no sibling container has been found."
            );
        }

        $container->setPosition($container->getPosition() + 1);
        $sibling->setPosition($sibling->getPosition() - 1);

        $this->sortChildrenByPosition($container->getContent(), 'containers');

        return $sibling;
    }
743313
public static function createBlockId(BlockInterface $block)
    {
        $id = '_'.$block->getName();

        if ($block->getParent() && $block->getOption('chained_block')) {
            $id = static::createBlockId($block->getParent()).$id;
        }

        return ltrim($id, '_0123456789');
    }
1280256
public function render(AbstractBlock $block, CliRenderer $renderer)
    {
        if (!($block instanceof ListBlock)) {
            throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
        }

        return $renderer->renderBlocks($block->children());
    }
827714
public function findSiblingBlock(EM\BlockInterface $block, $next = false)
    {
        if (null === $row = $block->getRow()) {
            return null;
        }

        return $this->findSibling($row->getBlocks(), $block, $next);
    }
720324
public function findByOwner(BlockInterface $owner, $version = false)
    {
        $blocks = $this->getRepository()->findBy(['owner' => $owner], ['sort' => 'asc']);

        if ($version) {
            foreach ($blocks as $key => $block) {
                $this->revertSingle($block, $version);

                if ($block->getDeletedAt() && $block->getDeletedAt() < new \DateTime) {
                    unset($blocks[$key]);
                }
            }
        }

        usort($blocks, function ($a, $b) {
            return ($a->getSort() < $b->getSort()) ? -1 : 1;
        });

        return $blocks;
    }
1323609
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
    {
        if (!($block instanceof FencedCode)) {
            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
        }

        $language = $this->getLanguage($block->getInfoWords(), $htmlRenderer);

        return $this->getHTMLElement($block->getStringContent(), $language);
    }
1301048
public function save(BlockInterface $block, $draft = true)
    {
        $this->setDraftVersionFilter(! $draft);
        $block->setDraft($draft);

        $this->em->persist($block);
        $this->em->flush($block);

        return $this;
    }
971259
public function moveUp(Model\BlockInterface $block)
    {
        $row = $block->getRow();
        if (null === $row || $row->isFirst()) {
            throw new InvalidOperationException(
                "This block can't be moved to the top."
            );
        }

        $sibling = $this->editor->getRepository()->findSiblingRow($row, false);
        if (null === $sibling) {
            throw new InvalidOperationException(
                "The block can't be moved to the top as no sibling row has been found."
            );
        }

        $row->removeBlock($block);
        $sibling->addBlock($block);

        $this->editor
            ->getRowManager()
            ->fixBlocksPositions($row)
            ->fixBlocksPositions($sibling);

        return $sibling;
    }
941651
public function delete()
    {
        if (null === $this->alBlock) {
            throw new General\ArgumentIsEmptyException('exception_no_blocks_set_delete_skipped');
        }

        $this->dispatchBeforeOperationEvent(
            '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\BeforeBlockDeletingEvent',
            BlockEvents::BEFORE_DELETE_BLOCK,
            array(),
            'exception_block_removing_aborted'
        );

        try {
            $this->blockRepository->startTransaction();

            $result = $this->blockRepository
                        ->setRepositoryObject($this->alBlock)
                        ->delete();
            if ($result) {
                $this->blockRepository->commit();
                $this->eventsHandler
                     ->createEvent(BlockEvents::AFTER_DELETE_BLOCK, '\RedKiteLabs\RedKiteCms\RedKiteCmsBundle\Core\Event\Content\Block\AfterBlockDeletedEvent', array($this))
                     ->dispatch();

                return true;
            }

            $this->blockRepository->rollBack();

            return false;
        } catch (\Exception $e) {
            if (isset($this->blockRepository) && $this->blockRepository !== null) {
                $this->blockRepository->rollBack();
            }

            throw $e;
        }
    }
483719
private function isAllowed($blockId, ModelInterface $block)
    {
        $result = $this->getEventManager()->trigger(
            __FUNCTION__,
            $this,
            [
                'block_id' => $blockId,
                'block' => $block
            ]
        );
        if ($result->stopped()) {
            return $result->last();
        }
        return true;
    }
173506
public function removeNode(NodeInterface $node): NodeInterface
    {
        unset($this->_nodes[$node->getId()]);

        if ($this->getParent()) {
            $this->getParent()->removeNode($node);
        }

        return $this;
    }
1365606
public function renderEsi(BlockInterface $block)
    {
        $reference = new ControllerReference(
            'OpiferContentBundle:Frontend/Block:view',
            ['id' => $block->getId()],
            $this->getRequest()->query->all()
        );

        return $this->fragmentHandler->render($reference, 'esi');
    }
629736
private function internalDisableTranslations(PersistenceBlock $block): PersistenceBlock
    {
        $block = $this->blockHandler->updateBlock(
            $block,
            BlockUpdateStruct::fromArray(
                [
                    'isTranslatable' => false,
                ]
            )
        );

        foreach ($block->availableLocales as $locale) {
            if ($locale !== $block->mainLocale) {
                $block = $this->blockHandler->deleteBlockTranslation(
                    $block,
                    $locale
                );
            }
        }

        foreach ($this->blockHandler->loadChildBlocks($block) as $childBlock) {
            $this->internalDisableTranslations($childBlock);
        }

        return $block;
    }