DMSGridFieldDetailForm_ItemRequest::ItemEditForm()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * Custom ItemRequest class the provides custom delete behaviour for the CMSFields of DMSDocument
5
 */
6
class DMSGridFieldDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
7
{
8
    private static $allowed_actions = array('ItemEditForm');
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...
9
10
    public function ItemEditForm()
11
    {
12
        $form = parent::ItemEditForm();
13
14
        //add a data attribute specifying how many pages this document is referenced on
15
        if ($record = $this->record) {
16
            $numberOfPageRelations = $record->getRelatedPages()->count();
17
            $relations = new ShortCodeRelationFinder();
18
            $numberOfInlineRelations = $relations->findPageCount($record->ID);
19
20
            //add the number of pages attached to this field as a data-attribute
21
            $form->setAttribute('data-pages-count', $numberOfPageRelations);
22
            $form->setAttribute('data-relation-count', $numberOfInlineRelations);
23
        }
24
        return $form;
25
    }
26
}
27