Code Duplication    Length = 51-56 lines in 2 locations

code/blocks/PageSectionBlock.php 1 location

@@ 17-72 (lines=56) @@
14
 *
15
 * @method HasManyList $Sections
16
 */
17
class PageSectionBlock extends Block
18
{
19
    /**
20
     * @return string
21
     */
22
    public function singular_name()
23
    {
24
        return _t('PageSectionBlock.SINGULARNAME', 'Page Sections Block');
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    public function plural_name()
31
    {
32
        return _t('PageSectionBlock.PLURALNAME', 'Page Sections Blocks');
33
    }
34
35
    /**
36
     * @var array
37
     */
38
    private static $has_many = [
39
        'Sections' => PageSectionObject::class,
40
    ];
41
42
    /**
43
     * @return \SilverStripe\Forms\FieldList
44
     */
45
    public function getCMSFields()
46
    {
47
        $fields = parent::getCMSFields();
48
49
        if ($this->ID) {
50
            // Sections
51
            $config = GridFieldConfig_RecordEditor::create();
52
            $config->addComponent(new GridFieldOrderableRows('SortOrder'));
53
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
54
            $config->removeComponentsByType('GridFieldDeleteAction');
55
            $config->addComponent(new GridFieldDeleteAction(false));
56
            $sectionsField = GridField::create('Sections', 'Sections', $this->Sections()->sort('SortOrder'), $config);
57
            $fields->addFieldsToTab('Root.Sections', array(
58
                $sectionsField,
59
            ));
60
        }
61
62
        return $fields;
63
    }
64
65
    /**
66
     * @return mixed
67
     */
68
    public function getPageSections()
69
    {
70
        return $this->Sections()->sort('SortOrder');
71
    }
72
}

code/blocks/PhotoGalleryBlock.php 1 location

@@ 14-64 (lines=51) @@
11
use SilverStripe\View\Requirements;
12
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
13
14
class PhotoGalleryBlock extends Block
15
{
16
    /**
17
     * @return string
18
     */
19
    public function singular_name()
20
    {
21
        return _t('PhotoGalleryBlock.SINGULARNAME', 'Photo Gallery Block');
22
    }
23
24
    /**
25
     * @return string
26
     */
27
    public function plural_name()
28
    {
29
        return _t('PhotoGalleryBlock.PLURALNAME', 'Photo Gallery Blocks');
30
    }
31
32
    /**
33
     * @var array
34
     */
35
    private static $has_many = array(
36
        'Images' => PhotoGalleryBlockImage::class
37
    );
38
39
    /**
40
     * @return \SilverStripe\Forms\FieldList
41
     */
42
    public function getCMSFields()
43
    {
44
        $fields = parent::getCMSFields();
45
46
        $fields->removeByName([
47
            'Images',
48
        ]);
49
50
        if ($this->owner->ID) {
51
            $config = GridFieldConfig_RecordEditor::create();
52
            $config->addComponent(new GridFieldOrderableRows('SortOrder'));
53
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
54
            $config->removeComponentsByType('GridFieldDeleteAction');
55
            $config->addComponent(new GridFieldDeleteAction(false));
56
            $imagesField = GridField::create('Images', 'Images', $this->Images()->sort('SortOrder'), $config);
57
58
            $fields->addFieldToTab('Root.Photos', $imagesField);
59
60
        }
61
62
        return $fields;
63
    }
64
}
65
66
class PhotoGalleryBlock_Controller extends BlockController
67
{