@param LayoutBlock $layoutBlock

@return LayoutBlock
@throws \Doctrine\ORM\ORMException
@throws \Doctrine\ORM\OptimisticLockException
@throws \ReflectionException
19547
public function resetContent(PageInterface $page, LayoutBlock $layoutBlock, \JMS\Serializer\SerializerInterface $serializer)
    {
	    if ($contentObject = $layoutBlock->getSnapshotContent()) {
		    $contentObject = $serializer->deserialize($contentObject, $layoutBlock->getClassType(), 'json');



		    try {
			    $contentObject = $this->_em->merge($contentObject);
			    $reflection = new \ReflectionClass($contentObject);
			    foreach ($reflection->getProperties() as $property) {
				    $method = sprintf('get%s', ucfirst($property->getName()));
				    if ($reflection->hasMethod($method) && $var = $contentObject->{$method}()) {
					    if ($var instanceof ArrayCollection) {
						    foreach ($var as $key =>  $v) {
							    $v = $this->_em->merge($v);

							    $var->set($key, $v);
						    }
						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $contentObject->{$method}($var);
					    }

					    if(is_object($var) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($var))){
						    $var = $this->_em->merge($var);

						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $contentObject->{$method}($var);
					    }
				    }
			    }

			    $this->_em->persist($contentObject);
			    $this->_em->flush($contentObject);

		    } catch (EntityNotFoundException $e) {
			    $classType = $layoutBlock->getClassType();
			    $newContentObject = clone $contentObject;
			    $reflection = new \ReflectionClass($contentObject);
			    foreach ($reflection->getProperties() as $property) {
				    $method = sprintf('get%s', ucfirst($property->getName()));
				    if ($reflection->hasMethod($method) && $var = $contentObject->{$method}()) {
					    if ($var instanceof ArrayCollection) {
						    foreach ($var as $key =>  $v) {
							    $v = $this->_em->merge($v);

							    $var->set($key, $v);
						    }
						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $newContentObject->{$method}($var);
					    }

					    if(is_object($var) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($var))){
						    $var = $this->_em->merge($var);

						    $method = sprintf('set%s', ucfirst($property->getName()));
						    $newContentObject->{$method}($var);
					    }

				    }
			    }
			    $this->_em->persist($newContentObject);
			    $this->_em->flush($newContentObject);


			    $layoutBlock->setObjectId($newContentObject->getId());
		    }

	    }

	    $layoutBlock->setPage($page);

	    $this->_em->persist($layoutBlock);

	    $this->_em->flush($layoutBlock);

	    return $layoutBlock;
    }
1344979
public function moveRight(Model\BlockInterface $block)
    {
        $sibling = $this->editor->getRepository()->findSiblingBlock($block, true);
        if (null === $sibling) {
            throw new InvalidOperationException(
                "The block can't be moved to the right as no sibling block has been found."
            );
        }

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

        $this->sortChildrenByPosition($block->getRow(), 'blocks');

        return $sibling;
    }
1220417
private function validateLayoutTypes(array $layoutTypes, array $blockDefinitions): void
    {
        foreach ($layoutTypes as $layoutType => $layoutTypeConfig) {
            foreach ($layoutTypeConfig['zones'] as $zoneConfig) {
                foreach ($zoneConfig['allowed_block_definitions'] as $blockDefinition) {
                    if (!isset($blockDefinitions[$blockDefinition])) {
                        throw new RuntimeException(
                            sprintf(
                                'Block definition "%s" used in "%s" layout type does not exist.',
                                $blockDefinition,
                                $layoutType
                            )
                        );
                    }
                }
            }
        }
    }
29664
public function newLayoutUpdateStruct(?Layout $layout = null): LayoutUpdateStruct
    {
        $layoutUpdateStruct = new LayoutUpdateStruct();

        if (!$layout instanceof Layout) {
            return $layoutUpdateStruct;
        }

        $layoutUpdateStruct->name = $layout->getName();
        $layoutUpdateStruct->description = $layout->getDescription();

        return $layoutUpdateStruct;
    }
410524
public function save(BlockInterface $block)
    {
        $block->setRootVersion($this->getNewVersion($block));

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

        return $this;
    }
356597
public function getCacheKeys(BlockInterface $block)
    {
        $settings = $block->getSettings();

        $keys = parent::getCacheKeys($block);

        $keys['environment'] = $this->getContainer()->get('kernel')->getEnvironment();

        if (isset($settings['template'])) {
            $keys['template'] = $settings['template'];
        }

        if (isset($settings['id'])) {
            $key = $this->getName() . ':' . $settings['id'];

            if (isset($settings['template'])) {
                $key = $key . ':' . $settings['template'];
            }

            $keys['block_id'] = $key;
        }

        $keys['updated_at'] = '';

        return $keys;
    }
544745
protected function _generateBlock($node, $parent)
    {
        if ($node instanceof Mage_Core_Model_Layout_Element) {
            if (!$this->checkConditionals($node)) {
                return $this;
            }
        }

        return parent::_generateBlock($node, $parent);
    }
606717
public function renderInitcmsAdminBlock(LayoutBlockInterface $layoutBlock)
    {
        if ($layoutBlock->getObjectId()) {
            // Draft View
            $contentItem = $layoutBlock->getContent();
        } else {
            $classType = $layoutBlock->getClassType();
            $contentItem = new $classType();
        }

        if (!is_object($contentItem)) {
            $this->layoutBlockAdmin->delete($layoutBlock);

            return false;
        }

        $adminContent = $contentItem->getAdminContent();

        return $this->templating->render($adminContent['template'], $adminContent['content']);
    }
1009849
protected function block(OutputBlock $block)
    {
        if (empty($block->lines) && empty($block->children)) {
            return;
        }

        $this->currentBlock = $block;

        $pre = $this->indentStr();

        if (! empty($block->selectors)) {
            $this->blockSelectors($block);

            $this->indentLevel++;
        }

        if (! empty($block->lines)) {
            $this->blockLines($block);
        }

        if (! empty($block->children)) {
            $this->blockChildren($block);
        }

        if (! empty($block->selectors)) {
            $this->indentLevel--;

            if (empty($block->children)) {
                $this->write($this->break);
            }

            $this->write($pre . $this->close . $this->break);
        }
    }
818170
protected function cleanUpBlockLayout(Model\BlockInterface $block, array $data)
    {
        $clean = [];

        // TODO responsive padding
        if (isset($data[static::PADDING_TOP]) && 0 < $data[static::PADDING_TOP]) {
            $clean[static::PADDING_TOP] = $data[static::PADDING_TOP];
        }
        if (isset($data[static::PADDING_BOTTOM]) && 0 < $data[static::PADDING_BOTTOM]) {
            $clean[static::PADDING_BOTTOM] = $data[static::PADDING_BOTTOM];
        }

        $hasPreviousSize = $hasPreviousOffset = false;
        $previousSize = $previousOffset = null;

        /** @var Model\BlockInterface[] $blocks */
        $blocks = [];
        if (null !== $row = $block->getRow()) {
            $blocks = $row->getBlocks()->filter(function (Model\BlockInterface $b) use ($block) {
                return $b !== $block;
            });
        }

        $devices = array_reverse(array_keys(static::getDevices()));

        foreach ($devices as $device) {
            // Do we need to clear the previous block layout (which size is lower than 12)
            $clear = false;
            foreach ($blocks as $b) {
                $d = $b->getLayout();
                if (isset($d[$device][static::SIZE]) && 12 > $d[$device][static::SIZE]) {
                    $clear = true;
                    break;
                }
            }

            // If layout is set for this device
            if (!$clear && !isset($data[$device])) {
                continue;
            }

            $size = isset($data[$device][static::SIZE]) ? $data[$device][static::SIZE] : $previousSize;
            $offset = isset($data[$device][static::OFFSET]) ? $data[$device][static::OFFSET] : $previousOffset;

            $cleanDevice = [];

            if ($clear || ($hasPreviousSize && $previousSize != $size) || (!$hasPreviousSize && 12 > $size)) {
                $cleanDevice[static::SIZE] = $size;
            }
            if (($hasPreviousOffset && $previousOffset != $offset) || (!$previousOffset && 0 < $offset)) {
                $cleanDevice[static::OFFSET] = $offset;
            }

            if (!$hasPreviousSize && 12 > $size) {
                $hasPreviousSize = true;
            }
            if (!$hasPreviousOffset && 0 < $offset) {
                $hasPreviousOffset = true;
            }

            $previousSize = $size;
            $previousOffset = $offset;

            if (!empty($cleanDevice)) {
                $clean[$device] = $cleanDevice;
            }
        }

        return $clean;
    }
666340
public function manipulate(\DOMDocument $document, LayoutInterface $layout): void
    {
        foreach ($layout->getBlocks() as $block) {
            switch ($block->getType()) {
                case BlockInterface::PREPEND:
                    $this->prependBlock($document, $block);
                    break;
                case BlockInterface::APPEND:
                    $this->appendBlock($document, $block);
                    break;
                case BlockInterface::REPLACE:
                    $this->replaceBlock($document, $block);
                    break;
            }
        }
    }
102451
public function resetLayoutBlock($publishedBlocks)
    {

	    $blocksToRemove = $this->layoutBlock->filter(function(LayoutBlock $originalBlock) use($publishedBlocks){
			$toRemove = true;
	    	foreach ($publishedBlocks as $block){
	    		if(!$block->getId()){
				    $toRemove = false;
			    }

				if($block->getId() == $originalBlock->getId()){
					$toRemove = false;
				}
			}

			return $toRemove;
	    });

        foreach ($blocksToRemove as $block) {
				$block->setNoAutoDraft(true);
				$this->layoutBlock->removeElement($block);
        }

    }
553545
function blockSet(BlockInterface $block, $templateFile) {
		$this->_blockStack[]= $block;
		$this->_templateFileStack[]= $templateFile;
	}
1118734
public function renderBlock(AbstractBlock $block)
    {
        $renderer = $this->getBlockRendererForClass(get_class($block));
        if (!$renderer) {
            throw new RuntimeException(
                sprintf('Unable to find corresponding renderer for block type: "%s"', get_class($block))
            );
        }

        return $renderer->render($block, $this);
    }
654449
public function removeBlock(Block $block)
	{
		if (! $this->equals($block->getPlaceHolder())
				|| ! $this->blocks->contains($block)) {
			throw new \InvalidArgumentException('Block does not belongs to this placeholder.');
		}

		$position = $block->getPosition();
	
		$this->blocks->removeElement($block);

		foreach ($this->blocks as $existingBlock) {
			if ($existingBlock->getPosition() > $position) {
				$existingBlock->setPosition($existingBlock->getPosition() - 1);
			}
		}
	}
632440
public function show(ReadBlockInterface $block)
    {
        $contents = $this->getContents($block->getAttribute('contentSearch'));

        if (!is_null($contents)) {

            $parameters = array(
                'contents' => $contents,
                'class' => $block->getStyle(),
                'id' => $block->getId(),
                'characterNumber' => $block->getAttribute('characterNumber')
            );

            if ('' != $block->getAttribute('contentNodeId')) {
                $language = $this->currentSiteManager->getSiteLanguage();
                $siteId = $this->currentSiteManager->getSiteId();
                $node = $this->nodeRepository->findOnePublished($block->getAttribute('contentNodeId'), $language, $siteId);
                $parameters['contentNodeId'] = $node->getId();

                if (!$this->isGrantedNode($node)) {
                    unset($parameters['contentNodeId']);
                }
            }

            return $this->render('OpenOrchestraDisplayBundle:Block/ContentList:show.html.twig', $parameters);
        }

        throw new ContentNotFoundException();
    }
1034552
protected function compileRoot(Block $rootBlock)
    {
        $this->rootBlock = $this->scope = $this->makeOutputBlock(Type::T_ROOT);

        $this->compileChildrenNoReturn($rootBlock->children, $this->scope);
        $this->flattenSelectors($this->scope);
        $this->missingSelectors();
    }