Issues (88)

src/bulkhandler/AddRelatedHandler.php (1 issue)

1
<?php
2
3
namespace SilverCommerce\ContactAdmin\BulkActions;
4
5
use SilverStripe\View\ArrayData;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\Forms\GridField\GridFieldDetailForm;
8
use Colymba\BulkManager\BulkAction\Handler as BulkActionHandler;
9
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
10
11
/**
12
 * Abstract(ish) handler class for bulk assigning actions that pre-loads some
13
 * common functions and properties.
14
 */
15
class AddRelatedHandler extends BulkActionHandler
16
{
17
18
    private static $url_handlers = [
0 ignored issues
show
The private property $url_handlers is not used, and could be removed.
Loading history...
19
        '' => "index",
20
        'Form' => "Form"
21
    ];
22
23
        /**
24
         * Whether this handler should be called via an XHR from the front-end
25
         *
26
         * @var boolean
27
         */
28
    protected $xhr = false;
29
30
    /**
31
     * Set to true is this handler will destroy any data.
32
     * A warning and confirmation will be shown on the front-end.
33
     *
34
     * @var boolean
35
     */
36
    protected $destructive = false;
37
38
    /**
39
     * Return URL to this RequestHandler
40
     *
41
     * @param  string $action Action to append to URL
42
     * @return string URL
43
     */
44
    public function Link($action = null)
45
    {
46
        return Controller::join_links(
47
            parent::Link(),
48
            $this->config()->url_segment,
49
            $action
50
        );
51
    }
52
53
    /**
54
     * Traverse up nested requests until we reach the first that's not a GridFieldDetailForm or GridFieldDetailForm_ItemRequest.
55
     * The opposite of {@link Controller::curr()}, required because
56
     * Controller::$controller_stack is not directly accessible.
57
     *
58
     * @return Controller
59
     */
60
    protected function getToplevelController()
61
    {
62
        $c = Controller::curr();
63
        while ($c && ($c instanceof GridFieldDetailForm_ItemRequest || $c instanceof GridFieldDetailForm)) {
64
            $c = $c->getController();
65
        }
66
67
        return $c;
68
    }
69
70
    /**
71
     * Edited version of the GridFieldEditForm function
72
     * adds the 'Bulk Upload' at the end of the crums.
73
     *
74
     * CMS-specific functionality: Passes through navigation breadcrumbs
75
     * to the template, and includes the currently edited record (if any).
76
     * see {@link LeftAndMain->Breadcrumbs()} for details.
77
     *
78
     * @author SilverStripe original Breadcrumbs() method
79
     *
80
     * @see GridFieldDetailForm_ItemRequest
81
     *
82
     * @param bool $unlinked
83
     *
84
     * @return ArrayData
85
     */
86
    public function Breadcrumbs($unlinked = false)
87
    {
88
        if (!Controller::curr()->hasMethod('Breadcrumbs')) {
89
            return;
90
        }
91
92
        $items = Controller::curr()->Breadcrumbs($unlinked);
93
        $items->push(
94
            ArrayData::create(
95
                [
96
                'Title' => $this->getI18nLabel(),
97
                'Link' => false,
98
                ]
99
            )
100
        );
101
102
        return $items;
103
    }
104
}
105