Completed
Pull Request — master (#168)
by Franco
02:41
created

code/extensions/DMSTaxonomyTypeExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

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
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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