/** * Handle decoration * @param \yii\base\Controller $controller * @param string $viewFile * @param array $params * @return void */ public function decorate($controller, $viewFile, $params) { if (isset($controller->view->blocks['content'])) { $dependency = new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(app\modules\core\models\ContentBlock::className()), ActiveRecordHelper::getCommonTag(get_class($params['model']))]]); $controller->view->blocks['content'] = ContentBlockHelper::compileContentString($controller->view->blocks['content'], get_class($params['model']) . ':' . $params['model']->id, $dependency); } }
/** * Actual run function for all widget classes extending BaseWidget * * @return mixed */ public function widgetRun() { $contentBlock = ContentBlockHelper::fetchChunkByKey($this->key); if ($contentBlock === null) { return ''; } return $this->render('content-block', ['content' => $contentBlock]); }
/** * Product page view * * @param null $model_id * @return string * @throws NotFoundHttpException * @throws ServerErrorHttpException */ public function actionShow($model_id = null) { if (null === ($object = Object::getForClass(Product::className()))) { throw new ServerErrorHttpException('Object not found.'); } $cacheKey = 'Product:' . $model_id; if (false === ($product = Yii::$app->cache->get($cacheKey))) { if (null === ($product = Product::findById($model_id))) { throw new NotFoundHttpException(); } Yii::$app->cache->set($cacheKey, $product, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Product::className(), $model_id)]])); } $request = Yii::$app->request; $values_by_property_id = $request->get('properties', []); if (!is_array($values_by_property_id)) { $values_by_property_id = [$values_by_property_id]; } $selected_category_id = $request->get('last_category_id'); $selected_category_ids = $request->get('categories', []); if (!is_array($selected_category_ids)) { $selected_category_ids = [$selected_category_ids]; } $category_group_id = intval($request->get('category_group_id', 0)); // trigger that we are to show product to user! // wow! such product! very events! $specialEvent = new ProductPageShowed(['product_id' => $product->id]); EventTriggeringHelper::triggerSpecialEvent($specialEvent); if (!empty($product->meta_description)) { $this->view->registerMetaTag(['name' => 'description', 'content' => ContentBlockHelper::compileContentString($product->meta_description, Product::className() . ":{$product->id}:meta_description", new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ContentBlock::className()), ActiveRecordHelper::getCommonTag(Product::className())]]))], 'meta_description'); } $selected_category = $selected_category_id > 0 ? Category::findById($selected_category_id) : null; $this->view->title = $product->title; $this->view->blocks['h1'] = $product->h1; $this->view->blocks['announce'] = $product->announce; $this->view->blocks['content'] = $product->content; $this->view->blocks['title'] = $product->title; return $this->render($this->computeViewFile($product, 'show'), ['model' => $product, 'category_group_id' => $category_group_id, 'values_by_property_id' => $values_by_property_id, 'selected_category_id' => $selected_category_id, 'selected_category' => $selected_category, 'selected_category_ids' => $selected_category_ids, 'object' => $object, 'breadcrumbs' => $this->buildBreadcrumbsArray($selected_category, $product)]); }
/** * Get property values by key. * @param $key * @param bool $asString * @param string $delimiter * @return array|string */ public function property($key, $asString = true, $delimiter = ', ') { $values = []; $propertyValue = $this->getPropertyValuesByKey($key); if (is_null($propertyValue)) { return $asString ? '' : []; } foreach ($propertyValue->values as $value) { $values[] = $value['value']; } if ($asString) { return ContentBlockHelper::compileContentString(implode($delimiter, $values), "{$this->owner->className()}:{$this->owner->id}:property={$key}", new TagDependency(['tags' => [$this->owner->objectTag(), ActiveRecordHelper::getCommonTag(ContentBlock::className())]])); } else { return $values; } }
/** * @param Page $model */ private function registerMetaDescription($model) { if (!empty($model->meta_description)) { $this->view->registerMetaTag(['name' => 'description', 'content' => ContentBlockHelper::compileContentString($model->meta_description, Page::className() . ":{$model->id}:meta_description", new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ContentBlock::className()), ActiveRecordHelper::getCommonTag(Page::className())]]))], 'meta_description'); } }
/** * @deprecated use ContentBlockHelper::getChunk($key, $params, $model) instead * Get chunk model or value * @param string $key * @param bool $valueOnly * @param mixed $defaultValue * @return ContentBlock|string */ public static function getChunk($key, $valueOnly = true, $defaultValue = null) { return ContentBlockHelper::getChunk($key); }
/** * @param $content * @param $contentKey * @param $dependency * @return string */ private function processChunks($content, $contentKey, $dependency) { return ContentBlockHelper::compileContentString($content, $contentKey, $dependency); }