These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Creates default taxonomy type records if they don't exist already |
||
4 | */ |
||
5 | class DMSTaxonomyTypeExtension extends DataExtension |
||
0 ignored issues
–
show
|
|||
6 | { |
||
7 | /** |
||
8 | * Create default taxonomy type records. Add records via YAML configuration (see taxonomy.yml): |
||
9 | * |
||
10 | * <code> |
||
11 | * DMSTaxonomyTypeExtension: |
||
12 | * default_records: |
||
13 | * - Document |
||
14 | * - PrivateDocument |
||
15 | * </code> |
||
16 | */ |
||
17 | public function requireDefaultRecords() |
||
18 | { |
||
19 | $records = (array) Config::inst()->get(get_class($this), 'default_records'); |
||
20 | foreach ($records as $name) { |
||
21 | $type = TaxonomyType::get()->filter('Name', $name)->first(); |
||
22 | if (!$type) { |
||
23 | $type = TaxonomyType::create(array('Name' => $name)); |
||
24 | $type->write(); |
||
25 | } |
||
26 | } |
||
27 | } |
||
28 | } |
||
29 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.