@@ 8-63 (lines=56) @@ | ||
5 | * |
|
6 | * @method HasManyList $Sections |
|
7 | */ |
|
8 | class PageSectionBlock extends Block |
|
9 | { |
|
10 | /** |
|
11 | * @return string |
|
12 | */ |
|
13 | public function singular_name() |
|
14 | { |
|
15 | return _t('PageSectionBlock.SINGULARNAME', 'Page Sections Block'); |
|
16 | } |
|
17 | ||
18 | /** |
|
19 | * @return string |
|
20 | */ |
|
21 | public function plural_name() |
|
22 | { |
|
23 | return _t('PageSectionBlock.PLURALNAME', 'Page Sections Blocks'); |
|
24 | } |
|
25 | ||
26 | /** |
|
27 | * @var array |
|
28 | */ |
|
29 | private static $has_many = [ |
|
30 | 'Sections' => 'PageSectionObject', |
|
31 | ]; |
|
32 | ||
33 | /** |
|
34 | * @return FieldList |
|
35 | */ |
|
36 | public function getCMSFields() |
|
37 | { |
|
38 | $fields = parent::getCMSFields(); |
|
39 | ||
40 | if ($this->ID) { |
|
41 | // Sections |
|
42 | $config = GridFieldConfig_RecordEditor::create(); |
|
43 | $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
|
44 | $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
45 | $config->removeComponentsByType('GridFieldDeleteAction'); |
|
46 | $config->addComponent(new GridFieldDeleteAction(false)); |
|
47 | $sectionsField = GridField::create('Sections', 'Sections', $this->Sections()->sort('SortOrder'), $config); |
|
48 | $fields->addFieldsToTab('Root.Sections', array( |
|
49 | $sectionsField, |
|
50 | )); |
|
51 | } |
|
52 | ||
53 | return $fields; |
|
54 | } |
|
55 | ||
56 | /** |
|
57 | * @return mixed |
|
58 | */ |
|
59 | public function getPageSections() |
|
60 | { |
|
61 | return $this->Sections()->sort('SortOrder'); |
|
62 | } |
|
63 | } |
@@ 3-53 (lines=51) @@ | ||
1 | <?php |
|
2 | ||
3 | class PhotoGalleryBlock extends Block |
|
4 | { |
|
5 | /** |
|
6 | * @return string |
|
7 | */ |
|
8 | public function singular_name() |
|
9 | { |
|
10 | return _t('PhotoGalleryBlock.SINGULARNAME', 'Photo Gallery Block'); |
|
11 | } |
|
12 | ||
13 | /** |
|
14 | * @return string |
|
15 | */ |
|
16 | public function plural_name() |
|
17 | { |
|
18 | return _t('PhotoGalleryBlock.PLURALNAME', 'Photo Gallery Blocks'); |
|
19 | } |
|
20 | ||
21 | /** |
|
22 | * @var array |
|
23 | */ |
|
24 | private static $has_many = array( |
|
25 | 'Images' => 'PhotoGalleryBlockImage' |
|
26 | ); |
|
27 | ||
28 | /** |
|
29 | * @return FieldList |
|
30 | */ |
|
31 | public function getCMSFields() |
|
32 | { |
|
33 | $fields = parent::getCMSFields(); |
|
34 | ||
35 | $fields->removeByName([ |
|
36 | 'Images', |
|
37 | ]); |
|
38 | ||
39 | if ($this->owner->ID) { |
|
40 | $config = GridFieldConfig_RecordEditor::create(); |
|
41 | $config->addComponent(new GridFieldOrderableRows('SortOrder')); |
|
42 | $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
43 | $config->removeComponentsByType('GridFieldDeleteAction'); |
|
44 | $config->addComponent(new GridFieldDeleteAction(false)); |
|
45 | $imagesField = GridField::create('Images', 'Images', $this->Images()->sort('SortOrder'), $config); |
|
46 | ||
47 | $fields->addFieldToTab('Root.Photos', $imagesField); |
|
48 | ||
49 | } |
|
50 | ||
51 | return $fields; |
|
52 | } |
|
53 | } |
|
54 | ||
55 | class PhotoGalleryBlock_Controller extends Block_Controller |
|
56 | { |