| @@ -15,121 +15,121 @@ | ||
| 15 | 15 | */ | 
| 16 | 16 | class Quicklink extends DataObject | 
| 17 | 17 |  { | 
| 18 | - private static $db = [ | |
| 19 | - 'Name' => 'Varchar(255)', | |
| 20 | - 'ExternalLink' => 'Varchar(255)', | |
| 21 | - 'SortOrder' => 'Int', | |
| 22 | - ]; | |
| 23 | - | |
| 24 | - private static $has_one = [ | |
| 25 | - 'Parent' => BaseHomePage::class, | |
| 26 | - 'InternalLink' => SiteTree::class, | |
| 27 | - ]; | |
| 28 | - | |
| 29 | - private static $summary_fields = [ | |
| 30 | - 'Name' => 'Name', | |
| 31 | - 'InternalLink.Title' => 'Internal Link', | |
| 32 | - 'ExternalLink' => 'External Link', | |
| 33 | - ]; | |
| 34 | - | |
| 35 | - private static $table_name = 'Quicklink'; | |
| 36 | - | |
| 37 | - public function fieldLabels($includerelations = true) | |
| 38 | -    { | |
| 39 | - $labels = parent::fieldLabels($includerelations); | |
| 40 | - $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); | |
| 41 | - $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); | |
| 42 | - $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); | |
| 43 | - $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); | |
| 44 | - $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); | |
| 45 | - | |
| 46 | - return $labels; | |
| 47 | - } | |
| 48 | - | |
| 49 | - public function getLink() | |
| 50 | -    { | |
| 51 | -        if ($this->ExternalLink) { | |
| 52 | - $url = parse_url($this->ExternalLink); | |
| 53 | - | |
| 54 | - // if no scheme set in the link, default to http | |
| 55 | -            if (!isset($url['scheme'])) { | |
| 56 | - return 'http://' . $this->ExternalLink; | |
| 57 | - } | |
| 58 | - | |
| 59 | - return $this->ExternalLink; | |
| 60 | - } | |
| 61 | - | |
| 62 | -        if ($this->InternalLinkID) { | |
| 63 | - return $this->InternalLink()->Link(); | |
| 64 | - } | |
| 65 | - } | |
| 66 | - | |
| 67 | - public function canCreate($member = null, $context = []) | |
| 68 | -    { | |
| 69 | - // Creating quick links should not be the same permission level as creating parent pages for them, they're | |
| 70 | - // essentially content in the context of the page, so use the edit permission instead. | |
| 71 | - return $this->canEdit($member); | |
| 72 | - } | |
| 73 | - | |
| 74 | - public function canEdit($member = null) | |
| 75 | -    { | |
| 76 | - return $this->Parent()->canEdit($member); | |
| 77 | - } | |
| 78 | - | |
| 79 | - public function canDelete($member = null) | |
| 80 | -    { | |
| 81 | - return $this->Parent()->canDelete($member); | |
| 82 | - } | |
| 83 | - | |
| 84 | - public function canView($member = null) | |
| 85 | -    { | |
| 86 | - return $this->Parent()->canView($member); | |
| 87 | - } | |
| 88 | - | |
| 89 | - public function getCMSFields() | |
| 90 | -    { | |
| 91 | - $fields = parent::getCMSFields(); | |
| 92 | - | |
| 93 | -        $fields->removeByName('ParentID'); | |
| 94 | - | |
| 95 | -        $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); | |
| 96 | - | |
| 97 | -        $fields->removeByName('ExternalLink'); | |
| 98 | -        $fields->removeByName('InternalLinkID'); | |
| 99 | -        $fields->removeByName('SortOrder'); | |
| 100 | -        $externalLinkField->addExtraClass('noBorder'); | |
| 101 | - | |
| 102 | -        $fields->addFieldToTab('Root.Main', CompositeField::create( | |
| 103 | - array( | |
| 104 | - TreeDropdownField::create( | |
| 105 | - 'InternalLinkID', | |
| 106 | -                    $this->fieldLabel('InternalLinkID'), | |
| 107 | - SiteTree::class | |
| 108 | - ), | |
| 109 | - $externalLinkField, | |
| 110 | - $wrap = CompositeField::create( | |
| 111 | - $extraLabel = LiteralField::create( | |
| 112 | - 'NoteOverride', | |
| 113 | -                        sprintf('<div class="message good notice">%s</div>', _t( | |
| 114 | - __CLASS__ . '.Note', | |
| 115 | - 'Note: If you specify an External Link, the Internal Link will be ignored.' | |
| 116 | - )) | |
| 117 | - ) | |
| 118 | - ) | |
| 119 | - ) | |
| 120 | - )); | |
| 121 | - $fields->insertBefore( | |
| 122 | - 'Name', | |
| 123 | - LiteralField::create( | |
| 124 | - 'Note', | |
| 125 | -                sprintf('<p>%s</p>', _t( | |
| 126 | - __CLASS__ . '.Note2', | |
| 127 | - 'Use this to specify a link to a page either on this site ' | |
| 128 | - . '(Internal Link) or another site (External Link).' | |
| 129 | - )) | |
| 130 | - ) | |
| 131 | - ); | |
| 132 | - | |
| 133 | - return $fields; | |
| 134 | - } | |
| 18 | + private static $db = [ | |
| 19 | + 'Name' => 'Varchar(255)', | |
| 20 | + 'ExternalLink' => 'Varchar(255)', | |
| 21 | + 'SortOrder' => 'Int', | |
| 22 | + ]; | |
| 23 | + | |
| 24 | + private static $has_one = [ | |
| 25 | + 'Parent' => BaseHomePage::class, | |
| 26 | + 'InternalLink' => SiteTree::class, | |
| 27 | + ]; | |
| 28 | + | |
| 29 | + private static $summary_fields = [ | |
| 30 | + 'Name' => 'Name', | |
| 31 | + 'InternalLink.Title' => 'Internal Link', | |
| 32 | + 'ExternalLink' => 'External Link', | |
| 33 | + ]; | |
| 34 | + | |
| 35 | + private static $table_name = 'Quicklink'; | |
| 36 | + | |
| 37 | + public function fieldLabels($includerelations = true) | |
| 38 | +	{ | |
| 39 | + $labels = parent::fieldLabels($includerelations); | |
| 40 | + $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); | |
| 41 | + $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); | |
| 42 | + $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); | |
| 43 | + $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); | |
| 44 | + $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); | |
| 45 | + | |
| 46 | + return $labels; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public function getLink() | |
| 50 | +	{ | |
| 51 | +		if ($this->ExternalLink) { | |
| 52 | + $url = parse_url($this->ExternalLink); | |
| 53 | + | |
| 54 | + // if no scheme set in the link, default to http | |
| 55 | +			if (!isset($url['scheme'])) { | |
| 56 | + return 'http://' . $this->ExternalLink; | |
| 57 | + } | |
| 58 | + | |
| 59 | + return $this->ExternalLink; | |
| 60 | + } | |
| 61 | + | |
| 62 | +		if ($this->InternalLinkID) { | |
| 63 | + return $this->InternalLink()->Link(); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + | |
| 67 | + public function canCreate($member = null, $context = []) | |
| 68 | +	{ | |
| 69 | + // Creating quick links should not be the same permission level as creating parent pages for them, they're | |
| 70 | + // essentially content in the context of the page, so use the edit permission instead. | |
| 71 | + return $this->canEdit($member); | |
| 72 | + } | |
| 73 | + | |
| 74 | + public function canEdit($member = null) | |
| 75 | +	{ | |
| 76 | + return $this->Parent()->canEdit($member); | |
| 77 | + } | |
| 78 | + | |
| 79 | + public function canDelete($member = null) | |
| 80 | +	{ | |
| 81 | + return $this->Parent()->canDelete($member); | |
| 82 | + } | |
| 83 | + | |
| 84 | + public function canView($member = null) | |
| 85 | +	{ | |
| 86 | + return $this->Parent()->canView($member); | |
| 87 | + } | |
| 88 | + | |
| 89 | + public function getCMSFields() | |
| 90 | +	{ | |
| 91 | + $fields = parent::getCMSFields(); | |
| 92 | + | |
| 93 | +		$fields->removeByName('ParentID'); | |
| 94 | + | |
| 95 | +		$externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); | |
| 96 | + | |
| 97 | +		$fields->removeByName('ExternalLink'); | |
| 98 | +		$fields->removeByName('InternalLinkID'); | |
| 99 | +		$fields->removeByName('SortOrder'); | |
| 100 | +		$externalLinkField->addExtraClass('noBorder'); | |
| 101 | + | |
| 102 | +		$fields->addFieldToTab('Root.Main', CompositeField::create( | |
| 103 | + array( | |
| 104 | + TreeDropdownField::create( | |
| 105 | + 'InternalLinkID', | |
| 106 | +					$this->fieldLabel('InternalLinkID'), | |
| 107 | + SiteTree::class | |
| 108 | + ), | |
| 109 | + $externalLinkField, | |
| 110 | + $wrap = CompositeField::create( | |
| 111 | + $extraLabel = LiteralField::create( | |
| 112 | + 'NoteOverride', | |
| 113 | +						sprintf('<div class="message good notice">%s</div>', _t( | |
| 114 | + __CLASS__ . '.Note', | |
| 115 | + 'Note: If you specify an External Link, the Internal Link will be ignored.' | |
| 116 | + )) | |
| 117 | + ) | |
| 118 | + ) | |
| 119 | + ) | |
| 120 | + )); | |
| 121 | + $fields->insertBefore( | |
| 122 | + 'Name', | |
| 123 | + LiteralField::create( | |
| 124 | + 'Note', | |
| 125 | +				sprintf('<p>%s</p>', _t( | |
| 126 | + __CLASS__ . '.Note2', | |
| 127 | + 'Use this to specify a link to a page either on this site ' | |
| 128 | + . '(Internal Link) or another site (External Link).' | |
| 129 | + )) | |
| 130 | + ) | |
| 131 | + ); | |
| 132 | + | |
| 133 | + return $fields; | |
| 134 | + } | |
| 135 | 135 | } |