Issues (26)

src/TaxonomyAdmin.php (2 issues)

1
<?php
2
3
namespace SilverStripe\Taxonomy;
4
5
use SilverStripe\Admin\ModelAdmin;
6
use SilverStripe\Forms\GridField\GridField;
7
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
8
use SilverStripe\ORM\SS_List;
9
use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
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
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);
21
22
    private static $menu_title = 'Taxonomies';
0 ignored issues
show
The private property $menu_title is not used, and could be removed.
Loading history...
23
24
    private static $menu_icon_class = 'font-icon-tags';
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