Test Setup Failed
Pull Request — master (#197)
by Gorrie
01:07
created

GridFieldDetailFormItemRequestExtension.php (2 issues)

1
<?php
2
3
namespace DNADesign\Elemental\Extensions;
4
5
use SilverStripe\ORM\FieldType\DBField;
6
use SilverStripe\Core\Extension;
7
use SilverStripe\Control\Controller;
8
use SilverStripe\ORM\CMSPreviewable;
9
use SilverStripe\CMS\Controllers\SilverStripeNavigator;
10
use SilverStripe\Forms\LiteralField;
11
use DNADesign\Elemental\Models\BaseElement;
12
use SilverStripe\Forms\FieldList;
13
use SilverStripe\Forms\FormAction;
14
15
class GridFieldDetailFormItemRequestExtension extends Extension
16
{
17
    public function updateBreadcrumbs($crumbs)
18
    {
19
        $record = $this->owner->getRecord();
20
21
        if ($record instanceof BaseElement) {
22
            $last = $crumbs->Last();
23
24
            $last->Title = DBField::create_field('HTMLVarchar', sprintf(
25
                "%s <small>(%s)</small>",
26
                DBField::create_field('Varchar', $last->Title)->XML(),
27
                $record->getType()
28
            ));
29
        }
30
    }
31
32
    /**
33
     * Updates the edit form to inject the preview panel controls if needed
34
     * i.e. if the class being edited implements CMSPreviewable
35
     *
36
     * @param SilverStripe\Forms\Form $form to be modified by reference
0 ignored issues
show
The type DNADesign\Elemental\Exte...SilverStripe\Forms\Form was not found. Did you mean SilverStripe\Forms\Form? If so, make sure to prefix the type with \.
Loading history...
37
     */
38
    public function updateItemEditForm(&$form)
39
    {
40
        $fields = $form->Fields();
41
        if ($this->owner->getRecord() instanceof CMSPreviewable &&
42
            !$fields->fieldByName('SilverStripeNavigator')
43
        ) {
44
            $template = Controller::curr()
45
                ->getTemplatesWithSuffix('_SilverStripeNavigator');
46
            $navigator = SilverStripeNavigator::create($this->owner->record);
47
            $field = LiteralField::create(
48
                'SilverStripeNavigator',
0 ignored issues
show
'SilverStripeNavigator' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
                /** @scrutinizer ignore-type */ 'SilverStripeNavigator',
Loading history...
49
                $navigator->renderWith($template)
50
            )->setAllowHTML(true);
51
            $fields->push($field);
52
            $form->addExtraClass('cms-previewable')
53
                ->removeExtraClass('cms-panel-padded center');
54
        }
55
    }
56
}
57