Create form view.

@param BlockView      $view
@param BlockInterface $block

@return FormView
17480
public static function createFormView(BlockView $view, BlockInterface $block)
    {
        $parentForm = static::getParentFormView($view);

        if (null !== $parentForm) {
            $formPath = $block->hasOption('form_path') && null !== $block->getOption('form_path')
                ? $block->getOption('form_path')
                : $block->getName();
            $formNames = explode('.', $formPath);
            $form = $parentForm->vars['form'];

            foreach ($formNames as $formName) {
                if (isset($form->children[$formName])) {
                    $form = $form->children[$formName];
                }
            }

            if ($form !== $parentForm->vars['form']) {
                return $form;
            }
        }

        return $block->getForm()->createView($parentForm);
    }
70984
public function show(ReadBlockInterface $block)
    {
        $request = $this->requestStack->getCurrentRequest();

        $data = $request->get('elastica_search');
        $searchData = array();
        if (is_array($data) && array_key_exists('search', $data) && null !== $data['search']) {
            $searchParameter = $data['search'];

            $index = $this->client->getIndex($this->indexName);

            $qb = new QueryBuilder();

            $search = new Search($this->client);
            $search->addIndex($index);
            $search->setQuery($qb->query()->filtered(
                $qb->query()->query_string($searchParameter),
                $qb->filter()->bool()->addMust(
                    $qb->filter()->term(array('language' => $request->getLocale()))
                )
            ));
            $searchData = $search->search(null, array('limit' => $block->getAttribute('searchLimit')));
        }

        return $this->render('OpenOrchestraElasticaFrontBundle:Block/List:show.html.twig', array(
            'searchData' => $searchData,
            'id' => $block->getId(),
            'class' => $block->getStyle(),
        ));
    }
1066393
protected function constructView($mixed)
    {
        if ($mixed instanceof Block) {
            $this->blockType = $mixed->getBlockTypeObject();
            $this->block = $mixed;
            $this->area = $mixed->getBlockAreaObject();
        } else {
            $this->blockType = $mixed;
            if ($this->blockType->controller) {
                $this->controller = $this->blockType->controller;
            }
        }
        $this->blockTypePkgHandle = $this->blockType->getPackageHandle();
        if (!isset($this->controller)) {
            if (isset($this->block)) {
                $this->controller = $this->block->getInstance();
                $this->controller->setBlockObject($this->block);
            } else {
                $this->controller = $this->blockType->getController();
            }
        }
    }
88064
protected function getLastRow(BlockInterface $block)
    {
        if ($block->hasAttribute('last_row')) {
            $row = $block->get($block->getAttribute('last_row'));

            // return current row
            if (\count($row) < $row->getOption('column')) {
                return $row;
            }
        }

        // new row
        $rowName = BlockUtil::createUniqueName();
        $block->add($rowName, PanelRowType::class);

        return $block->get($rowName);
    }
596787
public function show(ReadBlockInterface $block)
    {
        $nodes = $this->getNodes();

        return $this->render(
            'OpenOrchestraDisplayBundle:Block/Menu:tree.html.twig',
            array(
                'tree' => $nodes,
                'id' => $block->getId(),
                'class' => $block->getStyle(),
            )
        );
    }
1371665
public function addBlock($blockId, ModelInterface $block)
    {
        $this->blockPool->add($blockId, $block);
        return $this;
    }
658536
public function searchAndRenderBlock(BaseView $view, string $blockNameSuffix, array $variables = [])
    {
        $viewCacheKey = $view->vars[self::CACHE_KEY_VAR];
        $viewAndSuffixCacheKey = $viewCacheKey.$blockNameSuffix;

        // In templates, we have to deal with two kinds of block hierarchies:
        //
        //   +---------+          +---------+
        //   | Theme B | -------> | Theme A |
        //   +---------+          +---------+
        //
        //   column_cell -------> column_cell
        //       ^
        //       |
        //   text_cell -----> text_cell
        //
        // The first kind of hierarchy is the theme hierarchy. This allows to
        // override the block "text_cell" from Theme A in the extending
        // Theme B. This kind of inheritance needs to be supported by the
        // template engine and, for example, offers "parent()" or similar
        // functions to fall back from the custom to the parent implementation.
        //
        // The second kind of hierarchy is the column type hierarchy. This allows
        // to implement a custom "text_cell" block (no matter in which theme),
        // or to fallback to the block of the parent type, which would be
        // "column_cell" in this example (again, no matter in which theme).
        // If the designers wants to explicitly fallback to "column_cell" in the
        // custom "text_cell", for example because they only wants to wrap
        // a <div> around the original implementation, they can simply call the
        // widget() function again to render the block for the parent type.
        //
        // The second kind is implemented in the following blocks.
        if (!isset($this->blockNameHierarchyMap[$viewAndSuffixCacheKey])) {
            // INITIAL CALL
            // Calculate the hierarchy of template blocks and start on
            // the bottom level of the hierarchy (= "_<id>_<section>" block)
            $blockNameHierarchy = [];

            foreach ($view->vars['block_prefixes'] as $blockNamePrefix) {
                $blockNameHierarchy[] = $blockNamePrefix.'_'.$blockNameSuffix;
            }

            $hierarchyLevel = count($blockNameHierarchy) - 1;
            $hierarchyInit = true;
        } else {
            // RECURSIVE CALL
            // If a block recursively calls searchAndRenderBlock() again, resume rendering
            // using the parent type in the hierarchy.
            $blockNameHierarchy = $this->blockNameHierarchyMap[$viewAndSuffixCacheKey];
            $hierarchyLevel = $this->hierarchyLevelMap[$viewAndSuffixCacheKey] - 1;

            $hierarchyInit = false;
        }

        // The variables are cached globally for a view (instead of for the
        // current suffix)
        if (!isset($this->variableStack[$viewCacheKey])) {
            $this->variableStack[$viewCacheKey] = [];

            // The default variable scope contains all view variables, merged with
            // the variables passed explicitly to the helper
            $scopeVariables = $view->vars;

            $varInit = true;
        } else {
            // Reuse the current scope and merge it with the explicitly passed variables
            $scopeVariables = end($this->variableStack[$viewCacheKey]);

            $varInit = false;
        }

        // Load the resource where this block can be found
        $resource = $this->engine->getResourceForBlockNameHierarchy($view, $blockNameHierarchy, $hierarchyLevel);

        // Update the current hierarchy level to the one at which the resource was
        // found. For example, if looking for "text_cell", but only a resource
        // is found for its parent "column_cell", then the level is updated here
        // to the parent level.
        $hierarchyLevel = $this->engine->getResourceHierarchyLevel($view, $blockNameHierarchy, $hierarchyLevel);

        // The actually existing block name in $resource
        $blockName = $blockNameHierarchy[$hierarchyLevel];

        // Escape if no resource exists for this block
        if (!$resource) {
            if (count($blockNameHierarchy) !== count(array_unique($blockNameHierarchy))) {
                throw new LogicException(
                    sprintf(
                        'Unable to render the %s because the block names array contains duplicates: "%s".',
                        $blockNameSuffix,
                        implode('", "', array_reverse($blockNameHierarchy))
                    )
                );
            }

            throw new LogicException(
                sprintf(
                    'Unable to render the %s as none of the following blocks exist: "%s".',
                    $blockNameSuffix,
                    implode('", "', array_reverse($blockNameHierarchy))
                )
            );
        }

        // Merge the passed with the existing attributes
        if (isset($variables['attr'], $scopeVariables['attr'])) {
            $variables['attr'] = array_replace($scopeVariables['attr'], $variables['attr']);
        }

        // Merge the passed with the exist *label* attributes
        if (isset($variables['label_attr'], $scopeVariables['label_attr'])) {
            $variables['label_attr'] = array_replace($scopeVariables['label_attr'], $variables['label_attr']);
        }

        // Merge the passed with the exist *header* attributes
        if (isset($variables['header_attr'], $scopeVariables['header_attr'])) {
            $variables['header_attr'] = array_replace($scopeVariables['header_attr'], $variables['header_attr']);
        }

        // Merge the passed with the exist *cell* attributes
        if (isset($variables['cell_attr'], $scopeVariables['cell_attr'])) {
            $variables['cell_attr'] = array_replace($scopeVariables['cell_attr'], $variables['cell_attr']);
        }

        // Do not use array_replace_recursive(), otherwise array variables
        // cannot be overwritten
        $variables = array_replace($scopeVariables, $variables);

        // In order to make recursive calls possible, we need to store the block hierarchy,
        // the current level of the hierarchy and the variables so that this method can
        // resume rendering one level higher of the hierarchy when it is called recursively.
        //
        // We need to store these values in maps (associative arrays) because within a
        // call to widget() another call to widget() can be made, but for a different view
        // object. These nested calls should not override each other.
        $this->blockNameHierarchyMap[$viewAndSuffixCacheKey] = $blockNameHierarchy;
        $this->hierarchyLevelMap[$viewAndSuffixCacheKey] = $hierarchyLevel;

        // We also need to store the variables for the view so that we can render other
        // blocks for the same view using the same variables as in the outer block.
        $this->variableStack[$viewCacheKey][] = $variables;

        // Don't optimize these to a protected method, this method will be called at least
        // 5000 times for a grid with 500 rows and it's headers!
        $vars = [
            'vars' => $variables,
            'name' => $view->name ?? null,
        ];

        if ($view instanceof DatagridView) {
            $vars['columns'] = $view->columns;
            $vars['rows'] = $view->getIterator();
        } elseif ($view instanceof HeaderView) {
            $vars['label'] = $variables['label'] ?? $view->label;
            $vars['datagrid'] = $view->datagrid;
        } elseif ($view instanceof CellView) {
            $vars['datagrid'] = $view->datagrid;
            $vars['column'] = $view->column;
            $vars['use_raw'] = $view->useRaw;
            $vars['value'] = $view->value;
            $vars['source'] = $view->source;
        }

        // Do the rendering
        $html = $this->engine->renderBlock($view, $resource, $blockName, $vars);

        // Clear the stack
        array_pop($this->variableStack[$viewCacheKey]);

        // Clear the caches if they were filled for the first time within
        // this function call
        if ($hierarchyInit) {
            unset($this->blockNameHierarchyMap[$viewAndSuffixCacheKey], $this->hierarchyLevelMap[$viewAndSuffixCacheKey]);
        }

        if ($varInit) {
            unset($this->variableStack[$viewCacheKey]);
        }

        return $html;
    }
866946
protected function populateView($view)
    {
        $view = $this->initViewVars($view);
        $view = $this->initViewContentBlocks($view);

        return $view;
    }
125804
public function execute(BlockInterface $block, Response $response = null, array $parameters = [])
    {
        $collection = $this->contentManager->getRepository()->findOrderedByIds(json_decode($block->getValue()));

        if ($collection) {
            $block->setCollection($collection);
        }

        return parent::execute($block, $response, $parameters);
    }
501376
public function parentBlockWidget(BlockView $view, array $variables = [])
    {
        return $this->renderer->searchAndRenderBlock($view, 'widget', $variables, true);
    }
447897
public function show(ReadBlockInterface $block)
    {
        $parameters = $this->getParameters();

        $currentPage = $this->request->get(NavigatorExtension::PARAMETER_PAGE);
        if (!$currentPage) {
            $currentPage = 1;
        }

        return $this->render(
            $this->template,
            array(
                'galleryClass' => $block->getStyle(),
                'id' => $block->getId(),
                'pictures' => $this->filterMedias($block->getAttribute('pictures'), $currentPage, $block->getAttribute('itemNumber')),
                'numberOfColumns' => $block->getAttribute('columnNumber'),
                'thumbnailFormat' => $block->getAttribute('thumbnailFormat'),
                'imageFormat' => $block->getAttribute('imageFormat'),
                'numberOfPages' => ($block->getAttribute('itemNumber') == 0) ? 1 : ceil(count($block->getAttribute('pictures')) / $block->getAttribute('itemNumber')),
                'parameters' => $parameters,
                'currentPage' => $currentPage,
                'width' => $block->getAttribute('width'),
            )
        );
    }
819942
public function create(BlockRequest $request)
    {

        $block = $this->repository->newInstance([]);
        return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('block::block.name')) 
            ->view('block::admin.block.create') 
            ->data(compact('block'))
            ->output();
    }
450715
private function recursiveBuildFinalBlockTree(BlockInterface $block = null, BlockView $view, &$output = null)
    {
        $viewHash = spl_object_hash($view);
        $blockHash = null;

        if (null !== $block) {
            $blockHash = spl_object_hash($block);
        } elseif (isset($this->blocksByView[$viewHash])) {
            $blockHash = $this->blocksByView[$viewHash];
        }

        $output = isset($this->dataByView[$viewHash])
            ? $this->dataByView[$viewHash]
            : [];

        if (null !== $blockHash) {
            $output = array_replace(
                $output,
                isset($this->dataByBlock[$blockHash])
                    ? $this->dataByBlock[$blockHash]
                    : []
            );
        }

        $this->validateViewIds($block, $view);

        $output['children'] = [];

        foreach ($view->children as $name => $childView) {
            // The CSRF token, for example, is never added to the block tree.
            // It is only present in the view.
            $childBlock = null !== $block && $block->has($name)
                ? $block->get($name)
                : null;

            $childHash = spl_object_hash($childView);
            $output['children'][$childHash] = [];

            $this->recursiveBuildFinalBlockTree($childBlock, $childView, $output['children'][$childHash]);
        }
    }
113487
public static function getParent(BlockView $view, $type)
    {
        $parent = null;

        if (null !== $view->parent) {
            if (static::isType($view->parent, $type)) {
                $parent = $view->parent;
            } else {
                $parent = static::getParent($view->parent, $type);
            }
        }

        return $parent;
    }
987453
public function renderBlock(BlockInterface $block, $arguments = array())
    {
        /** @var BlockManager $manager */
        $manager = $this->container->get('opifer.content.block_manager');

        $service = $manager->getService($block);

        if ($this->blockEnvironment->getBlockMode($block) == 'manage') {
            $content =  $service->setEnvironment($this->blockEnvironment)->manage($block)->getContent();
//            $block->isRendered = true;
//
//            // TODO check for unrendered blocks
//            if ($block instanceof BlockContainerInterface) {
//                foreach ($block->getChildren() as $child) {
//                    if (!property_exists($child, 'isRendered') || $child->isRendered) {
//                        $content .= $manager->getService($child)->manage($child)->getContent();
//                    }
//                }
//            }

            return $content;
        }

        return $service->execute($block)->getContent();
    }
992247
public function buildView(FormView $view, FormInterface $form, array $options)
    {   
        $data = $form->getData();
        $view->vars['configs'] = array_merge(array(
            'dependent_value' => isset($data[$options['second_name']]) ? $data[$options['second_name']] : null
        ), $options['configs']);
        
    }
440535
private function createFormView(FormInterface $form)
    {
        $themes = $this->getParameterResolver()->resolveThemes();
        $view = $form->createView();

        if (!empty($themes)) {
            $this->formRenderer->setTheme($view, $themes);
        }

        return $view;
    }