/** * @return \DotPlant\Monster\models\Layout */ public function getLayout() { return $this->layout_id > 0 ? Layout::findById($this->layout_id) : null; }
protected function applyLayout(&$entity, &$actionData, $dataEntity) { /** @var \yii\base\Model|MonsterEntityTrait $entity */ $layoutId = ArrayHelper::getValue($this->visualBuilderProvided(), 'layout.templateId'); if ($layoutId !== null) { $entity->setLayoutId($layoutId); } // apply layout $layoutId = $entity->getLayoutId(); $layout = $layoutId > 0 ? Layout::findById($layoutId) : null; if ($layout === null) { $layout = Layout::findByKey($this->defaultLayoutKey); } $layoutEditData = []; if ($layout !== null) { if ($this->action() !== self::ACTION_DEFAULT) { $this->providersSupplied($layout, 'layout'); $this->templateRegions($layout, 'layout'); } Yii::$app->params['layoutTemplateRegions'] = $layout->templateRegions; Yii::$app->params['layoutMainEntity'] =& $entity; $packedLayoutProviders = []; $providedLayoutKeys = []; $dataLayout = DataProviderProcessor::process($layout->getEntityDataProviders(), $actionData, $packedLayoutProviders, $providedLayoutKeys); // merged data is needed for rendering the layout $mergedData = ArrayHelper::merge($dataLayout, $dataEntity); Yii::$app->params['layoutDataByTemplateRegion'] = $mergedData; $actionData->controller->layout = '@DotPlant/Monster/views/layout-template.php'; $layoutEditData = ['id' => $layout->id, 'providers' => $packedLayoutProviders, 'key' => $layout->key, 'regions' => ArrayHelper::map($layout->templateRegions, 'id', function (TemplateRegion $item) { return ['id' => $item->id, 'name' => $item->name, 'key' => $item->key, 'entity_dependent' => (bool) $item->entity_dependent]; }), 'providedKeys' => $providedLayoutKeys]; } return $layoutEditData; }