Showing 1 of 4 files from the diff.

@@ -0,0 +1,83 @@
Loading
1 +
<?php
2 +
3 +
namespace Symbiote\GridFieldExtensions\Extensions;
4 +
5 +
use SilverStripe\Control\Controller;
6 +
use SilverStripe\Core\Convert;
7 +
use SilverStripe\Core\Extension;
8 +
use SilverStripe\Forms\FieldList;
9 +
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest as CoreGridFieldDetailForm_ItemRequest;
10 +
use SilverStripe\Forms\LiteralField;
11 +
use SilverStripe\View\ArrayData;
12 +
use SilverStripe\View\HTML;
13 +
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
14 +
use Symbiote\GridFieldExtensions\GridFieldExtensions;
15 +
16 +
/**
17 +
 * @property CoreGridFieldDetailForm_ItemRequest $owner
18 +
 */
19 +
class GridFieldDetailFormItemRequestExtension extends Extension
20 +
{
21 +
    /**
22 +
     * @param FieldList $actions
23 +
     */
24 +
    public function updateFormActions(FieldList &$actions)
25 +
    {
26 +
        $grid = $this->owner->getGridField();
27 +
        $gridFieldConfig = $grid->getConfig();
28 +
        $addMultiClassComponent = $gridFieldConfig->getComponentByType(GridFieldAddNewMultiClass::class);
29 +
        if ($addMultiClassComponent) {
30 +
            $newRecordField = static::get_new_record_field_from_actions($actions);
31 +
            if ($newRecordField) {
32 +
                $newRecordField->getContainerFieldList()->removeByName('new-record');
33 +
                $newRecordField->getContainerFieldList()->push(
34 +
                    LiteralField::create('new-record', $this->getHTMLFragment($addMultiClassComponent))
35 +
                );
36 +
                GridFieldExtensions::include_requirements();
37 +
            }
38 +
        }
39 +
    }
40 +
41 +
    /**
42 +
     * {@inheritDoc}
43 +
     */
44 +
    private function getHTMLFragment(GridFieldAddNewMultiClass $component)
45 +
    {
46 +
        $grid = $this->owner->getGridField();
47 +
48 +
        $classes = $component->getClasses($grid);
49 +
50 +
        if (!count($classes)) {
51 +
            return false;
52 +
        }
53 +
54 +
        return HTML::createTag('a', [
55 +
            'data-href-template' => Controller::join_links($grid->Link(), 'add-multi-class', '{class}'),
56 +
            'title' => _t(__CLASS__ . '.NEW', 'Add new record'),
57 +
            'aria-label' => _t(__CLASS__ . '.NEW', 'Add new record'),
58 +
            'class' => implode(' ', array(
59 +
                'btn',
60 +
                'btn-primary',
61 +
                'font-icon-plus-thin',
62 +
                'btn--circular',
63 +
                'action--new',
64 +
                'discard-confirmation',
65 +
                'action--new__multi-class',
66 +
            )),
67 +
            'data-classes' => Convert::array2json($classes),
68 +
        ]);
69 +
    }
70 +
71 +
    /**
72 +
     * @param FieldList $actions
73 +
     * @return LiteralField OR NULL
74 +
     */
75 +
    private static function get_new_record_field_from_actions(FieldList &$actions)
76 +
    {
77 +
        $rightGroup = $actions->fieldByName('RightGroup');
78 +
        if (!$rightGroup) {
79 +
            return null;
80 +
        }
81 +
        return $rightGroup->getChildren()->fieldByName('new-record');
82 +
    }
83 +
}
Files Complexity Coverage
src 329 30.80%
Project Totals (13 files) 329 30.80%
640.6
TRAVIS_OS_NAME=linux
7.4=.4
640.5
7.3=.3
TRAVIS_OS_NAME=linux
653.6
TRAVIS_OS_NAME=linux
7.4=.4
653.5
7.3=.3
TRAVIS_OS_NAME=linux
1
comment: false
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading