-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlugGeneratorWidget.php
38 lines (30 loc) · 993 Bytes
/
SlugGeneratorWidget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace oxycoach\slugwidget;
use Codeception\Exception\ConfigurationException;
use yii\base\Widget;
use yii\helpers\Url;
class SlugGeneratorWidget extends Widget
{
public $form;
public $model;
public $slugGenerationAction = ['generate-slug'];
private $_assetBundle;
public function init()
{
parent::init();
$this->_assetBundle = SlugGeneratorAsset::register($this->getView());
if (!$this->model->hasProperty('nameAttribute')) {
throw new ConfigurationException("SeoBehavior is not attached to model {$this->model::className()}");
}
$this->slugGenerationAction = Url::to($this->slugGenerationAction);
}
public function run()
{
$view = $this->getView();
$view->registerJs("jQuery('body').ChangeNameHandler('{$this->slugGenerationAction}');");
return $this->render('index', [
'form' => $this->form,
'model' => $this->model,
]);
}
}