@@ -28,240 +28,240 @@ |
||
| 28 | 28 | |
| 29 | 29 | class BasePage extends SiteTree |
| 30 | 30 | { |
| 31 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide" |
|
| 35 | - * |
|
| 36 | - * {@inheritDoc} |
|
| 37 | - */ |
|
| 38 | - private static $hide_ancestor = BasePage::class; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @config |
|
| 42 | - * @var bool |
|
| 43 | - */ |
|
| 44 | - private static $pdf_export = false; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Domain to generate PDF's from, DOES not include protocol |
|
| 48 | - * i.e. google.com not http://google.com |
|
| 49 | - * @config |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - private static $pdf_base_url = ""; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Allow custom overriding of the path to the WKHTMLTOPDF binary, in cases |
|
| 56 | - * where multiple versions of the binary are available to choose from. This |
|
| 57 | - * should be the full path to the binary (e.g. /usr/local/bin/wkhtmltopdf) |
|
| 58 | - * @see BasePage_Controller::generatePDF(); |
|
| 59 | - * |
|
| 60 | - * @config |
|
| 61 | - * @var string|null |
|
| 62 | - */ |
|
| 63 | - private static $wkhtmltopdf_binary = null; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Where to store generated PDF files |
|
| 67 | - * |
|
| 68 | - * @config |
|
| 69 | - * @var string |
|
| 70 | - */ |
|
| 71 | - private static $generated_pdf_path = 'assets/_generated_pdfs'; |
|
| 72 | - |
|
| 73 | - private static $api_access = [ |
|
| 74 | - 'view' => [ |
|
| 75 | - 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 76 | - 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 77 | - ], |
|
| 78 | - 'edit' => [ |
|
| 79 | - 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 80 | - 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 81 | - ], |
|
| 82 | - ]; |
|
| 83 | - |
|
| 84 | - private static $table_name = 'BasePage'; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @config |
|
| 88 | - * @var string |
|
| 89 | - */ |
|
| 90 | - private static $related_pages_title = 'Related pages'; |
|
| 91 | - |
|
| 92 | - private static $many_many = [ |
|
| 93 | - 'Terms' => TaxonomyTerm::class, |
|
| 94 | - 'RelatedPages' => BasePage::class, |
|
| 95 | - ]; |
|
| 96 | - |
|
| 97 | - private static $many_many_extraFields = [ |
|
| 98 | - 'RelatedPages' => [ |
|
| 99 | - 'SortOrder' => 'Int', |
|
| 100 | - ], |
|
| 101 | - ]; |
|
| 102 | - |
|
| 103 | - private static $plural_name = 'Base Pages'; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Get the footer holder. |
|
| 107 | - */ |
|
| 108 | - public function getFooter() |
|
| 109 | - { |
|
| 110 | - return FooterHolder::get_one(FooterHolder::class); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Return the full filename of the pdf file, including path & extension |
|
| 115 | - */ |
|
| 116 | - public function getPdfFilename() |
|
| 117 | - { |
|
| 118 | - $baseName = sprintf('%s-%s', $this->URLSegment, $this->ID); |
|
| 119 | - |
|
| 120 | - $folderPath = $this->config()->get('generated_pdf_path'); |
|
| 121 | - if ($folderPath[0] != '/') { |
|
| 122 | - $folderPath = BASE_PATH . '/' . $folderPath; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return sprintf('%s/%s.pdf', $folderPath, $baseName); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Build pdf link for template. |
|
| 130 | - */ |
|
| 131 | - public function PdfLink() |
|
| 132 | - { |
|
| 133 | - if (!$this->config()->get('pdf_export')) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $path = $this->getPdfFilename(); |
|
| 138 | - |
|
| 139 | - if ((Versioned::get_stage() === Versioned::LIVE) && file_exists($path)) { |
|
| 140 | - return Director::baseURL() . preg_replace('#^/#', '', Director::makeRelative($path)); |
|
| 141 | - } |
|
| 142 | - return $this->Link('downloadpdf'); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function RelatedPages() |
|
| 146 | - { |
|
| 147 | - return $this->getManyManyComponents('RelatedPages')->sort('SortOrder'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function RelatedPagesTitle() |
|
| 151 | - { |
|
| 152 | - return $this->config()->get('related_pages_title'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Remove linked pdf when publishing the page, |
|
| 157 | - * as it would be out of date. |
|
| 158 | - */ |
|
| 159 | - public function onAfterPublish() |
|
| 160 | - { |
|
| 161 | - $filepath = $this->getPdfFilename(); |
|
| 162 | - if (file_exists($filepath)) { |
|
| 163 | - unlink($filepath); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Remove linked pdf when unpublishing the page, |
|
| 169 | - * so it's no longer valid. |
|
| 170 | - * |
|
| 171 | - * @return boolean |
|
| 172 | - */ |
|
| 173 | - public function doUnpublish() |
|
| 174 | - { |
|
| 175 | - if (!parent::doUnpublish()) { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $filepath = $this->getPdfFilename(); |
|
| 180 | - if (file_exists($filepath)) { |
|
| 181 | - unlink($filepath); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return true; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - public function getCMSFields() |
|
| 188 | - { |
|
| 189 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 190 | - // Related Pages |
|
| 191 | - $components = GridFieldConfig_RelationEditor::create(); |
|
| 192 | - $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 193 | - $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 194 | - $components->removeComponentsByType(GridFieldFilterHeader::class); |
|
| 195 | - $components->addComponent(new GridFieldSortableRows('SortOrder')); |
|
| 196 | - |
|
| 197 | - /** @var GridFieldDataColumns $dataColumns */ |
|
| 198 | - $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 199 | - $dataColumns->setDisplayFields([ |
|
| 200 | - 'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'), |
|
| 201 | - 'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type') |
|
| 202 | - ]); |
|
| 203 | - |
|
| 204 | - $fields->findOrMakeTab( |
|
| 205 | - 'Root.RelatedPages', |
|
| 206 | - _t(__CLASS__ . '.RelatedPages', 'Related pages') |
|
| 207 | - ); |
|
| 208 | - $fields->addFieldToTab( |
|
| 209 | - 'Root.RelatedPages', |
|
| 210 | - GridField::create( |
|
| 211 | - 'RelatedPages', |
|
| 212 | - _t(__CLASS__ . '.RelatedPages', 'Related pages'), |
|
| 213 | - $this->RelatedPages(), |
|
| 214 | - $components |
|
| 215 | - ) |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc) |
|
| 219 | - $hasMany = $this->hasMany(); |
|
| 220 | - $manyMany = $this->manyMany(); |
|
| 221 | - if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) { |
|
| 222 | - $components = GridFieldConfig_RelationEditor::create(); |
|
| 223 | - $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 224 | - $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 225 | - |
|
| 226 | - /** @var GridFieldAddExistingAutocompleter $autoCompleter */ |
|
| 227 | - $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class); |
|
| 228 | - $autoCompleter->setResultsFormat('$Name ($TaxonomyName)'); |
|
| 229 | - |
|
| 230 | - /** @var GridFieldDataColumns $dataColumns */ |
|
| 231 | - $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 232 | - $dataColumns->setDisplayFields([ |
|
| 233 | - 'Name' => _t(__CLASS__ . '.Term', 'Term'), |
|
| 234 | - 'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy') |
|
| 235 | - ]); |
|
| 236 | - |
|
| 237 | - $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags')); |
|
| 238 | - $fields->addFieldToTab( |
|
| 239 | - 'Root.Tags', |
|
| 240 | - TreeMultiselectField::create( |
|
| 241 | - 'Terms', |
|
| 242 | - _t(__CLASS__ . '.Terms', 'Terms'), |
|
| 243 | - TaxonomyTerm::class |
|
| 244 | - )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms')) |
|
| 245 | - ); |
|
| 246 | - } |
|
| 247 | - }); |
|
| 248 | - return parent::getCMSFields(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Returns the native language name for the selected locale/language, empty string if Fluent is not available |
|
| 253 | - * |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - public function getSelectedLanguage() |
|
| 257 | - { |
|
| 258 | - if (!class_exists(Locale::class) || !$this->hasMethod('Locales')) { |
|
| 259 | - return ''; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** @var ArrayData $information */ |
|
| 263 | - $information = $this->LocaleInformation(FluentState::singleton()->getLocale()); |
|
| 264 | - |
|
| 265 | - return $information->LanguageNative; |
|
| 266 | - } |
|
| 31 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide" |
|
| 35 | + * |
|
| 36 | + * {@inheritDoc} |
|
| 37 | + */ |
|
| 38 | + private static $hide_ancestor = BasePage::class; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @config |
|
| 42 | + * @var bool |
|
| 43 | + */ |
|
| 44 | + private static $pdf_export = false; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Domain to generate PDF's from, DOES not include protocol |
|
| 48 | + * i.e. google.com not http://google.com |
|
| 49 | + * @config |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + private static $pdf_base_url = ""; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Allow custom overriding of the path to the WKHTMLTOPDF binary, in cases |
|
| 56 | + * where multiple versions of the binary are available to choose from. This |
|
| 57 | + * should be the full path to the binary (e.g. /usr/local/bin/wkhtmltopdf) |
|
| 58 | + * @see BasePage_Controller::generatePDF(); |
|
| 59 | + * |
|
| 60 | + * @config |
|
| 61 | + * @var string|null |
|
| 62 | + */ |
|
| 63 | + private static $wkhtmltopdf_binary = null; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Where to store generated PDF files |
|
| 67 | + * |
|
| 68 | + * @config |
|
| 69 | + * @var string |
|
| 70 | + */ |
|
| 71 | + private static $generated_pdf_path = 'assets/_generated_pdfs'; |
|
| 72 | + |
|
| 73 | + private static $api_access = [ |
|
| 74 | + 'view' => [ |
|
| 75 | + 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 76 | + 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 77 | + ], |
|
| 78 | + 'edit' => [ |
|
| 79 | + 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 80 | + 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 81 | + ], |
|
| 82 | + ]; |
|
| 83 | + |
|
| 84 | + private static $table_name = 'BasePage'; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @config |
|
| 88 | + * @var string |
|
| 89 | + */ |
|
| 90 | + private static $related_pages_title = 'Related pages'; |
|
| 91 | + |
|
| 92 | + private static $many_many = [ |
|
| 93 | + 'Terms' => TaxonomyTerm::class, |
|
| 94 | + 'RelatedPages' => BasePage::class, |
|
| 95 | + ]; |
|
| 96 | + |
|
| 97 | + private static $many_many_extraFields = [ |
|
| 98 | + 'RelatedPages' => [ |
|
| 99 | + 'SortOrder' => 'Int', |
|
| 100 | + ], |
|
| 101 | + ]; |
|
| 102 | + |
|
| 103 | + private static $plural_name = 'Base Pages'; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Get the footer holder. |
|
| 107 | + */ |
|
| 108 | + public function getFooter() |
|
| 109 | + { |
|
| 110 | + return FooterHolder::get_one(FooterHolder::class); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Return the full filename of the pdf file, including path & extension |
|
| 115 | + */ |
|
| 116 | + public function getPdfFilename() |
|
| 117 | + { |
|
| 118 | + $baseName = sprintf('%s-%s', $this->URLSegment, $this->ID); |
|
| 119 | + |
|
| 120 | + $folderPath = $this->config()->get('generated_pdf_path'); |
|
| 121 | + if ($folderPath[0] != '/') { |
|
| 122 | + $folderPath = BASE_PATH . '/' . $folderPath; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return sprintf('%s/%s.pdf', $folderPath, $baseName); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Build pdf link for template. |
|
| 130 | + */ |
|
| 131 | + public function PdfLink() |
|
| 132 | + { |
|
| 133 | + if (!$this->config()->get('pdf_export')) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $path = $this->getPdfFilename(); |
|
| 138 | + |
|
| 139 | + if ((Versioned::get_stage() === Versioned::LIVE) && file_exists($path)) { |
|
| 140 | + return Director::baseURL() . preg_replace('#^/#', '', Director::makeRelative($path)); |
|
| 141 | + } |
|
| 142 | + return $this->Link('downloadpdf'); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function RelatedPages() |
|
| 146 | + { |
|
| 147 | + return $this->getManyManyComponents('RelatedPages')->sort('SortOrder'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function RelatedPagesTitle() |
|
| 151 | + { |
|
| 152 | + return $this->config()->get('related_pages_title'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Remove linked pdf when publishing the page, |
|
| 157 | + * as it would be out of date. |
|
| 158 | + */ |
|
| 159 | + public function onAfterPublish() |
|
| 160 | + { |
|
| 161 | + $filepath = $this->getPdfFilename(); |
|
| 162 | + if (file_exists($filepath)) { |
|
| 163 | + unlink($filepath); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Remove linked pdf when unpublishing the page, |
|
| 169 | + * so it's no longer valid. |
|
| 170 | + * |
|
| 171 | + * @return boolean |
|
| 172 | + */ |
|
| 173 | + public function doUnpublish() |
|
| 174 | + { |
|
| 175 | + if (!parent::doUnpublish()) { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $filepath = $this->getPdfFilename(); |
|
| 180 | + if (file_exists($filepath)) { |
|
| 181 | + unlink($filepath); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return true; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + public function getCMSFields() |
|
| 188 | + { |
|
| 189 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 190 | + // Related Pages |
|
| 191 | + $components = GridFieldConfig_RelationEditor::create(); |
|
| 192 | + $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 193 | + $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 194 | + $components->removeComponentsByType(GridFieldFilterHeader::class); |
|
| 195 | + $components->addComponent(new GridFieldSortableRows('SortOrder')); |
|
| 196 | + |
|
| 197 | + /** @var GridFieldDataColumns $dataColumns */ |
|
| 198 | + $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 199 | + $dataColumns->setDisplayFields([ |
|
| 200 | + 'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'), |
|
| 201 | + 'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type') |
|
| 202 | + ]); |
|
| 203 | + |
|
| 204 | + $fields->findOrMakeTab( |
|
| 205 | + 'Root.RelatedPages', |
|
| 206 | + _t(__CLASS__ . '.RelatedPages', 'Related pages') |
|
| 207 | + ); |
|
| 208 | + $fields->addFieldToTab( |
|
| 209 | + 'Root.RelatedPages', |
|
| 210 | + GridField::create( |
|
| 211 | + 'RelatedPages', |
|
| 212 | + _t(__CLASS__ . '.RelatedPages', 'Related pages'), |
|
| 213 | + $this->RelatedPages(), |
|
| 214 | + $components |
|
| 215 | + ) |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc) |
|
| 219 | + $hasMany = $this->hasMany(); |
|
| 220 | + $manyMany = $this->manyMany(); |
|
| 221 | + if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) { |
|
| 222 | + $components = GridFieldConfig_RelationEditor::create(); |
|
| 223 | + $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 224 | + $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 225 | + |
|
| 226 | + /** @var GridFieldAddExistingAutocompleter $autoCompleter */ |
|
| 227 | + $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class); |
|
| 228 | + $autoCompleter->setResultsFormat('$Name ($TaxonomyName)'); |
|
| 229 | + |
|
| 230 | + /** @var GridFieldDataColumns $dataColumns */ |
|
| 231 | + $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 232 | + $dataColumns->setDisplayFields([ |
|
| 233 | + 'Name' => _t(__CLASS__ . '.Term', 'Term'), |
|
| 234 | + 'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy') |
|
| 235 | + ]); |
|
| 236 | + |
|
| 237 | + $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags')); |
|
| 238 | + $fields->addFieldToTab( |
|
| 239 | + 'Root.Tags', |
|
| 240 | + TreeMultiselectField::create( |
|
| 241 | + 'Terms', |
|
| 242 | + _t(__CLASS__ . '.Terms', 'Terms'), |
|
| 243 | + TaxonomyTerm::class |
|
| 244 | + )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms')) |
|
| 245 | + ); |
|
| 246 | + } |
|
| 247 | + }); |
|
| 248 | + return parent::getCMSFields(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Returns the native language name for the selected locale/language, empty string if Fluent is not available |
|
| 253 | + * |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + public function getSelectedLanguage() |
|
| 257 | + { |
|
| 258 | + if (!class_exists(Locale::class) || !$this->hasMethod('Locales')) { |
|
| 259 | + return ''; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** @var ArrayData $information */ |
|
| 263 | + $information = $this->LocaleInformation(FluentState::singleton()->getLocale()); |
|
| 264 | + |
|
| 265 | + return $information->LanguageNative; |
|
| 266 | + } |
|
| 267 | 267 | } |
@@ -186,7 +186,7 @@ |
||
| 186 | 186 | |
| 187 | 187 | public function getCMSFields() |
| 188 | 188 | { |
| 189 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 189 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 190 | 190 | // Related Pages |
| 191 | 191 | $components = GridFieldConfig_RelationEditor::create(); |
| 192 | 192 | $components->removeComponentsByType(GridFieldAddNewButton::class); |