@param BlockView    $rootView
@param int|null     $rootId

@return BlockView
@throws BlockViewNotFoundException
320199
private function getRootView(BlockView $rootView, $rootId)
    {
        if ($rootId !== null) {
            $rootView = $this->findBlockById($rootView, $rootId);
            if ($rootView === null) {
                throw new BlockViewNotFoundException(sprintf("BlockView with id \"%s\" is not found.", $rootId));
            }
        }

        return $rootView;
    }
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();
    }
753044
public function execute(Request $request, $pageId, $blockId)
    {
        $cmsManager = $this->cmsManagerSelector->retrieve();

        $page = $cmsManager->getPageById($pageId);
        $block = $cmsManager->getBlock($blockId);

        if (!$block instanceof BlockInterface) {
            throw new BlockNotFoundException(sprintf('Unable to find block identifier "%s" in page "%s".', $blockId, $pageId));
        }

        $blockContext = $this->contextManager->get($block);

        return $this->blockRenderer->render($blockContext);
    }
971423
public function findDomainRecordsByRootPagesIds(array $rootPageIds = [])
    {
        $resultTmp = $this->getDomainRecordsByRootPageIds($rootPageIds);

        $result = [];
        foreach ($resultTmp as $key => $row) {
            $result[$row['pid']] = $row;
        }
        return $result;
    }
293378
public function renderFormJavascriptPrototypes(array $context, FormView $rootView)
    {
        if (!isset($rootView->vars['prototype'])) {
            throw new \InvalidArgumentException('The given root form view has no prototype');
        }

        $stack = [
            // FormView $prototype, string $prototypeName, string[] $parentPrototypeNames
            [$rootView->vars['prototype'], $rootView->vars['prototype']->vars['name'], []],
        ];

        $output = '[';
        $counter = 0;

        while (list($prototype, $prototypeName, $parentPrototypeNames) = \array_pop($stack)) {
            try {
                // the "unique_block_prefix" must be changed to prevent messing
                // up FormRenderer's internal cache and causing errors later on
                $prototype->vars['unique_block_prefix'] .= \sprintf('_%d', ++$this->prototypeRenderUidSeq);

                if (isset($prototype->vars['prototype'])) {
                    // directly nested collection prototypes lead to recursion in searchAndRenderBlock()
                    throw new \RuntimeException('Directly nested collections with prototypes are not supported. Add an intermediate type or disable prototypes.');
                }
                $code = $this->renderer->searchAndRenderBlock($prototype, 'javascript_prototype', $context);

                if (++$counter > 1) {
                    $output .= ",\n";
                }

                $output .= \sprintf(
                    '{id: %s, prototypeName: %s, parentPrototypeNames: %s, initializer: function ($field) { %s }}',
                    \json_encode($prototype->vars['id']),
                    \json_encode($prototypeName),
                    \json_encode($parentPrototypeNames),
                    $code
                );
            } catch (\LogicException $e) {
                foreach ($prototype->children as $child) {
                    $stack[] = isset($child->vars['prototype'])
                        ? [
                            $child->vars['prototype'],
                            $child->vars['prototype']->vars['name'],
                            \array_merge($parentPrototypeNames, [$prototypeName]),
                        ]
                        : [
                            $child,
                            $prototypeName,
                            $parentPrototypeNames,
                        ];
                }
            }
        }

        $output .= ']';

        return $output;
    }
199097
@Nullable static View getView(Context context, int resourceId, View view) {
    LayoutInflater inflater = LayoutInflater.from(context);
    if (view != null) {
      return view;
    }
    if (resourceId != INVALID) {
      view = inflater.inflate(resourceId, null);
    }
    return view;
  }
629314
public void index(String rootViewUuid) {
    try (DbSession dbSession = dbClient.openSession(false)) {
      Map<String, String> viewAndProjectViewUuidMap = newHashMap();
      for (ComponentDto viewOrSubView : dbClient.componentDao().selectEnabledDescendantModules(dbSession, rootViewUuid)) {
        viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.projectUuid());
      }
      index(dbSession, viewAndProjectViewUuidMap, true, Size.REGULAR);
    }
  }
44173
public function loadLayoutBlockIds($layoutId, ?int $status = null): array
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT id')
            ->from('ngbm_block')
            ->where(
                $query->expr()->eq('layout_id', ':layout_id')
            )
            ->setParameter('layout_id', $layoutId, Type::INTEGER);

        if ($status !== null) {
            $this->applyStatusCondition($query, $status);
        }

        $result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return array_column($result, 'id');
    }
192738
public function execute(&$rootDoc)
    {
        $docletFile = $this->fixPath($this->_docletPath).$this->_doclet.'/'.$this->_doclet.'.php';
        if (is_file($docletFile)) { // load doclet
            $this->message('Loading doclet "'.$this->_doclet.'"');
            require_once($this->fixPath($this->_docletPath).'/doclet.php');
            require_once($docletFile);
            $doclet =& new $this->_doclet($rootDoc, $this->getFormatter());
        } else {
            $this->error('Could not find doclet "'.$docletFile.'"');
        }
        $this->message('Done ('.round($this->_getTime() - $this->_startTime, 2).' seconds)');
    }
413147
protected function getConfiguredSolrConnectionByRootPage(array $rootPage, $languageId)
    {
        $connection = [];

        $languageId = (int)$languageId;
        GeneralUtility::_GETset($languageId, 'L');
        $connectionKey = $rootPage['uid'] . '|' . $languageId;

        $pageSelect = GeneralUtility::makeInstance(PageRepository::class);
        $rootLine = $pageSelect->getRootLine($rootPage['uid']);

        $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
        $tmpl->tt_track = false; // Do not log time-performance information
        $tmpl->init();
        $tmpl->runThroughTemplates($rootLine); // This generates the constants/config + hierarchy info for the template.

        // fake micro TSFE to get correct condition parsing
        $GLOBALS['TSFE'] = new \stdClass();
        $GLOBALS['TSFE']->tmpl = new \stdClass();
        $GLOBALS['TSFE']->cObjectDepthCounter = 50;
        $GLOBALS['TSFE']->tmpl->rootLine = $rootLine;
        $GLOBALS['TSFE']->sys_page = $pageSelect;
        $GLOBALS['TSFE']->id = $rootPage['uid'];
        $GLOBALS['TSFE']->page = $rootPage;

        $tmpl->generateConfig();
        $GLOBALS['TSFE']->tmpl->setup = $tmpl->setup;

        $configuration = Util::getSolrConfigurationFromPageId($rootPage['uid'], false, $languageId);

        $solrIsEnabledAndConfigured = $configuration->getEnabled() && $configuration->getSolrHasConnectionConfiguration();
        if (!$solrIsEnabledAndConfigured) {
            return $connection;
        }

        $connection = [
            'connectionKey' => $connectionKey,
            'rootPageTitle' => $rootPage['title'],
            'rootPageUid' => $rootPage['uid'],
            'read' => [
                'scheme' => $configuration->getSolrScheme(),
                'host' => $configuration->getSolrHost(),
                'port' => $configuration->getSolrPort(),
                'path' => $configuration->getSolrPath(),
                'username' => $configuration->getSolrUsername(),
                'password' => $configuration->getSolrPassword(),
                'timeout' => $configuration->getSolrTimeout()
            ],
            'write' => [
                'scheme' => $configuration->getSolrScheme('http', 'write'),
                'host' => $configuration->getSolrHost('localhost', 'write'),
                'port' => $configuration->getSolrPort(8983, 'write'),
                'path' => $configuration->getSolrPath('/solr/core_en/', 'write'),
                'username' => $configuration->getSolrUsername('', 'write'),
                'password' => $configuration->getSolrPassword('', 'write'),
                'timeout' => $configuration->getSolrTimeout(0, 'write')
            ],

            'language' => $languageId
        ];

        $connection['label'] = $this->buildConnectionLabel($connection);
        return $connection;
    }
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;
    }
1105046
public function registerStream($rootDirectory)
    {
        $streamManager = new StreamManager();
        if (is_null($streamManager->getStream('sulu-block-bundle'))) {
            $stream = new Stream('sulu-block-bundle', [
                'blocks' => __DIR__.'/Resources/templates/blocks/',
                'properties' => __DIR__.'/Resources/templates/properties/',
                'app-properties' => $rootDirectory.'/Resources/ConnectHollandSuluBlockBundle/templates/properties/',
                'app-property-params' => $rootDirectory.'/Resources/ConnectHollandSuluBlockBundle/templates/params/',
            ]);

            StreamManager::create()->registerStream($stream);
        }
    }
575908
@Nullable public View findViewById(int id) {
        if (searchView != null) {
            return searchView.findViewById(id);
        } else if (supportView != null) {
            return supportView.findViewById(id);
        }
        throw new IllegalStateException(ERROR_NO_SEARCHVIEW);
    }
48427
public function getByModelRootId($rootId){

        $this->fillScopes();

        if(!isset($this->scopeByModelRootId[$rootId])){
            throw new OutOfBoundsException("No scope with modelRootId '$rootId' found");
        }

        return $this->scopeByModelRootId[$rootId];

    }
123329
function(ownerId, userId, callback) {
      if (!ownerId) return callback(new Error(utils.i18n.blocklist.ownerId));
      if (!userId) return callback(new Error(utils.i18n.blocklist.userId));
      utils.debug('Blocklist block: ' + ownerId + ' userId: ' + userId);

      request.post({
        path: '/users/' + querystring.escape(ownerId) + '/blocks',
        body: {
          user_id: userId
        }
      }, callback || utils.nop);
    }
1298981
public function findAllByRoot( $rootId  = null,
                                   $order   = null,
                                   $limit   = null,
                                   $offset  = null )
    {
        $select = $this->select();

        if ( empty( $rootId ) )
        {
            $where = array(
                new Predicate\IsNull( 'rootParagraphId' )
            );
        }
        else
        {
            $where = array(
                'rootParagraphId' => (int) $rootId,
            );
        }

        $select->where( $where )
               ->order( $order ?: array() )
               ->limit( $limit )
               ->offset( $offset );

        /* @var $result \Zend\Db\Adapter\Driver\ResultInterface */

        $return = array();
        $result = $this->sql()
                       ->prepareStatementForSqlObject( $select )
                       ->execute();

        foreach ( $result as $row )
        {
            $return[] = $this->selected( $row );
        }

        return $return;
    }
998811
protected function injectFormCell(BlockView $view, BlockInterface $block)
    {
        $section = BlockViewUtil::getParent($view, 'panel_section');

        if (null !== $section
                && $section->vars['rendered']
                && $view->vars['rendered']
                && null !== $formPath = $block->getConfig()->getAttribute('form_name')) {
            $parentForm = BlockFormUtil::getParentFormView($view);

            if (null !== $parentForm) {
                $formNames = explode('.', $formPath);
                $formCell = $parentForm;

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

                if (null !== $formCell && $formCell !== $parentForm) {
                    $view->vars['form_cell'] = $formCell;
                }
            }
        }
    }