TaxonomyAdmin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 1
b 0
f 0
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEditForm() 0 19 4
A getList() 0 7 2
1
<?php
2
3
namespace SilverStripe\Taxonomy;
4
5
use SilverStripe\Admin\ModelAdmin;
6
use SilverStripe\Forms\GridField\GridField;
7
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
0 ignored issues
show
Bug introduced by
The type Symbiote\GridFieldExtens...\GridFieldOrderableRows was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SilverStripe\ORM\SS_List;
9
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
0 ignored issues
show
Bug introduced by
The type UndefinedOffset\Sortable...s\GridFieldSortableRows was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
/**
12
* Management interface for Taxonomies, TaxonomyTerms and TaxonomyTypes
13
*
14
* @package taxonomy
15
*/
16
class TaxonomyAdmin extends ModelAdmin
17
{
18
    private static $url_segment = 'taxonomy';
0 ignored issues
show
introduced by
The private property $url_segment is not used, and could be removed.
Loading history...
19
20
    private static $managed_models = array(TaxonomyTerm::class, TaxonomyType::class);
0 ignored issues
show
introduced by
The private property $managed_models is not used, and could be removed.
Loading history...
21
22
    private static $menu_title = 'Taxonomies';
0 ignored issues
show
introduced by
The private property $menu_title is not used, and could be removed.
Loading history...
23
24
    private static $menu_icon_class = 'font-icon-tags';
0 ignored issues
show
introduced by
The private property $menu_icon_class is not used, and could be removed.
Loading history...
25
    /**
26
     * If terms are the models being managed, filter for only top-level terms - no children
27
     *
28
     * @return SS_List
29
     */
30
    public function getList()
31
    {
32
        if ($this->modelClass === TaxonomyTerm::class) {
33
            $list = parent::getList();
34
            return $list->filter('ParentID', '0');
35
        }
36
        return parent::getList();
37
    }
38
39
    public function getEditForm($id = null, $fields = null)
40
    {
41
        if ($this->modelClass !== TaxonomyTerm::class) {
42
            return parent::getEditForm($id, $fields);
43
        }
44
45
        $form = parent::getEditForm($id, $fields);
46
47
        /** @var GridField $gf */
48
        $gf = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
49
50
        // Setup sorting of TaxonomyTerm siblings, if a suitable module is included
51
        if (class_exists(GridFieldOrderableRows::class)) {
52
            $gf->getConfig()->addComponent(GridFieldOrderableRows::create('Sort'));
53
        } elseif (class_exists(GridFieldSortableRows::class)) {
54
            $gf->getConfig()->addComponent(new GridFieldSortableRows('Sort'));
55
        }
56
57
        return $form;
58
    }
59
}
60