/** * @param string|BlockTypeInterface $blockType The block type name or instance of BlockTypeInterface * * @return string The name of the given block type */ protected function ensureInitialized($blockType) { if ($blockType instanceof BlockTypeInterface) { $name = $blockType->getName(); $type = $blockType; } else { $name = $blockType; $type = null; } if (!isset($this->types[$name])) { if (!$type) { $type = $this->registry->getType($name); } $types = [$type]; $typeName = $type->getName(); $names = [$typeName]; $nameMap = [$typeName => true]; $parentName = $type->getParent(); while ($parentName) { if (isset($this->types[$parentName])) { // use data from already loaded parent type $types = array_merge($this->types[$parentName], array_reverse($types)); $names = array_merge($this->names[$parentName], array_reverse($names)); $nameMap = array_merge($nameMap, $this->nameMap[$parentName]); break; } else { $type = $this->registry->getType($parentName); $typeName = $type->getName(); $types[] = $type; $names[] = $typeName; $nameMap[$typeName] = true; $parentName = $type->getParent(); } } if (null === $parentName) { $types = array_reverse($types); $names = array_reverse($names); } $this->types[$name] = $types; $this->names[$name] = $names; $this->nameMap[$name] = $nameMap; // initialise all parent types if them are not initialized yet $typeNames = array_keys($nameMap); $offset = 0; while (false !== ($typeName = next($typeNames))) { if (isset($this->nameMap[$typeName])) { break; } $offset++; $this->types[$typeName] = array_slice($types, 0, -$offset); $this->names[$typeName] = array_slice($names, 0, -$offset); $this->nameMap[$typeName] = array_slice($nameMap, $offset); } } return $name; }
/** * @param string $name The name of the data provider * * @return mixed The returned values: * DataProviderInterface if the data provider is loaded * mixed if data should be loaded from the layout context * false if the requested data cannot be loaded */ protected function getDataProvider($name) { if (isset($this->dataProviders[$name])) { return $this->dataProviders[$name]; } $dataProvider = $this->registry->findDataProvider($name); if ($dataProvider === null) { $dataProvider = $this->context->data()->has($name) ? $this->context->data()->getIdentifier($name) : false; } $this->dataProviders[$name] = $dataProvider; return $dataProvider; }
/** * {@inheritdoc} */ public function getLayout(ContextInterface $context, $rootId = null) { if (!$context->isResolved()) { $this->registry->configureContext($context); $context->resolve(); } $this->layoutManipulator->applyChanges($context); $rawLayout = $this->rawLayoutBuilder->getRawLayout(); $rootView = $this->blockFactory->createBlockView($rawLayout, $context, $rootId); $layout = $this->createLayout($rootView); $rootBlockId = $rawLayout->getRootId(); $blockThemes = $rawLayout->getBlockThemes(); foreach ($blockThemes as $blockId => $themes) { $layout->setBlockTheme($themes, $blockId !== $rootBlockId ? $blockId : null); } return $layout; }
/** * @param int $key The action key * @param int $index The action index * @param array $args The action arguments * * @return int The number of executed actions */ protected function postExecuteAction($key, $index, $args) { switch ($key) { case self::ADD: $this->addCounter++; $this->item->initialize($args[0]); $this->registry->updateLayout($args[0], $this, $this->item); break; case self::ADD_ALIAS: $this->item->initialize($this->rawLayoutBuilder->resolveId($args[1]), $args[0]); $this->registry->updateLayout($args[0], $this, $this->item); break; case self::MOVE: $this->addCounter++; break; case self::REMOVE: $this->removeLink($key, $index, $args[0]); break; } return 0; }
/** * {@inheritdoc} */ public function getType($name) { return $this->registry->getType($name); }