Issues (158)

code/extension/ShareThisSiteConfigDE.php (1 issue)

Severity
1
<?php
2
3
namespace SunnysideUp\ShareThis;
4
5
use SilverStripe\Forms\FieldList;
6
use SunnysideUp\ShareThis\ShareThisDataObject;
7
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
8
use SilverStripe\Forms\GridField\GridField;
9
use SunnysideUp\ShareThis\SocialNetworkingLinksDataObject;
10
use SilverStripe\Forms\HiddenField;
11
use SilverStripe\Forms\CheckboxField;
12
use SilverStripe\Forms\LiteralField;
13
use SilverStripe\Forms\Tab;
14
use SilverStripe\Forms\TabSet;
15
use SilverStripe\ORM\DataExtension;
16
17
/**
18
 * @todo Check that permissions on the 2 tables in the CMS are the same than before
19
 * @todo Fix the CanEditShareIcons section in updateCMSFields
20
 */
21
class ShareThisSiteConfigDE extends DataExtension
22
{
23
    /**
24
     * @var array
25
     */
26
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
27
        'AlwaysIncludeShareThisLinks' => 'Boolean',
28
        'AlwaysIncludeSocialNetworkingLinks' => 'Boolean',
29
        'IncludeByDefaultShareThisLinks' => 'Boolean',
30
        'IncludeByDefaultSocialNetworkingLinks' => 'Boolean',
31
        'ShareThisAllInOne' => 'Boolean'
32
    ];
33
34
    /**
35
     * @param  FieldList $fields
36
     *
37
     * @return FieldList $fields
38
     */
39
    public function updateCMSFields(FieldList $fields)
40
    {
41
        $individualPageNoteWith = _t("ShareThis.INDIVIDUAL_PAGE_NOTE_WITH", " (with the ability to turn them off/on on individual pages) ");
42
43
        $individualPageNoteWithout  = _t("ShareThis.INDIVIDUAL_PAGE_NOTE_WITHOUT", " (without the ability to turn them off/on on individual pages) ");
44
45
        $shareThisExtra = '<h3 style="margin-top: 50px">Select Icons</h3>';
46
47
        $shareThisTableField = GridField::create('ShareThisOptions', null, ShareThisDataObject::get(), GridFieldConfig_RecordEditor::create());
48
49
        $socialNetworkExtra = '<h3 style="margin-top: 50px">Add / Edit / Delete Your Social Networking Home Pages (e.g. www.facebook.com/our-company-page)</h3>';
50
51
        $socialNetworkTableField = GridField::create('JoinUs', null, SocialNetworkingLinksDataObject::get(), GridFieldConfig_RecordEditor::create());
52
53
        if ($this->owner->AlwaysIncludeShareThisLinks) {
54
            $defaultShareThisCheckbox = HiddenField::create('IncludeByDefaultShareThisLinks', true);
55
        } else {
56
            $defaultShareThisCheckbox = CheckboxField::create('IncludeByDefaultShareThisLinks', 'Show links on every page by default '.$individualPageNoteWith);
57
        }
58
59
        if ($this->owner->AlwaysIncludeSocialNetworkingLinks) {
60
            $defaultSocialNetworkingCheckbox = HiddenField::create('IncludeByDefaultSocialNetworkingLinks', true);
61
        } else {
62
            $defaultSocialNetworkingCheckbox = CheckboxField::create('IncludeByDefaultSocialNetworkingLinks', 'Include on every page by default '.$individualPageNoteWith);
63
        }
64
65
        $fields->addFieldToTab(
66
            'Root.SocialMedia',
67
            TabSet::create(
68
                'SocialNetworkingOptions',
69
                Tab::create(
70
                    'ShareThis',
71
                    CheckboxField::create('AlwaysIncludeShareThisLinks', 'Show links on every page '.$individualPageNoteWithout),
72
                    $defaultShareThisCheckbox,
73
                    CheckboxField::create('ShareThisAllInOne', 'Add a \'share\' all-in-one button'),
74
                    LiteralField::create('shareThisExtra', $shareThisExtra),
75
                    $shareThisTableField
76
                ),
77
                Tab::create(
78
                    'JoinUs',
79
                    CheckboxField::create('AlwaysIncludeSocialNetworkingLinks', 'Show links on every page '.$individualPageNoteWithout),
80
                    $defaultSocialNetworkingCheckbox,
81
                    LiteralField::create('socialNetworkExtra', $socialNetworkExtra),
82
                    $socialNetworkTableField
83
                )
84
            )
85
        );
86
87
        return $fields;
88
    }
89
90
    /**
91
     * CanEditShareIcons
92
     *
93
     * @return void
94
     */
95
    public function CanEditShareIcons()
96
    {
97
        if (class_exists('DataObjectSorterDOD')) {
98
            $obj = singleton(ShareThisDataObject::class);
99
            if ($obj->hasExtension('DataObjectSorterDOD')) {
100
                return true;
101
            } else {
102
                USER_ERROR('You have installed DataObjectSorterDOD, but you have not extended ShareThisDataObject with DataObjectSorterDOD, see sharethis/_config.php for more information.', E_USER_NOTICE);
103
            }
104
        } else {
105
            USER_ERROR('You need to install the DataObjectSorter module (see sharethis/README or sharethis/_config.php for more information)', E_USER_NOTICE);
106
        }
107
    }
108
}
109