GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AdvancedWorkflowAdmin   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 342
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 20

Importance

Changes 0
Metric Value
wmc 35
lcom 1
cbo 20
dl 0
loc 342
rs 9.6
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 1
C getEditForm() 0 101 8
A isAdminUser() 0 7 2
A columns() 0 17 1
A setFieldFormatting() 0 14 6
B userObjects() 0 29 7
A getFieldDependentData() 0 9 3
A export() 0 18 3
A ImportForm() 0 17 2
A setWorkflowService() 0 5 1
A getWorkflowService() 0 4 1
1
<?php
2
3
namespace Symbiote\AdvancedWorkflow\Admin;
4
5
use SilverStripe\Admin\ModelAdmin;
6
use SilverStripe\CMS\Controllers\CMSPageEditController;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Control\HTTPResponse;
9
use SilverStripe\Forms\FieldList;
10
use SilverStripe\Forms\FormAction;
11
use SilverStripe\Forms\GridField\GridField;
12
use SilverStripe\Forms\GridField\GridFieldConfig_Base;
13
use SilverStripe\Forms\GridField\GridFieldDataColumns;
14
use SilverStripe\Forms\GridField\GridFieldDetailForm;
15
use SilverStripe\Forms\GridField\GridFieldEditButton;
16
use SilverStripe\Forms\GridField\GridFieldExportButton;
17
use SilverStripe\Forms\GridField\GridFieldImportButton;
18
use SilverStripe\Forms\GridField\GridFieldPaginator;
19
use SilverStripe\ORM\ArrayList;
20
use SilverStripe\ORM\DataObject;
21
use SilverStripe\Security\Member;
22
use SilverStripe\Security\Permission;
23
use SilverStripe\Security\Security;
24
use SilverStripe\View\Requirements;
25
use Symbiote\AdvancedWorkflow\DataObjects\WorkflowDefinition;
26
use Symbiote\AdvancedWorkflow\Dev\WorkflowBulkLoader;
27
use Symbiote\AdvancedWorkflow\Forms\GridField\GridFieldExportAction;
28
use Symbiote\AdvancedWorkflow\Forms\GridField\GridFieldWorkflowRestrictedEditButton;
29
use Symbiote\AdvancedWorkflow\Services\WorkflowService;
30
31
/**
32
 * @package advancedworkflow
33
 * @todo UI/UX needs looking at for when current user has no pending and/or submitted items, (Current
34
 * implementation is bog-standard <p> text)
35
 */
36
class AdvancedWorkflowAdmin extends ModelAdmin
37
{
38
    private static $menu_title    = 'Workflows';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
39
    private static $menu_priority = -1;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
40
    private static $url_segment   = 'workflows';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
41
    private static $menu_icon_class = 'font-icon-flow-tree';
42
43
    /**
44
     *
45
     * @var array Allowable actions on this controller.
46
     */
47
    private static $allowed_actions = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
48
        'export',
49
        'ImportForm'
50
    );
51
52
    private static $url_handlers = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
53
        '$ModelClass/export/$ID!' => 'export',
54
        '$ModelClass/$Action' => 'handleAction',
55
        '' => 'index'
56
    );
57
58
    private static $managed_models = WorkflowDefinition::class;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
59
60
    private static $model_importers = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
61
        'WorkflowDefinition' => WorkflowBulkLoader::class
62
    );
63
64
    private static $dependencies = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
65
        'workflowService' => '%$' . WorkflowService::class,
66
    );
67
68
    private static $fileEditActions = 'getCMSActions';
69
70
    /**
71
     * Defaults are set in {@link getEditForm()}.
72
     *
73
     * @var array
74
     */
75
    private static $fieldOverrides = array();
76
77
    /**
78
     * @var WorkflowService
79
     */
80
    public $workflowService;
81
82
    /**
83
     * Initialise javascript translation files
84
     *
85
     * @return void
86
     */
87
    protected function init()
88
    {
89
        parent::init();
90
91
        Requirements::add_i18n_javascript('symbiote/silverstripe-advancedworkflow:client/lang');
92
        Requirements::javascript('symbiote/silverstripe-advancedworkflow:client/dist/js/advancedworkflow.js');
93
        Requirements::css('symbiote/silverstripe-advancedworkflow:client/dist/styles/advancedworkflow.css');
94
    }
95
96
    /*
97
     * Shows up to x2 GridFields for Pending and Submitted items, dependent upon the current CMS user and
98
     * that user's permissions on the objects showing in each field.
99
     */
100
    public function getEditForm($id = null, $fields = null)
101
    {
102
        $form = parent::getEditForm($id, $fields);
103
104
        $definitionGridFieldName = $this->sanitiseClassName(WorkflowDefinition::class);
105
106
        // Show items submitted into a workflow for current user to action
107
        $fieldName = 'PendingObjects';
108
        $pending = $this->userObjects(Security::getCurrentUser(), $fieldName);
0 ignored issues
show
Bug introduced by
It seems like \SilverStripe\Security\Security::getCurrentUser() can be null; however, userObjects() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
109
110
        if ($this->config()->fieldOverrides) {
111
            $displayFields = $this->config()->fieldOverrides;
112
        } else {
113
            $displayFields = array(
114
                'Title'          => _t('AdvancedWorkflowAdmin.Title', 'Title'),
115
                'LastEdited'     => _t('AdvancedWorkflowAdmin.LastEdited', 'Changed'),
116
                'WorkflowTitle'  => _t('AdvancedWorkflowAdmin.WorkflowTitle', 'Effective workflow'),
117
                'WorkflowStatus' => _t('AdvancedWorkflowAdmin.WorkflowStatus', 'Current action'),
118
            );
119
        }
120
121
        // Pending/Submitted items GridField Config
122
        $config = new GridFieldConfig_Base();
123
        $config->addComponent(new GridFieldEditButton());
124
        $config->addComponent(new GridFieldDetailForm());
125
        $config->getComponentByType(GridFieldPaginator::class)->setItemsPerPage(5);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface SilverStripe\Forms\GridField\GridFieldComponent as the method setItemsPerPage() does only exist in the following implementations of said interface: SilverStripe\Forms\GridField\GridFieldPaginator.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
126
        $columns = $config->getComponentByType(GridFieldDataColumns::class);
127
        $columns->setFieldFormatting($this->setFieldFormatting($config));
0 ignored issues
show
Documentation introduced by
$config is of type object<SilverStripe\Form...d\GridFieldConfig_Base>, but the function expects a object<Symbiote\Advanced...\Admin\GridFieldConfig>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
128
129
        if ($pending->count()) {
130
            $formFieldTop = GridField::create(
131
                $fieldName,
132
                $this->isAdminUser(Security::getCurrentUser()) ?
0 ignored issues
show
Bug introduced by
It seems like \SilverStripe\Security\Security::getCurrentUser() can be null; however, isAdminUser() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
133
                    _t(
134
                        'AdvancedWorkflowAdmin.GridFieldTitleAssignedAll',
135
                        'All pending items'
136
                    ):
137
                    _t(
138
                        'AdvancedWorkflowAdmin.GridFieldTitleAssignedYour',
139
                        'Your pending items'
140
                    ),
141
                $pending,
142
                $config
143
            );
144
145
            $dataColumns = $formFieldTop->getConfig()->getComponentByType(GridFieldDataColumns::class);
146
            $dataColumns->setDisplayFields($displayFields);
147
148
            $formFieldTop->setForm($form);
149
            $form->Fields()->insertBefore($definitionGridFieldName, $formFieldTop);
150
        }
151
152
        // Show items submitted into a workflow by current user
153
        $fieldName = 'SubmittedObjects';
154
        $submitted = $this->userObjects(Security::getCurrentUser(), $fieldName);
0 ignored issues
show
Bug introduced by
It seems like \SilverStripe\Security\Security::getCurrentUser() can be null; however, userObjects() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
155
        if ($submitted->count()) {
156
            $formFieldBottom = GridField::create(
157
                $fieldName,
158
                $this->isAdminUser(Security::getCurrentUser()) ?
0 ignored issues
show
Bug introduced by
It seems like \SilverStripe\Security\Security::getCurrentUser() can be null; however, isAdminUser() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
159
                    _t(
160
                        'AdvancedWorkflowAdmin.GridFieldTitleSubmittedAll',
161
                        'All submitted items'
162
                    ):
163
                    _t(
164
                        'AdvancedWorkflowAdmin.GridFieldTitleSubmittedYour',
165
                        'Your submitted items'
166
                    ),
167
                $submitted,
168
                $config
169
            );
170
171
            $dataColumns = $formFieldBottom->getConfig()->getComponentByType(GridFieldDataColumns::class);
172
            $dataColumns->setDisplayFields($displayFields);
173
174
            $formFieldBottom->setForm($form);
175
            $formFieldBottom->getConfig()->removeComponentsByType(GridFieldEditButton::class);
176
            $formFieldBottom->getConfig()->addComponent(new GridFieldWorkflowRestrictedEditButton());
177
            $form->Fields()->insertBefore($definitionGridFieldName, $formFieldBottom);
178
        }
179
180
        $grid = $form->Fields()->fieldByName($definitionGridFieldName);
181
        if ($grid) {
182
            $grid->getConfig()->getComponentByType(GridFieldDetailForm::class)
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on SilverStripe\Forms\FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
183
                ->setItemEditFormCallback(function ($form) {
184
                    $record = $form->getRecord();
185
                    if ($record) {
186
                        $record->updateAdminActions($form->Actions());
187
                    }
188
                });
189
190
            $grid->getConfig()->getComponentByType(GridFieldDetailForm::class)
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on SilverStripe\Forms\FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
191
                ->setItemRequestClass(WorkflowDefinitionItemRequestClass::class);
192
            $grid->getConfig()->addComponent(new GridFieldExportAction());
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on SilverStripe\Forms\FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
193
            $grid->getConfig()->removeComponentsByType(GridFieldExportButton::class);
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on SilverStripe\Forms\FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
194
            $grid->getConfig()->removeComponentsByType(GridFieldImportButton::class);
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on SilverStripe\Forms\FormField. Did you maybe mean config()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
195
        }
196
197
        $this->extend('updateEditFormAfter', $form);
198
        
199
        return $form;
200
    }
201
202
    /*
203
     * @param Member $user
204
     * @return boolean
205
     */
206
    public function isAdminUser(Member $user)
207
    {
208
        if (Permission::checkMember($user, 'ADMIN')) {
209
            return true;
210
        }
211
        return false;
212
    }
213
214
    /*
215
     * By default, we implement GridField_ColumnProvider to allow users to click through to the PagesAdmin.
216
     * We would also like a "Quick View", that allows users to quickly make a decision on a given workflow-bound
217
     * content-object
218
     */
219
    public function columns()
220
    {
221
        $fields = array(
222
            'Title' => array(
223
                'link' => function ($value, $item) {
224
                    $pageAdminLink = singleton(CMSPageEditController::class)->Link('show');
225
                    return sprintf('<a href="%s/%s">%s</a>', $pageAdminLink, $item->Link, $value);
226
                }
227
            ),
228
            'WorkflowStatus' => array(
229
                'text' => function ($value, $item) {
230
                    return $item->WorkflowCurrentAction;
231
                }
232
            )
233
        );
234
        return $fields;
235
    }
236
237
    /*
238
     * Discreet method used by both intro gridfields to format the target object's links and clickable text
239
     *
240
     * @param GridFieldConfig $config
241
     * @return array $fieldFormatting
242
     */
243
    public function setFieldFormatting(&$config)
0 ignored issues
show
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
244
    {
245
        $fieldFormatting = array();
246
        // Parse the column information
247
        foreach ($this->columns() as $source => $info) {
248
            if (isset($info['link']) && $info['link']) {
249
                $fieldFormatting[$source] = '<a href=\"$ObjectRecordLink\">$value</a>';
250
            }
251
            if (isset($info['text']) && $info['text']) {
252
                $fieldFormatting[$source] = $info['text'];
253
            }
254
        }
255
        return $fieldFormatting;
256
    }
257
258
    /**
259
     * Get WorkflowInstance Target objects to show for users in initial gridfield(s)
260
     *
261
     * @param Member $member
0 ignored issues
show
Bug introduced by
There is no parameter named $member. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
262
     * @param string $fieldName The name of the gridfield that determines which dataset to return
263
     * @return DataList
264
     * @todo Add the ability to see embargo/expiry dates in report-gridfields at-a-glance if QueuedJobs module installed
265
     */
266
    public function userObjects(Member $user, $fieldName)
267
    {
268
        $list = new ArrayList();
269
        $userWorkflowInstances = $this->getFieldDependentData($user, $fieldName);
270
        foreach ($userWorkflowInstances as $instance) {
0 ignored issues
show
Bug introduced by
The expression $userWorkflowInstances of type object<SilverStripe\ORM\DataList>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
271
            if (!$instance->TargetID || !$instance->DefinitionID) {
272
                continue;
273
            }
274
            // @todo can we use $this->getDefinitionFor() to fetch the "Parent" definition of $instance? Maybe
275
            // define $this->workflowParent()
276
            $effectiveWorkflow = DataObject::get_by_id(WorkflowDefinition::class, $instance->DefinitionID);
277
            $target = $instance->getTarget();
278
            if (!is_object($effectiveWorkflow) || !$target) {
279
                continue;
280
            }
281
            $instance->setField('WorkflowTitle', $effectiveWorkflow->getField('Title'));
282
            $instance->setField('WorkflowCurrentAction', $instance->getCurrentAction());
283
            // Note the order of property-setting here, somehow $instance->Title is overwritten by the Target
284
            // Title property..
285
            $instance->setField('Title', $target->getField('Title'));
286
            $instance->setField('LastEdited', $target->getField('LastEdited'));
287
            if (method_exists($target, 'CMSEditLink')) {
288
                $instance->setField('ObjectRecordLink', $target->CMSEditLink());
289
            }
290
291
            $list->push($instance);
292
        }
293
        return $list;
294
    }
295
296
    /*
297
     * Return content-object data depending on which gridfeld is calling for it
298
     *
299
     * @param Member $user
300
     * @param string $fieldName
301
     */
302
    public function getFieldDependentData(Member $user, $fieldName)
303
    {
304
        if ($fieldName == 'PendingObjects') {
305
            return $this->getWorkflowService()->userPendingItems($user);
306
        }
307
        if ($fieldName == 'SubmittedObjects') {
308
            return $this->getWorkflowService()->userSubmittedItems($user);
309
        }
310
    }
311
312
    /**
313
     * Spits out an exported version of the selected WorkflowDefinition for download.
314
     *
315
     * @param HTTPRequest $request
316
     * @return HTTPResponse
317
     */
318
    public function export(HTTPRequest $request)
319
    {
320
        $url = explode('/', $request->getURL());
321
        $definitionID = end($url);
322
        if ($definitionID && is_numeric($definitionID)) {
323
            $exporter = new WorkflowDefinitionExporter($definitionID);
324
            $exportFilename = WorkflowDefinitionExporter::config()
325
                ->get('export_filename_prefix') . '-' . $definitionID . '.yml';
326
            $exportBody = $exporter->export();
327
            $fileData = array(
328
                'name' => $exportFilename,
329
                'mime' => 'text/x-yaml',
330
                'body' => $exportBody,
331
                'size' => $exporter->getExportSize($exportBody)
0 ignored issues
show
Bug introduced by
It seems like $exportBody defined by $exporter->export() on line 326 can also be of type array<integer,string>; however, Symbiote\AdvancedWorkflo...porter::getExportSize() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
332
            );
333
            return $exporter->sendFile($fileData);
334
        }
335
    }
336
337
    /**
338
     * Required so we can simply change the visible label of the "Import" button and lose some redundant form-fields.
339
     *
340
     * @return Form
341
     */
342
    public function ImportForm()
343
    {
344
        $form = parent::ImportForm();
345
        if (!$form) {
346
            return;
347
        }
348
349
        $form->unsetAllActions();
350
        $newActionList = new FieldList(array(
351
            new FormAction('import', _t('AdvancedWorkflowAdmin.IMPORT', 'Import workflow'))
352
        ));
353
        $form->Fields()->fieldByName('_CsvFile')->getValidator()->setAllowedExtensions(array('yml', 'yaml'));
354
        $form->Fields()->removeByName('EmptyBeforeImport');
355
        $form->setActions($newActionList);
356
357
        return $form;
358
    }
359
360
    /**
361
     * @param WorkflowService $workflowService
362
     * @return $this
363
     */
364
    public function setWorkflowService(WorkflowService $workflowService)
365
    {
366
        $this->workflowService = $workflowService;
367
        return $this;
368
    }
369
370
    /**
371
     * @return WorkflowService
372
     */
373
    public function getWorkflowService()
374
    {
375
        return $this->workflowService;
376
    }
377
}
378