This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace SheaDawson\Blocks\Model; |
||
4 | |||
5 | use SheaDawson\Blocks\Forms\GridFieldConfigBlockManager; |
||
6 | use SilverStripe\ORM\DataObject; |
||
7 | use SilverStripe\ORM\ArrayLib; |
||
8 | use SilverStripe\CMS\Model\SiteTree; |
||
9 | use SilverStripe\Security\PermissionProvider; |
||
10 | use SilverStripe\Security\Permission; |
||
11 | use SilverStripe\Security\Group; |
||
12 | use SilverStripe\Forms\TreeMultiselectField; |
||
13 | use SilverStripe\Forms\CheckboxField; |
||
14 | use SilverStripe\Forms\HeaderField; |
||
15 | use SilverStripe\Forms\LiteralField; |
||
16 | use SilverStripe\Forms\GridField\GridField; |
||
17 | use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
||
18 | use SilverStripe\Forms\GridField\GridFieldDeleteAction; |
||
19 | use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
||
20 | use Symbiote\MultiValueField\Fields\MultiValueCheckboxField; |
||
21 | use Symbiote\MultiValueField\ORM\FieldType\MultiValueField; |
||
22 | |||
23 | /** |
||
24 | * BlockSet. |
||
25 | * |
||
26 | * @author Shea Dawson <[email protected]> |
||
27 | */ |
||
28 | class BlockSet extends DataObject implements PermissionProvider |
||
29 | { |
||
30 | /** |
||
31 | * @var array |
||
32 | **/ |
||
33 | private static $table_name = "BlockSet"; |
||
0 ignored issues
–
show
Comprehensibility
introduced
by
Loading history...
|
|||
34 | |||
35 | /** |
||
36 | * @var array |
||
37 | **/ |
||
38 | private static $db = [ |
||
0 ignored issues
–
show
|
|||
39 | 'Title' => 'Varchar(255)', |
||
40 | 'PageTypes' => MultiValueField::class, |
||
41 | 'IncludePageParent' => 'Boolean', |
||
42 | ]; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | **/ |
||
47 | private static $many_many = [ |
||
0 ignored issues
–
show
|
|||
48 | "Blocks" => Block::class, |
||
49 | "PageParents" => SiteTree::class, |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * @var array |
||
54 | **/ |
||
55 | private static $many_many_extraFields = [ |
||
0 ignored issues
–
show
|
|||
56 | 'Blocks' => [ |
||
57 | 'Sort' => 'Int', |
||
58 | 'BlockArea' => 'Varchar', |
||
59 | 'AboveOrBelow' => 'Varchar', |
||
60 | ], |
||
61 | ]; |
||
62 | |||
63 | /** |
||
64 | * @var array |
||
65 | **/ |
||
66 | private static $above_or_below_options = [ |
||
0 ignored issues
–
show
|
|||
67 | 'Above' => 'Above Page Blocks', |
||
68 | 'Below' => 'Below Page Blocks', |
||
69 | ]; |
||
70 | |||
71 | public function getCMSFields() |
||
72 | { |
||
73 | $fields = parent::getCMSFields(); |
||
74 | |||
75 | $fields->removeFieldFromTab('Root', 'PageParents'); |
||
76 | |||
77 | $fields->addFieldToTab('Root.Main', HeaderField::create('SettingsHeading', _t('BlockSet.Settings', 'Settings')), 'Title'); |
||
78 | $fields->addFieldToTab('Root.Main', MultiValueCheckboxField::create('PageTypes', _t('BlockSet.OnlyApplyToThesePageTypes', 'Only apply to these Page Types:'), $this->pageTypeOptions()) |
||
79 | ->setDescription(_t('BlockSet.OnlyApplyToThesePageTypesDescription', 'Selected Page Types will inherit this Block Set automatically. Leave all unchecked to apply to all page types.'))); |
||
80 | $fields->addFieldToTab('Root.Main', TreeMultiselectField::create('PageParents', _t('BlockSet.OnlyApplyToChildrenOfThesePages', 'Only apply to children of these Pages:'), 'SilverStripe\\CMS\\Model\\SiteTree')); |
||
81 | $fields->addFieldToTab('Root.Main', CheckboxField::create('IncludePageParent', _t('BlockSet.ApplyBlockSetToSelectedPageParentsAsWellAsChildren','Apply block set to selected page parents as well as children'))); |
||
82 | |||
83 | if (!$this->ID) { |
||
84 | $fields->addFieldToTab('Root.Main', LiteralField::create('NotSaved', "<p class='message warning'>"._t('BlockSet.YouCanAddBlocksToThisSetOnceYouHaveSavedIt', 'You can add Blocks to this set once you have saved it for the first time').'</p>')); |
||
85 | |||
86 | return $fields; |
||
87 | } |
||
88 | |||
89 | $fields->removeFieldFromTab('Root', 'Blocks'); |
||
90 | |||
91 | /** |
||
92 | * @todo - change relation editor back to the custom block manager config and fix issues when 'creating' Blocks from a BlockSet. |
||
93 | */ |
||
94 | $gridConfig = GridFieldConfig_RelationEditor::create(); |
||
95 | $gridConfig->addComponent(new GridFieldOrderableRows('Sort')); |
||
96 | $gridConfig->addComponent(new GridFieldDeleteAction()); |
||
97 | |||
98 | $gridSource = $this->Blocks()->Sort('Sort'); |
||
0 ignored issues
–
show
The method
Blocks does not exist on object<SheaDawson\Blocks\Model\BlockSet> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
99 | |||
100 | $fields->addFieldToTab('Root.Blocks', HeaderField::create('BlocksHeading', _t('Block.PLURALNAME', 'Blocks'))); |
||
101 | $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig)); |
||
102 | |||
103 | return $fields; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Returns a sorted array suitable for a dropdown with pagetypes and their translated name. |
||
108 | * |
||
109 | * @return array |
||
110 | */ |
||
111 | protected function pageTypeOptions() |
||
112 | { |
||
113 | $pageTypes = []; |
||
114 | $classes = ArrayLib::valueKey(SiteTree::page_type_classes()); |
||
115 | unset($classes['VirtualPage']); |
||
116 | unset($classes['ErrorPage']); |
||
117 | unset($classes['RedirectorPage']); |
||
118 | foreach ($classes as $pageTypeClass) { |
||
119 | $pageTypes[$pageTypeClass] = singleton($pageTypeClass)->i18n_singular_name(); |
||
120 | } |
||
121 | asort($pageTypes); |
||
122 | |||
123 | return $pageTypes; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Returns a list of pages this BlockSet features on. |
||
128 | * |
||
129 | * @return DataList |
||
130 | */ |
||
131 | public function Pages() |
||
132 | { |
||
133 | $pages = SiteTree::get(); |
||
134 | $types = $this->PageTypes->getValue(); |
||
0 ignored issues
–
show
The property
PageTypes does not exist on object<SheaDawson\Blocks\Model\BlockSet> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property.
Loading history...
|
|||
135 | if (count($types)) { |
||
136 | $pages = $pages->filter('ClassName', $types); |
||
137 | } |
||
138 | |||
139 | $parents = $this->PageParents()->column('ID'); |
||
0 ignored issues
–
show
The method
PageParents does not exist on object<SheaDawson\Blocks\Model\BlockSet> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
140 | if (count($parents)) { |
||
141 | $pages = $pages->filter('ParentID', $parents); |
||
142 | } |
||
143 | |||
144 | return $pages; |
||
145 | } |
||
146 | |||
147 | public function canView($member = null) |
||
148 | { |
||
149 | return true; |
||
150 | } |
||
151 | |||
152 | public function canEdit($member = null) |
||
153 | { |
||
154 | return Permission::check('ADMIN', 'any', $member) || Permission::check('BLOCK_EDIT', 'any', $member); |
||
155 | } |
||
156 | |||
157 | public function canDelete($member = null) |
||
158 | { |
||
159 | return Permission::check('ADMIN', 'any', $member) || Permission::check('BLOCK_DELETE', 'any', $member); |
||
160 | } |
||
161 | |||
162 | public function canCreate($member = null, $context = []) |
||
163 | { |
||
164 | return Permission::check('ADMIN', 'any', $member) || Permission::check('BLOCK_CREATE', 'any', $member); |
||
165 | } |
||
166 | |||
167 | public function providePermissions() |
||
168 | { |
||
169 | return [ |
||
170 | 'BLOCKSET_EDIT' => [ |
||
171 | 'name' => _t('BlockSet.EditBlockSet','Edit a Block Set'), |
||
172 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
||
173 | ], |
||
174 | 'BLOCKSET_DELETE' => [ |
||
175 | 'name' => _t('BlockSet.DeleteBlockSet','Delete a Block Set'), |
||
176 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
||
177 | ], |
||
178 | 'BLOCKSET_CREATE' => [ |
||
179 | 'name' => _t('BlockSet.CreateBlockSet','Create a Block Set'), |
||
180 | 'category' => _t('Block.PermissionCategory', 'Blocks'), |
||
181 | ], |
||
182 | ]; |
||
183 | } |
||
184 | } |
||
185 |