/** * Deletes a block. * * @return int $id an id of a block to delete. * @throws InvalidCallException if id in $_POST does not match the provided id. */ public function actionDelete($id) { $templateId = $_POST['id']; if ($templateId != $id) { throw new InvalidCallException("Invalid form submitted. Template with id: '{$id}' not deleted."); } $model = TemplateEditor::getModel($id); if ($model->is_default) { Yii::$app->getSession()->setFlash('info', Yii::t('cms', 'Cannot delete the default template.')); } elseif ($model->delete()) { Yii::$app->getSession()->setFlash('success', Yii::t('cms', 'Template deleted.')); } else { Yii::$app->getSession()->setFlash('error', Yii::t('cms', 'Template "{title}" could not be deleted.', ['title' => $model->title])); } return $this->redirect(['index']); }
<div class="row"> <div class="col-md-6"> <?php echo $form->field($model, 'title', ['inputOptions' => ['class' => 'form-control input-lg']]); ?> </div> <div class="col-md-3"> <?php echo $form->field($model, 'layout')->dropDownList($layouts); ?> </div> <div class="col-md-3"> <?php /** * The default template can not be changed. */ if ($model->is_default) { echo $form->field($model, 'is_default', ['inputOptions' => ['disabled' => 'disabled']])->dropDownList(['No', 'Yes']); } else { echo $form->field($model, 'is_default')->dropDownList(['No', 'Yes']); } ?> </div> </div> <?php echo TemplateEditor::widget(['model' => $model]); ?> <?php ActiveForm::end();