Showing 1 of 1 files from the diff.

@@ -3,10 +3,13 @@
Loading
3 3
namespace DNADesign\Elemental\Extensions;
4 4
5 5
use SilverStripe\Admin\Forms\UsedOnTable;
6 +
use SilverStripe\CMS\Model\SiteTree;
6 7
use SilverStripe\ORM\DataExtension;
7 8
use SilverStripe\ORM\ArrayList;
8 9
use SilverStripe\ORM\DataObject;
10 +
use SilverStripe\ORM\ValidationException;
9 11
use DNADesign\Elemental\Models\ElementalArea;
12 +
use DNADesign\Elemental\Models\BaseElement;
10 13
11 14
class ElementalAreaUsedOnTableExtension extends DataExtension
12 15
{
@@ -14,13 +17,65 @@
Loading
14 17
    /**
15 18
     * Hides ElementalArea's from the "Used On" tab when viewing files
16 19
     *
20 +
     * @var array $excludedClasses
21 +
     */
22 +
    public function updateUsageExcludedClasses(array &$excludedClasses)
23 +
    {
24 +
        $excludedClasses[] = ElementalArea::class;
25 +
    }
26 +
27 +
    /**
28 +
     * Legacy function kept for semver, replaced with updateUsageExcludedClasses above
29 +
     *
17 30
     * @return void
18 -
     * @var ArrayList $dataObjects
31 +
     * @var ArrayList $usage
19 32
     * @var DataObject $record
20 33
     * @see UsedOnTable::updateUsage
34 +
     * @deprecated 4.5.0 Use self::updateUsageExcludedClasses instead
35 +
     */
36 +
    public function updateUsage(ArrayList &$usage, DataObject &$record)
37 +
    {
38 +
        // noop
39 +
    }
40 +
41 +
    /**
42 +
     * Exclude content blocks that aren't linked to a page
43 +
     *
44 +
     * @param bool $excludeDataObject
45 +
     * @param DataObject $dataObject
46 +
     */
47 +
    public function updateUsageExcludeDataObject(bool &$excludeDataObject, DataObject $dataObject)
48 +
    {
49 +
        if (!($dataObject instanceof BaseElement)) {
50 +
            return;
51 +
        }
52 +
        try {
53 +
            if (!$dataObject->getPage()) {
54 +
                $excludeDataObject = true;
55 +
            }
56 +
        } catch (ValidationException $e) {
57 +
        }
58 +
    }
59 +
60 +
    /**
61 +
     * Link BaseElement's to their parent page
62 +
     *
63 +
     * @param array $ancestorDataObjects
64 +
     * @param DataObject $dataObject
21 65
     */
22 -
    public function updateUsage(ArrayList &$dataObjects, DataObject &$record)
66 +
    public function updateUsageAncestorDataObjects(array &$ancestorDataObjects, DataObject $dataObject)
23 67
    {
24 -
        $usage = $dataObjects->exclude('ClassName', ElementalArea::class);
68 +
        if (!($dataObject instanceof BaseElement)) {
69 +
            return;
70 +
        }
71 +
        try {
72 +
            // BaseElement::getPage() caches results so there's no performance decrease from
73 +
            // also calling it in updateUsageExcludeDataObject()
74 +
            /** @var SiteTree $page */
75 +
            if ($page = $dataObject->getPage()) {
76 +
                $ancestorDataObjects[] = $page;
77 +
            }
78 +
        } catch (ValidationException $e) {
79 +
        }
25 80
    }
26 81
}
Files Complexity Coverage
src 513 59.75%
Project Totals (36 files) 513 59.75%
1714.3
10=-f0
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