Completed
Push — master ( 31b3ff...06692e )
by Robbie
01:52
created

code/cms/DMSGridFieldDetailForm.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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...
The property $allowed_actions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

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