-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContentModelMetadataGenerator.php
75 lines (63 loc) · 1.49 KB
/
ContentModelMetadataGenerator.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/**
* @link http://neamlabs.com/
* @copyright Copyright (c) 2015 Neam AB
*/
namespace neam\gii2_content_model_metadata_generators;
use yii\base\ErrorException;
use yii\helpers\Json;
use Yii;
abstract class ContentModelMetadataGenerator extends \yii\gii\Generator
{
public $ns;
/**
* @var null string
*/
public $jsonPathAlias = null;
/**
* @inheritdoc
*/
public function rules()
{
return array_merge(
parent::rules(),
[
[['jsonPathAlias'], 'required'],
]
);
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return array_merge(
parent::attributeLabels(),
[
'jsonPathAlias' => 'Path alias to content-model-metadata.json',
]
);
}
/**
* @inheritdoc
*/
public function hints()
{
return array_merge(
parent::hints(),
[
'jsonPathAlias' => 'This json file should contain metadata about the item types and attributes for the current content model',
]
);
}
public function getContentModelMetadata()
{
$path = Yii::getAlias($this->jsonPathAlias);
$json = file_get_contents($path);
$cmm = Json::decode($json, false);
if (empty($cmm)) {
throw new ErrorException("Content model metadata json was found empty");
}
return $cmm;
}
}