@@ -11,53 +11,53 @@ |
||
11 | 11 | class CwpSiteTreeFileExtension extends DataExtension |
12 | 12 | { |
13 | 13 | |
14 | - public function updateCMSFields(FieldList $fields) |
|
15 | - { |
|
16 | - Requirements::css('cwp/cwp:css/fieldDescriptionToggle.css'); |
|
17 | - Requirements::javascript('cwp/cwp:javascript/fieldDescriptionToggle.js'); |
|
18 | - |
|
19 | - $fields->insertAfter( |
|
20 | - 'LastEdited', |
|
21 | - ReadonlyField::create( |
|
22 | - 'BackLinkCount', |
|
23 | - _t('SilverStripe\\CMS\\Model\\SiteTreeFileExtension.BACKLINKCOUNT', 'Used on:'), |
|
24 | - $this->owner->BackLinkTracking()->Count() . ' ' |
|
25 | - . _t('SilverStripe\\CMS\\Model\\SiteTreeFileExtension.PAGES', 'page(s)') |
|
26 | - ) |
|
27 | - ->addExtraClass('cms-description-toggle') |
|
28 | - ->setDescription($this->BackLinkHTMLList()) |
|
29 | - ); |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Generate an HTML list which provides links to where a file is used. |
|
34 | - * |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function BackLinkHTMLList() |
|
38 | - { |
|
39 | - $html = '<em>' . _t( |
|
40 | - __CLASS__ . '.BACKLINK_LIST_DESCRIPTION', |
|
41 | - 'This list shows all pages where the file has been added through a WYSIWYG editor.' |
|
42 | - ) . '</em>'; |
|
43 | - $html .= '<ul>'; |
|
44 | - |
|
45 | - foreach ($this->owner->BackLinkTracking() as $backLink) { |
|
46 | - $listItem = '<li>'; |
|
47 | - |
|
48 | - // Add the page link |
|
49 | - $listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' |
|
50 | - . Convert::raw2xml($backLink->MenuTitle) . '</a> – '; |
|
51 | - |
|
52 | - // Add the CMS link |
|
53 | - $listItem .= '<a href="' . $backLink->CMSEditLink() . '">' |
|
54 | - . _t(__CLASS__ . '.EDIT', 'Edit') . '</a>'; |
|
55 | - |
|
56 | - $html .= $listItem . '</li>'; |
|
57 | - } |
|
58 | - |
|
59 | - $html .= '</ul>'; |
|
60 | - |
|
61 | - return $html; |
|
62 | - } |
|
14 | + public function updateCMSFields(FieldList $fields) |
|
15 | + { |
|
16 | + Requirements::css('cwp/cwp:css/fieldDescriptionToggle.css'); |
|
17 | + Requirements::javascript('cwp/cwp:javascript/fieldDescriptionToggle.js'); |
|
18 | + |
|
19 | + $fields->insertAfter( |
|
20 | + 'LastEdited', |
|
21 | + ReadonlyField::create( |
|
22 | + 'BackLinkCount', |
|
23 | + _t('SilverStripe\\CMS\\Model\\SiteTreeFileExtension.BACKLINKCOUNT', 'Used on:'), |
|
24 | + $this->owner->BackLinkTracking()->Count() . ' ' |
|
25 | + . _t('SilverStripe\\CMS\\Model\\SiteTreeFileExtension.PAGES', 'page(s)') |
|
26 | + ) |
|
27 | + ->addExtraClass('cms-description-toggle') |
|
28 | + ->setDescription($this->BackLinkHTMLList()) |
|
29 | + ); |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Generate an HTML list which provides links to where a file is used. |
|
34 | + * |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function BackLinkHTMLList() |
|
38 | + { |
|
39 | + $html = '<em>' . _t( |
|
40 | + __CLASS__ . '.BACKLINK_LIST_DESCRIPTION', |
|
41 | + 'This list shows all pages where the file has been added through a WYSIWYG editor.' |
|
42 | + ) . '</em>'; |
|
43 | + $html .= '<ul>'; |
|
44 | + |
|
45 | + foreach ($this->owner->BackLinkTracking() as $backLink) { |
|
46 | + $listItem = '<li>'; |
|
47 | + |
|
48 | + // Add the page link |
|
49 | + $listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' |
|
50 | + . Convert::raw2xml($backLink->MenuTitle) . '</a> – '; |
|
51 | + |
|
52 | + // Add the CMS link |
|
53 | + $listItem .= '<a href="' . $backLink->CMSEditLink() . '">' |
|
54 | + . _t(__CLASS__ . '.EDIT', 'Edit') . '</a>'; |
|
55 | + |
|
56 | + $html .= $listItem . '</li>'; |
|
57 | + } |
|
58 | + |
|
59 | + $html .= '</ul>'; |
|
60 | + |
|
61 | + return $html; |
|
62 | + } |
|
63 | 63 | } |
@@ -9,39 +9,39 @@ |
||
9 | 9 | |
10 | 10 | class CwpSiteTreeExtension extends DataExtension |
11 | 11 | { |
12 | - private static $db = array( |
|
13 | - 'ShowPageUtilities' => 'Boolean(1)' |
|
14 | - ); |
|
12 | + private static $db = array( |
|
13 | + 'ShowPageUtilities' => 'Boolean(1)' |
|
14 | + ); |
|
15 | 15 | |
16 | - private static $defaults = array( |
|
17 | - 'ShowPageUtilities' => true |
|
18 | - ); |
|
16 | + private static $defaults = array( |
|
17 | + 'ShowPageUtilities' => true |
|
18 | + ); |
|
19 | 19 | |
20 | - /** |
|
21 | - * Modify the settings for a SiteTree |
|
22 | - * |
|
23 | - * {@inheritDoc} |
|
24 | - * |
|
25 | - * @param FieldList $fields |
|
26 | - */ |
|
27 | - public function updateSettingsFields(FieldList $fields) |
|
28 | - { |
|
29 | - $helpText = _t( |
|
30 | - __CLASS__ . '.SHOW_PAGE_UTILITIES_HELP', |
|
31 | - 'You can disable page utilities (print, share, etc) for this page' |
|
32 | - ); |
|
20 | + /** |
|
21 | + * Modify the settings for a SiteTree |
|
22 | + * |
|
23 | + * {@inheritDoc} |
|
24 | + * |
|
25 | + * @param FieldList $fields |
|
26 | + */ |
|
27 | + public function updateSettingsFields(FieldList $fields) |
|
28 | + { |
|
29 | + $helpText = _t( |
|
30 | + __CLASS__ . '.SHOW_PAGE_UTILITIES_HELP', |
|
31 | + 'You can disable page utilities (print, share, etc) for this page' |
|
32 | + ); |
|
33 | 33 | |
34 | - $fields->addFieldsToTab( |
|
35 | - 'Root.Settings', |
|
36 | - array( |
|
37 | - LiteralField::create('PageUtilitiesHelp', $helpText), |
|
38 | - CheckboxField::create('ShowPageUtilities', $this->owner->fieldLabel('ShowPageUtilities')) |
|
39 | - ) |
|
40 | - ); |
|
41 | - } |
|
34 | + $fields->addFieldsToTab( |
|
35 | + 'Root.Settings', |
|
36 | + array( |
|
37 | + LiteralField::create('PageUtilitiesHelp', $helpText), |
|
38 | + CheckboxField::create('ShowPageUtilities', $this->owner->fieldLabel('ShowPageUtilities')) |
|
39 | + ) |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | - public function updateFieldLabels(&$labels) |
|
44 | - { |
|
45 | - $labels['ShowPageUtilities'] = _t(__CLASS__ . '.SHOW_PAGE_UTILITIES', 'Show page utilities?'); |
|
46 | - } |
|
43 | + public function updateFieldLabels(&$labels) |
|
44 | + { |
|
45 | + $labels['ShowPageUtilities'] = _t(__CLASS__ . '.SHOW_PAGE_UTILITIES', 'Show page utilities?'); |
|
46 | + } |
|
47 | 47 | } |
@@ -7,57 +7,57 @@ |
||
7 | 7 | |
8 | 8 | class EventHolder extends DatedUpdateHolder |
9 | 9 | { |
10 | - private static $description = 'Container page for Event Pages, provides event filtering and pagination'; |
|
11 | - |
|
12 | - private static $allowed_children = [ |
|
13 | - EventPage::class, |
|
14 | - ]; |
|
15 | - |
|
16 | - private static $default_child = EventPage::class; |
|
17 | - |
|
18 | - private static $update_name = 'Events'; |
|
19 | - |
|
20 | - private static $update_class = EventPage::class; |
|
21 | - |
|
22 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_holder.png'; |
|
23 | - |
|
24 | - private static $singular_name = 'Event Holder'; |
|
25 | - |
|
26 | - private static $plural_name = 'Event Holders'; |
|
27 | - |
|
28 | - private static $table_name = 'EventHolder'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Find all site's news items, based on some filters. |
|
32 | - * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | - * |
|
34 | - * @param string $className The name of the class to fetch. |
|
35 | - * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | - * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | - * @param string $dateFrom The beginning of a date filter range. |
|
38 | - * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | - * @param int $year Numeric value of the year to show. |
|
40 | - * @param int $monthNumber Numeric value of the month to show. |
|
41 | - * |
|
42 | - * @returns DataList|PaginatedList |
|
43 | - */ |
|
44 | - public static function AllUpdates( |
|
45 | - $className = 'Events', |
|
46 | - $parentID = null, |
|
47 | - $tagID = null, |
|
48 | - $dateFrom = null, |
|
49 | - $dateTo = null, |
|
50 | - $year = null, |
|
51 | - $monthNumber = null |
|
52 | - ) { |
|
53 | - return parent::AllUpdates( |
|
54 | - $className, |
|
55 | - $parentID, |
|
56 | - $tagID, |
|
57 | - $dateFrom, |
|
58 | - $dateTo, |
|
59 | - $year, |
|
60 | - $monthNumber |
|
61 | - )->Sort('Date', 'ASC'); |
|
62 | - } |
|
10 | + private static $description = 'Container page for Event Pages, provides event filtering and pagination'; |
|
11 | + |
|
12 | + private static $allowed_children = [ |
|
13 | + EventPage::class, |
|
14 | + ]; |
|
15 | + |
|
16 | + private static $default_child = EventPage::class; |
|
17 | + |
|
18 | + private static $update_name = 'Events'; |
|
19 | + |
|
20 | + private static $update_class = EventPage::class; |
|
21 | + |
|
22 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_holder.png'; |
|
23 | + |
|
24 | + private static $singular_name = 'Event Holder'; |
|
25 | + |
|
26 | + private static $plural_name = 'Event Holders'; |
|
27 | + |
|
28 | + private static $table_name = 'EventHolder'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Find all site's news items, based on some filters. |
|
32 | + * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | + * |
|
34 | + * @param string $className The name of the class to fetch. |
|
35 | + * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | + * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | + * @param string $dateFrom The beginning of a date filter range. |
|
38 | + * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | + * @param int $year Numeric value of the year to show. |
|
40 | + * @param int $monthNumber Numeric value of the month to show. |
|
41 | + * |
|
42 | + * @returns DataList|PaginatedList |
|
43 | + */ |
|
44 | + public static function AllUpdates( |
|
45 | + $className = 'Events', |
|
46 | + $parentID = null, |
|
47 | + $tagID = null, |
|
48 | + $dateFrom = null, |
|
49 | + $dateTo = null, |
|
50 | + $year = null, |
|
51 | + $monthNumber = null |
|
52 | + ) { |
|
53 | + return parent::AllUpdates( |
|
54 | + $className, |
|
55 | + $parentID, |
|
56 | + $tagID, |
|
57 | + $dateFrom, |
|
58 | + $dateTo, |
|
59 | + $year, |
|
60 | + $monthNumber |
|
61 | + )->Sort('Date', 'ASC'); |
|
62 | + } |
|
63 | 63 | } |
@@ -7,50 +7,50 @@ |
||
7 | 7 | |
8 | 8 | class NewsHolder extends DatedUpdateHolder |
9 | 9 | { |
10 | - private static $description = 'Container page for News Pages, provides news filtering and pagination'; |
|
11 | - |
|
12 | - private static $allowed_children = [ |
|
13 | - NewsPage::class, |
|
14 | - ]; |
|
15 | - |
|
16 | - private static $default_child = NewsPage::class; |
|
17 | - |
|
18 | - private static $update_name = 'News'; |
|
19 | - |
|
20 | - private static $update_class = NewsPage::class; |
|
21 | - |
|
22 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/news_listing.png'; |
|
23 | - |
|
24 | - private static $singular_name = 'News Holder'; |
|
25 | - |
|
26 | - private static $plural_name = 'News Holders'; |
|
27 | - |
|
28 | - private static $table_name = 'NewsHolder'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Find all site's news items, based on some filters. |
|
32 | - * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | - * |
|
34 | - * @param string $className The name of the class to fetch. |
|
35 | - * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | - * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | - * @param string $dateFrom The beginning of a date filter range. |
|
38 | - * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | - * @param int $year Numeric value of the year to show. |
|
40 | - * @param int $monthNumber Numeric value of the month to show. |
|
41 | - * |
|
42 | - * @returns DataList|PaginatedList |
|
43 | - */ |
|
44 | - public static function AllUpdates( |
|
45 | - $className = NewsPage::class, |
|
46 | - $parentID = null, |
|
47 | - $tagID = null, |
|
48 | - $dateFrom = null, |
|
49 | - $dateTo = null, |
|
50 | - $year = null, |
|
51 | - $monthNumber = null |
|
52 | - ) { |
|
53 | - return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber) |
|
54 | - ->Sort('Date', 'DESC'); |
|
55 | - } |
|
10 | + private static $description = 'Container page for News Pages, provides news filtering and pagination'; |
|
11 | + |
|
12 | + private static $allowed_children = [ |
|
13 | + NewsPage::class, |
|
14 | + ]; |
|
15 | + |
|
16 | + private static $default_child = NewsPage::class; |
|
17 | + |
|
18 | + private static $update_name = 'News'; |
|
19 | + |
|
20 | + private static $update_class = NewsPage::class; |
|
21 | + |
|
22 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/news_listing.png'; |
|
23 | + |
|
24 | + private static $singular_name = 'News Holder'; |
|
25 | + |
|
26 | + private static $plural_name = 'News Holders'; |
|
27 | + |
|
28 | + private static $table_name = 'NewsHolder'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Find all site's news items, based on some filters. |
|
32 | + * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
33 | + * |
|
34 | + * @param string $className The name of the class to fetch. |
|
35 | + * @param int $parentID The ID of the holder to extract the news items from. |
|
36 | + * @param int $tagID The ID of the tag to filter the news items by. |
|
37 | + * @param string $dateFrom The beginning of a date filter range. |
|
38 | + * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
39 | + * @param int $year Numeric value of the year to show. |
|
40 | + * @param int $monthNumber Numeric value of the month to show. |
|
41 | + * |
|
42 | + * @returns DataList|PaginatedList |
|
43 | + */ |
|
44 | + public static function AllUpdates( |
|
45 | + $className = NewsPage::class, |
|
46 | + $parentID = null, |
|
47 | + $tagID = null, |
|
48 | + $dateFrom = null, |
|
49 | + $dateTo = null, |
|
50 | + $year = null, |
|
51 | + $monthNumber = null |
|
52 | + ) { |
|
53 | + return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber) |
|
54 | + ->Sort('Date', 'DESC'); |
|
55 | + } |
|
56 | 56 | } |
@@ -64,7 +64,7 @@ |
||
64 | 64 | |
65 | 65 | public function getCMSFields() |
66 | 66 | { |
67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
67 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
68 | 68 | $fields->removeByName('Date'); |
69 | 69 | |
70 | 70 | $dateTimeFields = array(); |
@@ -12,81 +12,81 @@ |
||
12 | 12 | |
13 | 13 | class EventPage extends DatedUpdatePage |
14 | 14 | { |
15 | - private static $description = 'Describes an event occurring on a specific date.'; |
|
16 | - |
|
17 | - private static $default_parent = EventHolder::class; |
|
18 | - |
|
19 | - private static $can_be_root = false; |
|
20 | - |
|
21 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png'; |
|
22 | - |
|
23 | - private static $singular_name = 'Event Page'; |
|
24 | - |
|
25 | - private static $plural_name = 'Event Pages'; |
|
26 | - |
|
27 | - private static $db = [ |
|
28 | - 'StartTime' => 'Time', |
|
29 | - 'EndTime' => 'Time', |
|
30 | - 'Location' => 'Text', |
|
31 | - ]; |
|
32 | - |
|
33 | - private static $table_name = 'EventPage'; |
|
34 | - |
|
35 | - public function fieldLabels($includerelations = true) |
|
36 | - { |
|
37 | - $labels = parent::fieldLabels($includerelations); |
|
38 | - $labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time'); |
|
39 | - $labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time'); |
|
40 | - $labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location'); |
|
41 | - |
|
42 | - return $labels; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Add the default for the Date being the current day. |
|
47 | - */ |
|
48 | - public function populateDefaults() |
|
49 | - { |
|
50 | - if (!isset($this->Date) || $this->Date === null) { |
|
51 | - $this->Date = DBDatetime::now()->Format('y-MM-dd'); |
|
52 | - } |
|
53 | - |
|
54 | - if (!isset($this->StartTime) || $this->StartTime === null) { |
|
55 | - $this->StartTime = '09:00:00'; |
|
56 | - } |
|
57 | - |
|
58 | - if (!isset($this->EndTime) || $this->EndTime === null) { |
|
59 | - $this->EndTime = '17:00:00'; |
|
60 | - } |
|
61 | - |
|
62 | - parent::populateDefaults(); |
|
63 | - } |
|
64 | - |
|
65 | - public function getCMSFields() |
|
66 | - { |
|
67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
68 | - $fields->removeByName('Date'); |
|
69 | - |
|
70 | - $dateTimeFields = array(); |
|
71 | - |
|
72 | - $dateTimeFields[] = $dateField = DateField::create('Date', 'Date'); |
|
73 | - $dateTimeFields[] = $startTimeField = TimeField::create( |
|
74 | - 'StartTime', |
|
75 | - $this->fieldLabel('StartTime') |
|
76 | - ); |
|
77 | - $dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime')); |
|
78 | - |
|
79 | - $fields->addFieldsToTab('Root.Main', [ |
|
80 | - $dateTimeField = FieldGroup::create('Date and time', $dateTimeFields), |
|
81 | - $locationField = TextareaField::create('Location', $this->fieldLabel('Location')) |
|
82 | - ], 'Abstract'); |
|
83 | - $locationField->setRows(4); |
|
84 | - }); |
|
85 | - return parent::getCMSFields(); |
|
86 | - } |
|
87 | - |
|
88 | - public function NiceLocation() |
|
89 | - { |
|
90 | - return nl2br(Convert::raw2xml($this->Location), true); |
|
91 | - } |
|
15 | + private static $description = 'Describes an event occurring on a specific date.'; |
|
16 | + |
|
17 | + private static $default_parent = EventHolder::class; |
|
18 | + |
|
19 | + private static $can_be_root = false; |
|
20 | + |
|
21 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/event_page.png'; |
|
22 | + |
|
23 | + private static $singular_name = 'Event Page'; |
|
24 | + |
|
25 | + private static $plural_name = 'Event Pages'; |
|
26 | + |
|
27 | + private static $db = [ |
|
28 | + 'StartTime' => 'Time', |
|
29 | + 'EndTime' => 'Time', |
|
30 | + 'Location' => 'Text', |
|
31 | + ]; |
|
32 | + |
|
33 | + private static $table_name = 'EventPage'; |
|
34 | + |
|
35 | + public function fieldLabels($includerelations = true) |
|
36 | + { |
|
37 | + $labels = parent::fieldLabels($includerelations); |
|
38 | + $labels['StartTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.StartTimeFieldLabel', 'Start Time'); |
|
39 | + $labels['EndTime'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.EndTimeFieldLabel', 'End Time'); |
|
40 | + $labels['Location'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.LocationFieldLabel', 'Location'); |
|
41 | + |
|
42 | + return $labels; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Add the default for the Date being the current day. |
|
47 | + */ |
|
48 | + public function populateDefaults() |
|
49 | + { |
|
50 | + if (!isset($this->Date) || $this->Date === null) { |
|
51 | + $this->Date = DBDatetime::now()->Format('y-MM-dd'); |
|
52 | + } |
|
53 | + |
|
54 | + if (!isset($this->StartTime) || $this->StartTime === null) { |
|
55 | + $this->StartTime = '09:00:00'; |
|
56 | + } |
|
57 | + |
|
58 | + if (!isset($this->EndTime) || $this->EndTime === null) { |
|
59 | + $this->EndTime = '17:00:00'; |
|
60 | + } |
|
61 | + |
|
62 | + parent::populateDefaults(); |
|
63 | + } |
|
64 | + |
|
65 | + public function getCMSFields() |
|
66 | + { |
|
67 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
68 | + $fields->removeByName('Date'); |
|
69 | + |
|
70 | + $dateTimeFields = array(); |
|
71 | + |
|
72 | + $dateTimeFields[] = $dateField = DateField::create('Date', 'Date'); |
|
73 | + $dateTimeFields[] = $startTimeField = TimeField::create( |
|
74 | + 'StartTime', |
|
75 | + $this->fieldLabel('StartTime') |
|
76 | + ); |
|
77 | + $dateTimeFields[] = $endTimeField = TimeField::create('EndTime', $this->fieldLabel('EndTime')); |
|
78 | + |
|
79 | + $fields->addFieldsToTab('Root.Main', [ |
|
80 | + $dateTimeField = FieldGroup::create('Date and time', $dateTimeFields), |
|
81 | + $locationField = TextareaField::create('Location', $this->fieldLabel('Location')) |
|
82 | + ], 'Abstract'); |
|
83 | + $locationField->setRows(4); |
|
84 | + }); |
|
85 | + return parent::getCMSFields(); |
|
86 | + } |
|
87 | + |
|
88 | + public function NiceLocation() |
|
89 | + { |
|
90 | + return nl2br(Convert::raw2xml($this->Location), true); |
|
91 | + } |
|
92 | 92 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | |
46 | 46 | public function getCMSFields() |
47 | 47 | { |
48 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
48 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
49 | 49 | $fields->addFieldToTab( |
50 | 50 | 'Root.Main', |
51 | 51 | TextField::create('Author', $this->fieldLabel('Author')), |
@@ -9,59 +9,59 @@ |
||
9 | 9 | |
10 | 10 | class NewsPage extends DatedUpdatePage |
11 | 11 | { |
12 | - private static $description = 'Describes an item of news'; |
|
12 | + private static $description = 'Describes an item of news'; |
|
13 | 13 | |
14 | - private static $default_parent = 'NewsHolderPage'; |
|
14 | + private static $default_parent = 'NewsHolderPage'; |
|
15 | 15 | |
16 | - private static $can_be_root = false; |
|
16 | + private static $can_be_root = false; |
|
17 | 17 | |
18 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png'; |
|
18 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/news.png'; |
|
19 | 19 | |
20 | - private static $singular_name = 'News Page'; |
|
20 | + private static $singular_name = 'News Page'; |
|
21 | 21 | |
22 | - private static $plural_name = 'News Pages'; |
|
22 | + private static $plural_name = 'News Pages'; |
|
23 | 23 | |
24 | - private static $db = [ |
|
25 | - 'Author' => 'Varchar(255)', |
|
26 | - ]; |
|
24 | + private static $db = [ |
|
25 | + 'Author' => 'Varchar(255)', |
|
26 | + ]; |
|
27 | 27 | |
28 | - private static $has_one = [ |
|
29 | - 'FeaturedImage' => Image::class, |
|
30 | - ]; |
|
28 | + private static $has_one = [ |
|
29 | + 'FeaturedImage' => Image::class, |
|
30 | + ]; |
|
31 | 31 | |
32 | - private static $owns = [ |
|
33 | - 'FeaturedImage', |
|
34 | - ]; |
|
32 | + private static $owns = [ |
|
33 | + 'FeaturedImage', |
|
34 | + ]; |
|
35 | 35 | |
36 | - private static $table_name = 'NewsPage'; |
|
36 | + private static $table_name = 'NewsPage'; |
|
37 | 37 | |
38 | - public function fieldLabels($includerelations = true) |
|
39 | - { |
|
40 | - $labels = parent::fieldLabels($includerelations); |
|
41 | - $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
42 | - $labels['FeaturedImageID'] = _t( |
|
43 | - 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
44 | - 'Featured Image' |
|
45 | - ); |
|
38 | + public function fieldLabels($includerelations = true) |
|
39 | + { |
|
40 | + $labels = parent::fieldLabels($includerelations); |
|
41 | + $labels['Author'] = _t('CWP\\CWP\\PageTypes\\DateUpdatePage.AuthorFieldLabel', 'Author'); |
|
42 | + $labels['FeaturedImageID'] = _t( |
|
43 | + 'CWP\\CWP\\PageTypes\\DateUpdatePage.FeaturedImageFieldLabel', |
|
44 | + 'Featured Image' |
|
45 | + ); |
|
46 | 46 | |
47 | - return $labels; |
|
48 | - } |
|
47 | + return $labels; |
|
48 | + } |
|
49 | 49 | |
50 | - public function getCMSFields() |
|
51 | - { |
|
52 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
53 | - $fields->addFieldToTab( |
|
54 | - 'Root.Main', |
|
55 | - TextField::create('Author', $this->fieldLabel('Author')), |
|
56 | - 'Abstract' |
|
57 | - ); |
|
50 | + public function getCMSFields() |
|
51 | + { |
|
52 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
53 | + $fields->addFieldToTab( |
|
54 | + 'Root.Main', |
|
55 | + TextField::create('Author', $this->fieldLabel('Author')), |
|
56 | + 'Abstract' |
|
57 | + ); |
|
58 | 58 | |
59 | - $fields->addFieldToTab( |
|
60 | - 'Root.Main', |
|
61 | - UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
62 | - 'Abstract' |
|
63 | - ); |
|
64 | - }); |
|
65 | - return parent::getCMSFields(); |
|
66 | - } |
|
59 | + $fields->addFieldToTab( |
|
60 | + 'Root.Main', |
|
61 | + UploadField::create('FeaturedImage', $this->fieldLabel('FeaturedImageID')), |
|
62 | + 'Abstract' |
|
63 | + ); |
|
64 | + }); |
|
65 | + return parent::getCMSFields(); |
|
66 | + } |
|
67 | 67 | } |
@@ -19,53 +19,53 @@ |
||
19 | 19 | */ |
20 | 20 | class EventHolderController extends DatedUpdateHolderController |
21 | 21 | { |
22 | - public function getUpdateName() |
|
23 | - { |
|
24 | - $params = $this->parseParams(); |
|
25 | - if ($params['upcomingOnly']) { |
|
26 | - return _t(__CLASS__ . '.Upcoming', 'Upcoming events'); |
|
27 | - } |
|
22 | + public function getUpdateName() |
|
23 | + { |
|
24 | + $params = $this->parseParams(); |
|
25 | + if ($params['upcomingOnly']) { |
|
26 | + return _t(__CLASS__ . '.Upcoming', 'Upcoming events'); |
|
27 | + } |
|
28 | 28 | |
29 | - return _t(__CLASS__ . '.Events', 'Events'); |
|
30 | - } |
|
29 | + return _t(__CLASS__ . '.Events', 'Events'); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Parse URL parameters. |
|
34 | - * |
|
35 | - * @param boolean $produceErrorMessages Set to false to omit session messages. |
|
36 | - */ |
|
37 | - public function parseParams($produceErrorMessages = true) |
|
38 | - { |
|
39 | - $params = parent::parseParams($produceErrorMessages); |
|
32 | + /** |
|
33 | + * Parse URL parameters. |
|
34 | + * |
|
35 | + * @param boolean $produceErrorMessages Set to false to omit session messages. |
|
36 | + */ |
|
37 | + public function parseParams($produceErrorMessages = true) |
|
38 | + { |
|
39 | + $params = parent::parseParams($produceErrorMessages); |
|
40 | 40 | |
41 | - // We need to set whether or not we're supposed to be displaying only upcoming events or all events. |
|
42 | - $params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']); |
|
41 | + // We need to set whether or not we're supposed to be displaying only upcoming events or all events. |
|
42 | + $params['upcomingOnly'] = !($params['from'] || $params['to'] || $params['year'] || $params['month']); |
|
43 | 43 | |
44 | - return $params; |
|
45 | - } |
|
44 | + return $params; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get the events based on the current query. |
|
49 | - */ |
|
50 | - public function FilteredUpdates($pageSize = 20) |
|
51 | - { |
|
52 | - $params = $this->parseParams(); |
|
47 | + /** |
|
48 | + * Get the events based on the current query. |
|
49 | + */ |
|
50 | + public function FilteredUpdates($pageSize = 20) |
|
51 | + { |
|
52 | + $params = $this->parseParams(); |
|
53 | 53 | |
54 | - $items = $this->Updates( |
|
55 | - $params['tag'], |
|
56 | - $params['from'], |
|
57 | - $params['to'], |
|
58 | - $params['year'], |
|
59 | - $params['month'] |
|
60 | - ); |
|
54 | + $items = $this->Updates( |
|
55 | + $params['tag'], |
|
56 | + $params['from'], |
|
57 | + $params['to'], |
|
58 | + $params['year'], |
|
59 | + $params['month'] |
|
60 | + ); |
|
61 | 61 | |
62 | - if ($params['upcomingOnly']) { |
|
63 | - $items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]); |
|
64 | - } |
|
62 | + if ($params['upcomingOnly']) { |
|
63 | + $items = $items->filter(['Date:LessThan:Not' => DBDatetime::now()->Format('y-MM-dd')]); |
|
64 | + } |
|
65 | 65 | |
66 | - // Apply pagination |
|
67 | - $list = PaginatedList::create($items, $this->getRequest()); |
|
68 | - $list->setPageLength($pageSize); |
|
69 | - return $list; |
|
70 | - } |
|
66 | + // Apply pagination |
|
67 | + $list = PaginatedList::create($items, $this->getRequest()); |
|
68 | + $list->setPageLength($pageSize); |
|
69 | + return $list; |
|
70 | + } |
|
71 | 71 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | } |
160 | 160 | |
161 | 161 | if (isset($tag)) { |
162 | - $tag = (int)$tag; |
|
162 | + $tag = (int) $tag; |
|
163 | 163 | } |
164 | 164 | if (isset($from)) { |
165 | 165 | $from = urldecode($from); |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | $to = $parser->Format('y-MM-dd'); |
175 | 175 | } |
176 | 176 | if (isset($year)) { |
177 | - $year = (int)$year; |
|
177 | + $year = (int) $year; |
|
178 | 178 | } |
179 | 179 | if (isset($month)) { |
180 | - $month = (int)$month; |
|
180 | + $month = (int) $month; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | $tagID = $this->request->getVar('tag'); |
260 | 260 | |
261 | 261 | if (isset($tagID)) { |
262 | - return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
262 | + return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int) $tagID); |
|
263 | 263 | } |
264 | 264 | } |
265 | 265 |
@@ -34,361 +34,361 @@ |
||
34 | 34 | */ |
35 | 35 | class DatedUpdateHolderController extends PageController |
36 | 36 | { |
37 | - private static $allowed_actions = [ |
|
38 | - 'rss', |
|
39 | - 'atom', |
|
40 | - 'DateRangeForm', |
|
41 | - ]; |
|
42 | - |
|
43 | - private static $casting = [ |
|
44 | - 'MetaTitle' => 'Text', |
|
45 | - 'FilterDescription' => 'Text', |
|
46 | - ]; |
|
47 | - |
|
48 | - /** |
|
49 | - * The session key for storing temporary form messages |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - const TEMP_FORM_MESSAGE = __CLASS__ . '.TempFormMessage'; |
|
54 | - |
|
55 | - /** |
|
56 | - * Get the meta title for the current action |
|
57 | - * |
|
58 | - * @return string |
|
59 | - */ |
|
60 | - public function getMetaTitle() |
|
61 | - { |
|
62 | - $title = $this->data()->getTitle(); |
|
63 | - $filter = $this->FilterDescription(); |
|
64 | - if ($filter) { |
|
65 | - $title = "{$title} - {$filter}"; |
|
66 | - } |
|
67 | - |
|
68 | - $this->extend('updateMetaTitle', $title); |
|
69 | - return $title; |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Returns a description of the current filter |
|
74 | - * |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function FilterDescription() |
|
78 | - { |
|
79 | - $params = $this->parseParams(); |
|
80 | - |
|
81 | - $filters = array(); |
|
82 | - if ($params['tag']) { |
|
83 | - $term = TaxonomyTerm::get_by_id(TaxonomyTerm::class, $params['tag']); |
|
84 | - if ($term) { |
|
85 | - $filters[] = _t( |
|
86 | - 'CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_WITHIN', |
|
87 | - 'within' |
|
88 | - ) . ' "' . $term->Name . '"'; |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - if ($params['from'] || $params['to']) { |
|
93 | - if ($params['from']) { |
|
94 | - $from = strtotime($params['from']); |
|
95 | - if ($params['to']) { |
|
96 | - $to = strtotime($params['to']); |
|
97 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_BETWEEN', 'between') . ' ' |
|
98 | - . date('j/m/Y', $from) . ' and ' . date('j/m/Y', $to); |
|
99 | - } else { |
|
100 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
101 | - . ' ' . date('j/m/Y', $from); |
|
102 | - } |
|
103 | - } else { |
|
104 | - $to = strtotime($params['to']); |
|
105 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
106 | - . ' ' . date('j/m/Y', $to); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - if ($params['year'] && $params['month']) { |
|
111 | - $timestamp = mktime(1, 1, 1, $params['month'], 1, $params['year']); |
|
112 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_IN', 'in') |
|
113 | - . ' ' . date('F', $timestamp) . ' ' . $params['year']; |
|
114 | - } |
|
115 | - |
|
116 | - if ($filters) { |
|
117 | - return $this->getUpdateName() . ' ' . implode(' ', $filters); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - public function getUpdateName() |
|
122 | - { |
|
123 | - return Config::inst()->get($this->data()->ClassName, 'update_name'); |
|
124 | - } |
|
125 | - |
|
126 | - protected function init() |
|
127 | - { |
|
128 | - parent::init(); |
|
129 | - RSSFeed::linkToFeed($this->Link() . 'rss', $this->getSubscriptionTitle()); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Parse URL parameters. |
|
134 | - * |
|
135 | - * @param bool $produceErrorMessages Set to false to omit session messages. |
|
136 | - */ |
|
137 | - public function parseParams($produceErrorMessages = true) |
|
138 | - { |
|
139 | - $tag = $this->request->getVar('tag'); |
|
140 | - $from = $this->request->getVar('from'); |
|
141 | - $to = $this->request->getVar('to'); |
|
142 | - $year = $this->request->getVar('year'); |
|
143 | - $month = $this->request->getVar('month'); |
|
144 | - |
|
145 | - if ($tag == '') { |
|
146 | - $tag = null; |
|
147 | - } |
|
148 | - if ($from == '') { |
|
149 | - $from = null; |
|
150 | - } |
|
151 | - if ($to == '') { |
|
152 | - $to = null; |
|
153 | - } |
|
154 | - if ($year == '') { |
|
155 | - $year = null; |
|
156 | - } |
|
157 | - if ($month == '') { |
|
158 | - $month = null; |
|
159 | - } |
|
160 | - |
|
161 | - if (isset($tag)) { |
|
162 | - $tag = (int)$tag; |
|
163 | - } |
|
164 | - if (isset($from)) { |
|
165 | - $from = urldecode($from); |
|
166 | - $parser = DBDatetime::create(); |
|
167 | - $parser->setValue($from); |
|
168 | - $from = $parser->Format('y-MM-dd'); |
|
169 | - } |
|
170 | - if (isset($to)) { |
|
171 | - $to = urldecode($to); |
|
172 | - $parser = DBDatetime::create(); |
|
173 | - $parser->setValue($to); |
|
174 | - $to = $parser->Format('y-MM-dd'); |
|
175 | - } |
|
176 | - if (isset($year)) { |
|
177 | - $year = (int)$year; |
|
178 | - } |
|
179 | - if (isset($month)) { |
|
180 | - $month = (int)$month; |
|
181 | - } |
|
182 | - |
|
183 | - // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
|
184 | - if (isset($to) && !isset($from)) { |
|
185 | - list($to, $from) = [$from, $to]; |
|
186 | - } |
|
187 | - |
|
188 | - // Flip the dates if the order is wrong. |
|
189 | - if (isset($to) && isset($from) && strtotime($from) > strtotime($to)) { |
|
190 | - list($to, $from) = [$from, $to]; |
|
191 | - |
|
192 | - if ($produceErrorMessages) { |
|
193 | - $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
194 | - __CLASS__ . '.FilterAppliedMessage', |
|
195 | - 'Filter has been applied with the dates reversed.' |
|
196 | - )); |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - // Notify the user that filtering by single date is taking place. |
|
201 | - if (isset($from) && !isset($to)) { |
|
202 | - if ($produceErrorMessages) { |
|
203 | - $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
204 | - __CLASS__ . '.DateRangeFilterMessage', |
|
205 | - 'Filtered by a single date.' |
|
206 | - )); |
|
207 | - } |
|
208 | - } |
|
209 | - |
|
210 | - return [ |
|
211 | - 'tag' => $tag, |
|
212 | - 'from' => $from, |
|
213 | - 'to' => $to, |
|
214 | - 'year' => $year, |
|
215 | - 'month' => $month, |
|
216 | - ]; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Build the link - keep the date range, reset the rest. |
|
221 | - */ |
|
222 | - public function AllTagsLink() |
|
223 | - { |
|
224 | - $link = HTTP::setGetVar('tag', null, null, '&'); |
|
225 | - $link = HTTP::setGetVar('month', null, $link, '&'); |
|
226 | - $link = HTTP::setGetVar('year', null, $link, '&'); |
|
227 | - $link = HTTP::setGetVar('start', null, $link, '&'); |
|
228 | - |
|
229 | - return $link; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * List tags and attach links. |
|
234 | - */ |
|
235 | - public function UpdateTagsWithLinks() |
|
236 | - { |
|
237 | - $tags = $this->UpdateTags(); |
|
238 | - |
|
239 | - $processed = ArrayList::create(); |
|
240 | - |
|
241 | - foreach ($tags as $tag) { |
|
242 | - // Build the link - keep the tag, and date range, but reset month, year and pagination. |
|
243 | - $link = HTTP::setGetVar('tag', $tag->ID, null, '&'); |
|
244 | - $link = HTTP::setGetVar('month', null, $link, '&'); |
|
245 | - $link = HTTP::setGetVar('year', null, $link, '&'); |
|
246 | - $link = HTTP::setGetVar('start', null, $link, '&'); |
|
247 | - |
|
248 | - $tag->Link = $link; |
|
249 | - $processed->push($tag); |
|
250 | - } |
|
251 | - |
|
252 | - return $processed; |
|
253 | - } |
|
254 | - |
|
255 | - /** |
|
256 | - * Get the TaxonomyTerm related to the current tag GET parameter. |
|
257 | - */ |
|
258 | - public function CurrentTag() |
|
259 | - { |
|
260 | - $tagID = $this->request->getVar('tag'); |
|
261 | - |
|
262 | - if (isset($tagID)) { |
|
263 | - return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Extract the available months based on the current query. |
|
269 | - * Only tag is respected. Pagination and months are ignored. |
|
270 | - */ |
|
271 | - public function AvailableMonths() |
|
272 | - { |
|
273 | - $params = $this->parseParams(); |
|
274 | - |
|
275 | - return DatedUpdateHolder::ExtractMonths( |
|
276 | - $this->Updates($params['tag'], $params['from'], $params['to']), |
|
277 | - Director::makeRelative($_SERVER['REQUEST_URI']), |
|
278 | - $params['year'], |
|
279 | - $params['month'] |
|
280 | - ); |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Get the updates based on the current query. |
|
285 | - */ |
|
286 | - public function FilteredUpdates($pageSize = 20) |
|
287 | - { |
|
288 | - $params = $this->parseParams(); |
|
289 | - |
|
290 | - $items = $this->Updates( |
|
291 | - $params['tag'], |
|
292 | - $params['from'], |
|
293 | - $params['to'], |
|
294 | - $params['year'], |
|
295 | - $params['month'] |
|
296 | - ); |
|
297 | - |
|
298 | - // Apply pagination |
|
299 | - $list = PaginatedList::create($items, $this->getRequest()); |
|
300 | - $list->setPageLength($pageSize); |
|
301 | - return $list; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @return Form |
|
306 | - */ |
|
307 | - public function DateRangeForm() |
|
308 | - { |
|
309 | - $dateFromTitle = DBField::create_field('HTMLText', sprintf( |
|
310 | - '%s <span class="field-note">%s</span>', |
|
311 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FROM_DATE', 'From date'), |
|
312 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
313 | - )); |
|
314 | - $dateToTitle = DBField::create_field('HTMLText', sprintf( |
|
315 | - '%s <span class="field-note">%s</span>', |
|
316 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.TO_DATE', 'To date'), |
|
317 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
318 | - )); |
|
319 | - |
|
320 | - $fields = FieldList::create( |
|
321 | - DateField::create('from', $dateFromTitle), |
|
322 | - DateField::create('to', $dateToTitle), |
|
323 | - HiddenField::create('tag') |
|
324 | - ); |
|
325 | - |
|
326 | - $actions = FieldList::create( |
|
327 | - FormAction::create("doDateFilter") |
|
328 | - ->setTitle(_t(__CLASS__ . '.Filter', 'Filter')) |
|
329 | - ->addExtraClass('btn btn-primary primary'), |
|
330 | - FormAction::create("doDateReset") |
|
331 | - ->setTitle(_t(__CLASS__ . '.Clear', 'Clear')) |
|
332 | - ->addExtraClass('btn') |
|
333 | - ); |
|
334 | - |
|
335 | - $form = Form::create($this, 'DateRangeForm', $fields, $actions); |
|
336 | - $form->loadDataFrom($this->request->getVars()); |
|
337 | - $form->setFormMethod('get'); |
|
338 | - |
|
339 | - // Add any locally stored form messages before returning |
|
340 | - if ($formMessage = $this->getRequest()->getSession()->get(self::TEMP_FORM_MESSAGE)) { |
|
341 | - $form->setMessage($formMessage, ValidationResult::TYPE_WARNING); |
|
342 | - $this->getRequest()->getSession()->clear(self::TEMP_FORM_MESSAGE); |
|
343 | - } |
|
344 | - |
|
345 | - return $form; |
|
346 | - } |
|
347 | - |
|
348 | - public function doDateFilter() |
|
349 | - { |
|
350 | - $params = $this->parseParams(); |
|
351 | - |
|
352 | - // Build the link - keep the tag, but reset month, year and pagination. |
|
353 | - $link = HTTP::setGetVar('from', $params['from'], $this->AbsoluteLink(), '&'); |
|
354 | - $link = HTTP::setGetVar('to', $params['to'], $link, '&'); |
|
355 | - if (isset($params['tag'])) { |
|
356 | - $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
357 | - } |
|
358 | - |
|
359 | - $this->redirect($link); |
|
360 | - } |
|
361 | - |
|
362 | - public function doDateReset() |
|
363 | - { |
|
364 | - $params = $this->parseParams(false); |
|
365 | - |
|
366 | - // Reset the link - only include the tag. |
|
367 | - $link = $this->AbsoluteLink(); |
|
368 | - if (isset($params['tag'])) { |
|
369 | - $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
370 | - } |
|
371 | - |
|
372 | - $this->redirect($link); |
|
373 | - } |
|
374 | - |
|
375 | - public function rss() |
|
376 | - { |
|
377 | - $rss = RSSFeed::create( |
|
378 | - $this->Updates()->sort('Created DESC')->limit(20), |
|
379 | - $this->Link('rss'), |
|
380 | - $this->getSubscriptionTitle() |
|
381 | - ); |
|
382 | - return $rss->outputToBrowser(); |
|
383 | - } |
|
384 | - |
|
385 | - public function atom() |
|
386 | - { |
|
387 | - $atom = CwpAtomFeed::create( |
|
388 | - $this->Updates()->sort('Created DESC')->limit(20), |
|
389 | - $this->Link('atom'), |
|
390 | - $this->getSubscriptionTitle() |
|
391 | - ); |
|
392 | - return $atom->outputToBrowser(); |
|
393 | - } |
|
37 | + private static $allowed_actions = [ |
|
38 | + 'rss', |
|
39 | + 'atom', |
|
40 | + 'DateRangeForm', |
|
41 | + ]; |
|
42 | + |
|
43 | + private static $casting = [ |
|
44 | + 'MetaTitle' => 'Text', |
|
45 | + 'FilterDescription' => 'Text', |
|
46 | + ]; |
|
47 | + |
|
48 | + /** |
|
49 | + * The session key for storing temporary form messages |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + const TEMP_FORM_MESSAGE = __CLASS__ . '.TempFormMessage'; |
|
54 | + |
|
55 | + /** |
|
56 | + * Get the meta title for the current action |
|
57 | + * |
|
58 | + * @return string |
|
59 | + */ |
|
60 | + public function getMetaTitle() |
|
61 | + { |
|
62 | + $title = $this->data()->getTitle(); |
|
63 | + $filter = $this->FilterDescription(); |
|
64 | + if ($filter) { |
|
65 | + $title = "{$title} - {$filter}"; |
|
66 | + } |
|
67 | + |
|
68 | + $this->extend('updateMetaTitle', $title); |
|
69 | + return $title; |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Returns a description of the current filter |
|
74 | + * |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function FilterDescription() |
|
78 | + { |
|
79 | + $params = $this->parseParams(); |
|
80 | + |
|
81 | + $filters = array(); |
|
82 | + if ($params['tag']) { |
|
83 | + $term = TaxonomyTerm::get_by_id(TaxonomyTerm::class, $params['tag']); |
|
84 | + if ($term) { |
|
85 | + $filters[] = _t( |
|
86 | + 'CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_WITHIN', |
|
87 | + 'within' |
|
88 | + ) . ' "' . $term->Name . '"'; |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + if ($params['from'] || $params['to']) { |
|
93 | + if ($params['from']) { |
|
94 | + $from = strtotime($params['from']); |
|
95 | + if ($params['to']) { |
|
96 | + $to = strtotime($params['to']); |
|
97 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_BETWEEN', 'between') . ' ' |
|
98 | + . date('j/m/Y', $from) . ' and ' . date('j/m/Y', $to); |
|
99 | + } else { |
|
100 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
101 | + . ' ' . date('j/m/Y', $from); |
|
102 | + } |
|
103 | + } else { |
|
104 | + $to = strtotime($params['to']); |
|
105 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
106 | + . ' ' . date('j/m/Y', $to); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + if ($params['year'] && $params['month']) { |
|
111 | + $timestamp = mktime(1, 1, 1, $params['month'], 1, $params['year']); |
|
112 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_IN', 'in') |
|
113 | + . ' ' . date('F', $timestamp) . ' ' . $params['year']; |
|
114 | + } |
|
115 | + |
|
116 | + if ($filters) { |
|
117 | + return $this->getUpdateName() . ' ' . implode(' ', $filters); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + public function getUpdateName() |
|
122 | + { |
|
123 | + return Config::inst()->get($this->data()->ClassName, 'update_name'); |
|
124 | + } |
|
125 | + |
|
126 | + protected function init() |
|
127 | + { |
|
128 | + parent::init(); |
|
129 | + RSSFeed::linkToFeed($this->Link() . 'rss', $this->getSubscriptionTitle()); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Parse URL parameters. |
|
134 | + * |
|
135 | + * @param bool $produceErrorMessages Set to false to omit session messages. |
|
136 | + */ |
|
137 | + public function parseParams($produceErrorMessages = true) |
|
138 | + { |
|
139 | + $tag = $this->request->getVar('tag'); |
|
140 | + $from = $this->request->getVar('from'); |
|
141 | + $to = $this->request->getVar('to'); |
|
142 | + $year = $this->request->getVar('year'); |
|
143 | + $month = $this->request->getVar('month'); |
|
144 | + |
|
145 | + if ($tag == '') { |
|
146 | + $tag = null; |
|
147 | + } |
|
148 | + if ($from == '') { |
|
149 | + $from = null; |
|
150 | + } |
|
151 | + if ($to == '') { |
|
152 | + $to = null; |
|
153 | + } |
|
154 | + if ($year == '') { |
|
155 | + $year = null; |
|
156 | + } |
|
157 | + if ($month == '') { |
|
158 | + $month = null; |
|
159 | + } |
|
160 | + |
|
161 | + if (isset($tag)) { |
|
162 | + $tag = (int)$tag; |
|
163 | + } |
|
164 | + if (isset($from)) { |
|
165 | + $from = urldecode($from); |
|
166 | + $parser = DBDatetime::create(); |
|
167 | + $parser->setValue($from); |
|
168 | + $from = $parser->Format('y-MM-dd'); |
|
169 | + } |
|
170 | + if (isset($to)) { |
|
171 | + $to = urldecode($to); |
|
172 | + $parser = DBDatetime::create(); |
|
173 | + $parser->setValue($to); |
|
174 | + $to = $parser->Format('y-MM-dd'); |
|
175 | + } |
|
176 | + if (isset($year)) { |
|
177 | + $year = (int)$year; |
|
178 | + } |
|
179 | + if (isset($month)) { |
|
180 | + $month = (int)$month; |
|
181 | + } |
|
182 | + |
|
183 | + // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
|
184 | + if (isset($to) && !isset($from)) { |
|
185 | + list($to, $from) = [$from, $to]; |
|
186 | + } |
|
187 | + |
|
188 | + // Flip the dates if the order is wrong. |
|
189 | + if (isset($to) && isset($from) && strtotime($from) > strtotime($to)) { |
|
190 | + list($to, $from) = [$from, $to]; |
|
191 | + |
|
192 | + if ($produceErrorMessages) { |
|
193 | + $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
194 | + __CLASS__ . '.FilterAppliedMessage', |
|
195 | + 'Filter has been applied with the dates reversed.' |
|
196 | + )); |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + // Notify the user that filtering by single date is taking place. |
|
201 | + if (isset($from) && !isset($to)) { |
|
202 | + if ($produceErrorMessages) { |
|
203 | + $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
204 | + __CLASS__ . '.DateRangeFilterMessage', |
|
205 | + 'Filtered by a single date.' |
|
206 | + )); |
|
207 | + } |
|
208 | + } |
|
209 | + |
|
210 | + return [ |
|
211 | + 'tag' => $tag, |
|
212 | + 'from' => $from, |
|
213 | + 'to' => $to, |
|
214 | + 'year' => $year, |
|
215 | + 'month' => $month, |
|
216 | + ]; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Build the link - keep the date range, reset the rest. |
|
221 | + */ |
|
222 | + public function AllTagsLink() |
|
223 | + { |
|
224 | + $link = HTTP::setGetVar('tag', null, null, '&'); |
|
225 | + $link = HTTP::setGetVar('month', null, $link, '&'); |
|
226 | + $link = HTTP::setGetVar('year', null, $link, '&'); |
|
227 | + $link = HTTP::setGetVar('start', null, $link, '&'); |
|
228 | + |
|
229 | + return $link; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * List tags and attach links. |
|
234 | + */ |
|
235 | + public function UpdateTagsWithLinks() |
|
236 | + { |
|
237 | + $tags = $this->UpdateTags(); |
|
238 | + |
|
239 | + $processed = ArrayList::create(); |
|
240 | + |
|
241 | + foreach ($tags as $tag) { |
|
242 | + // Build the link - keep the tag, and date range, but reset month, year and pagination. |
|
243 | + $link = HTTP::setGetVar('tag', $tag->ID, null, '&'); |
|
244 | + $link = HTTP::setGetVar('month', null, $link, '&'); |
|
245 | + $link = HTTP::setGetVar('year', null, $link, '&'); |
|
246 | + $link = HTTP::setGetVar('start', null, $link, '&'); |
|
247 | + |
|
248 | + $tag->Link = $link; |
|
249 | + $processed->push($tag); |
|
250 | + } |
|
251 | + |
|
252 | + return $processed; |
|
253 | + } |
|
254 | + |
|
255 | + /** |
|
256 | + * Get the TaxonomyTerm related to the current tag GET parameter. |
|
257 | + */ |
|
258 | + public function CurrentTag() |
|
259 | + { |
|
260 | + $tagID = $this->request->getVar('tag'); |
|
261 | + |
|
262 | + if (isset($tagID)) { |
|
263 | + return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Extract the available months based on the current query. |
|
269 | + * Only tag is respected. Pagination and months are ignored. |
|
270 | + */ |
|
271 | + public function AvailableMonths() |
|
272 | + { |
|
273 | + $params = $this->parseParams(); |
|
274 | + |
|
275 | + return DatedUpdateHolder::ExtractMonths( |
|
276 | + $this->Updates($params['tag'], $params['from'], $params['to']), |
|
277 | + Director::makeRelative($_SERVER['REQUEST_URI']), |
|
278 | + $params['year'], |
|
279 | + $params['month'] |
|
280 | + ); |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Get the updates based on the current query. |
|
285 | + */ |
|
286 | + public function FilteredUpdates($pageSize = 20) |
|
287 | + { |
|
288 | + $params = $this->parseParams(); |
|
289 | + |
|
290 | + $items = $this->Updates( |
|
291 | + $params['tag'], |
|
292 | + $params['from'], |
|
293 | + $params['to'], |
|
294 | + $params['year'], |
|
295 | + $params['month'] |
|
296 | + ); |
|
297 | + |
|
298 | + // Apply pagination |
|
299 | + $list = PaginatedList::create($items, $this->getRequest()); |
|
300 | + $list->setPageLength($pageSize); |
|
301 | + return $list; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @return Form |
|
306 | + */ |
|
307 | + public function DateRangeForm() |
|
308 | + { |
|
309 | + $dateFromTitle = DBField::create_field('HTMLText', sprintf( |
|
310 | + '%s <span class="field-note">%s</span>', |
|
311 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FROM_DATE', 'From date'), |
|
312 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
313 | + )); |
|
314 | + $dateToTitle = DBField::create_field('HTMLText', sprintf( |
|
315 | + '%s <span class="field-note">%s</span>', |
|
316 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.TO_DATE', 'To date'), |
|
317 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
318 | + )); |
|
319 | + |
|
320 | + $fields = FieldList::create( |
|
321 | + DateField::create('from', $dateFromTitle), |
|
322 | + DateField::create('to', $dateToTitle), |
|
323 | + HiddenField::create('tag') |
|
324 | + ); |
|
325 | + |
|
326 | + $actions = FieldList::create( |
|
327 | + FormAction::create("doDateFilter") |
|
328 | + ->setTitle(_t(__CLASS__ . '.Filter', 'Filter')) |
|
329 | + ->addExtraClass('btn btn-primary primary'), |
|
330 | + FormAction::create("doDateReset") |
|
331 | + ->setTitle(_t(__CLASS__ . '.Clear', 'Clear')) |
|
332 | + ->addExtraClass('btn') |
|
333 | + ); |
|
334 | + |
|
335 | + $form = Form::create($this, 'DateRangeForm', $fields, $actions); |
|
336 | + $form->loadDataFrom($this->request->getVars()); |
|
337 | + $form->setFormMethod('get'); |
|
338 | + |
|
339 | + // Add any locally stored form messages before returning |
|
340 | + if ($formMessage = $this->getRequest()->getSession()->get(self::TEMP_FORM_MESSAGE)) { |
|
341 | + $form->setMessage($formMessage, ValidationResult::TYPE_WARNING); |
|
342 | + $this->getRequest()->getSession()->clear(self::TEMP_FORM_MESSAGE); |
|
343 | + } |
|
344 | + |
|
345 | + return $form; |
|
346 | + } |
|
347 | + |
|
348 | + public function doDateFilter() |
|
349 | + { |
|
350 | + $params = $this->parseParams(); |
|
351 | + |
|
352 | + // Build the link - keep the tag, but reset month, year and pagination. |
|
353 | + $link = HTTP::setGetVar('from', $params['from'], $this->AbsoluteLink(), '&'); |
|
354 | + $link = HTTP::setGetVar('to', $params['to'], $link, '&'); |
|
355 | + if (isset($params['tag'])) { |
|
356 | + $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
357 | + } |
|
358 | + |
|
359 | + $this->redirect($link); |
|
360 | + } |
|
361 | + |
|
362 | + public function doDateReset() |
|
363 | + { |
|
364 | + $params = $this->parseParams(false); |
|
365 | + |
|
366 | + // Reset the link - only include the tag. |
|
367 | + $link = $this->AbsoluteLink(); |
|
368 | + if (isset($params['tag'])) { |
|
369 | + $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
370 | + } |
|
371 | + |
|
372 | + $this->redirect($link); |
|
373 | + } |
|
374 | + |
|
375 | + public function rss() |
|
376 | + { |
|
377 | + $rss = RSSFeed::create( |
|
378 | + $this->Updates()->sort('Created DESC')->limit(20), |
|
379 | + $this->Link('rss'), |
|
380 | + $this->getSubscriptionTitle() |
|
381 | + ); |
|
382 | + return $rss->outputToBrowser(); |
|
383 | + } |
|
384 | + |
|
385 | + public function atom() |
|
386 | + { |
|
387 | + $atom = CwpAtomFeed::create( |
|
388 | + $this->Updates()->sort('Created DESC')->limit(20), |
|
389 | + $this->Link('atom'), |
|
390 | + $this->getSubscriptionTitle() |
|
391 | + ); |
|
392 | + return $atom->outputToBrowser(); |
|
393 | + } |
|
394 | 394 | } |
@@ -11,117 +11,117 @@ |
||
11 | 11 | |
12 | 12 | class Quicklink extends DataObject |
13 | 13 | { |
14 | - private static $db = [ |
|
15 | - 'Name' => 'Varchar(255)', |
|
16 | - 'ExternalLink' => 'Varchar(255)', |
|
17 | - 'SortOrder' => 'Int', |
|
18 | - ]; |
|
19 | - |
|
20 | - private static $has_one = [ |
|
21 | - 'Parent' => BaseHomePage::class, |
|
22 | - 'InternalLink' => SiteTree::class, |
|
23 | - ]; |
|
24 | - |
|
25 | - private static $summary_fields = [ |
|
26 | - 'Name' => 'Name', |
|
27 | - 'InternalLink.Title' => 'Internal Link', |
|
28 | - 'ExternalLink' => 'External Link', |
|
29 | - ]; |
|
30 | - |
|
31 | - private static $table_name = 'Quicklink'; |
|
32 | - |
|
33 | - public function fieldLabels($includerelations = true) |
|
34 | - { |
|
35 | - $labels = parent::fieldLabels($includerelations); |
|
36 | - $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
37 | - $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
38 | - $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
39 | - $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
40 | - $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
41 | - |
|
42 | - return $labels; |
|
43 | - } |
|
44 | - |
|
45 | - public function getLink() |
|
46 | - { |
|
47 | - if ($this->ExternalLink) { |
|
48 | - $url = parse_url($this->ExternalLink); |
|
49 | - |
|
50 | - // if no scheme set in the link, default to http |
|
51 | - if (!isset($url['scheme'])) { |
|
52 | - return 'http://' . $this->ExternalLink; |
|
53 | - } |
|
54 | - |
|
55 | - return $this->ExternalLink; |
|
56 | - } elseif ($this->InternalLinkID) { |
|
57 | - return $this->InternalLink()->Link(); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - public function canCreate($member = null, $context = []) |
|
62 | - { |
|
63 | - return $this->Parent()->canCreate($member, $context); |
|
64 | - } |
|
65 | - |
|
66 | - public function canEdit($member = null) |
|
67 | - { |
|
68 | - return $this->Parent()->canEdit($member); |
|
69 | - } |
|
70 | - |
|
71 | - public function canDelete($member = null) |
|
72 | - { |
|
73 | - return $this->Parent()->canDelete($member); |
|
74 | - } |
|
75 | - |
|
76 | - public function canView($member = null) |
|
77 | - { |
|
78 | - return $this->Parent()->canView($member); |
|
79 | - } |
|
80 | - |
|
81 | - public function getCMSFields() |
|
82 | - { |
|
83 | - $fields = parent::getCMSFields(); |
|
84 | - |
|
85 | - $fields->removeByName('ParentID'); |
|
86 | - |
|
87 | - $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
88 | - |
|
89 | - $fields->removeByName('ExternalLink'); |
|
90 | - $fields->removeByName('InternalLinkID'); |
|
91 | - $fields->removeByName('SortOrder'); |
|
92 | - $externalLinkField->addExtraClass('noBorder'); |
|
93 | - |
|
94 | - $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
95 | - array( |
|
96 | - TreeDropdownField::create( |
|
97 | - 'InternalLinkID', |
|
98 | - $this->fieldLabel('InternalLinkID'), |
|
99 | - SiteTree::class |
|
100 | - ), |
|
101 | - $externalLinkField, |
|
102 | - $wrap = CompositeField::create( |
|
103 | - $extraLabel = LiteralField::create( |
|
104 | - 'NoteOverride', |
|
105 | - sprintf('<div class="message good notice">%s</div>', _t( |
|
106 | - __CLASS__ . '.Note', |
|
107 | - 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
108 | - )) |
|
109 | - ) |
|
110 | - ) |
|
111 | - ) |
|
112 | - )); |
|
113 | - $fields->insertBefore( |
|
114 | - 'Name', |
|
115 | - LiteralField::create( |
|
116 | - 'Note', |
|
117 | - sprintf('<p>%s</p>', _t( |
|
118 | - __CLASS__ . '.Note2', |
|
119 | - 'Use this to specify a link to a page either on this site ' |
|
120 | - . '(Internal Link) or another site (External Link).' |
|
121 | - )) |
|
122 | - ) |
|
123 | - ); |
|
124 | - |
|
125 | - return $fields; |
|
126 | - } |
|
14 | + private static $db = [ |
|
15 | + 'Name' => 'Varchar(255)', |
|
16 | + 'ExternalLink' => 'Varchar(255)', |
|
17 | + 'SortOrder' => 'Int', |
|
18 | + ]; |
|
19 | + |
|
20 | + private static $has_one = [ |
|
21 | + 'Parent' => BaseHomePage::class, |
|
22 | + 'InternalLink' => SiteTree::class, |
|
23 | + ]; |
|
24 | + |
|
25 | + private static $summary_fields = [ |
|
26 | + 'Name' => 'Name', |
|
27 | + 'InternalLink.Title' => 'Internal Link', |
|
28 | + 'ExternalLink' => 'External Link', |
|
29 | + ]; |
|
30 | + |
|
31 | + private static $table_name = 'Quicklink'; |
|
32 | + |
|
33 | + public function fieldLabels($includerelations = true) |
|
34 | + { |
|
35 | + $labels = parent::fieldLabels($includerelations); |
|
36 | + $labels['Name'] = _t(__CLASS__ . '.NameLabel', 'Name'); |
|
37 | + $labels['ExternalLink'] = _t(__CLASS__ . '.ExternalLinkLabel', 'External Link'); |
|
38 | + $labels['SortOrder'] = _t(__CLASS__ . '.SortOrderLabel', 'Sort Order'); |
|
39 | + $labels['ParentID'] = _t(__CLASS__ . '.ParentRelationLabel', 'Parent'); |
|
40 | + $labels['InternalLinkID'] = _t(__CLASS__ . '.InternalLinkLabel', 'Internal Link'); |
|
41 | + |
|
42 | + return $labels; |
|
43 | + } |
|
44 | + |
|
45 | + public function getLink() |
|
46 | + { |
|
47 | + if ($this->ExternalLink) { |
|
48 | + $url = parse_url($this->ExternalLink); |
|
49 | + |
|
50 | + // if no scheme set in the link, default to http |
|
51 | + if (!isset($url['scheme'])) { |
|
52 | + return 'http://' . $this->ExternalLink; |
|
53 | + } |
|
54 | + |
|
55 | + return $this->ExternalLink; |
|
56 | + } elseif ($this->InternalLinkID) { |
|
57 | + return $this->InternalLink()->Link(); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + public function canCreate($member = null, $context = []) |
|
62 | + { |
|
63 | + return $this->Parent()->canCreate($member, $context); |
|
64 | + } |
|
65 | + |
|
66 | + public function canEdit($member = null) |
|
67 | + { |
|
68 | + return $this->Parent()->canEdit($member); |
|
69 | + } |
|
70 | + |
|
71 | + public function canDelete($member = null) |
|
72 | + { |
|
73 | + return $this->Parent()->canDelete($member); |
|
74 | + } |
|
75 | + |
|
76 | + public function canView($member = null) |
|
77 | + { |
|
78 | + return $this->Parent()->canView($member); |
|
79 | + } |
|
80 | + |
|
81 | + public function getCMSFields() |
|
82 | + { |
|
83 | + $fields = parent::getCMSFields(); |
|
84 | + |
|
85 | + $fields->removeByName('ParentID'); |
|
86 | + |
|
87 | + $externalLinkField = $fields->fieldByName('Root.Main.ExternalLink'); |
|
88 | + |
|
89 | + $fields->removeByName('ExternalLink'); |
|
90 | + $fields->removeByName('InternalLinkID'); |
|
91 | + $fields->removeByName('SortOrder'); |
|
92 | + $externalLinkField->addExtraClass('noBorder'); |
|
93 | + |
|
94 | + $fields->addFieldToTab('Root.Main', CompositeField::create( |
|
95 | + array( |
|
96 | + TreeDropdownField::create( |
|
97 | + 'InternalLinkID', |
|
98 | + $this->fieldLabel('InternalLinkID'), |
|
99 | + SiteTree::class |
|
100 | + ), |
|
101 | + $externalLinkField, |
|
102 | + $wrap = CompositeField::create( |
|
103 | + $extraLabel = LiteralField::create( |
|
104 | + 'NoteOverride', |
|
105 | + sprintf('<div class="message good notice">%s</div>', _t( |
|
106 | + __CLASS__ . '.Note', |
|
107 | + 'Note: If you specify an External Link, the Internal Link will be ignored.' |
|
108 | + )) |
|
109 | + ) |
|
110 | + ) |
|
111 | + ) |
|
112 | + )); |
|
113 | + $fields->insertBefore( |
|
114 | + 'Name', |
|
115 | + LiteralField::create( |
|
116 | + 'Note', |
|
117 | + sprintf('<p>%s</p>', _t( |
|
118 | + __CLASS__ . '.Note2', |
|
119 | + 'Use this to specify a link to a page either on this site ' |
|
120 | + . '(Internal Link) or another site (External Link).' |
|
121 | + )) |
|
122 | + ) |
|
123 | + ); |
|
124 | + |
|
125 | + return $fields; |
|
126 | + } |
|
127 | 127 | } |