mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 08:17:12 +02:00
Additional update for custom page classes for repeater page items. processwire/processwire-requests#239
This commit is contained in:
@@ -872,6 +872,18 @@ class Templates extends WireSaveableItems {
|
||||
|
||||
// determine if custom class available (3.0.152+)
|
||||
if($usePageClasses) {
|
||||
$customPageClass = '';
|
||||
// repeaters support a field-name based name strategy
|
||||
/** @var RepeaterField $field */
|
||||
if(strpos($template->name, 'repeater_') === 0) {
|
||||
$field = $this->wire()->fields->get(ltrim(strstr($template->name, '_'), '_'));
|
||||
if($field && wireInstanceOf($field->type, 'FieldtypeRepeater')) {
|
||||
$customPageClass = $field->type->getCustomPageClass($field);
|
||||
}
|
||||
}
|
||||
if($customPageClass) {
|
||||
$pageClass = $customPageClass;
|
||||
} else {
|
||||
// generate a CamelCase name + 'Page' from template name, i.e. 'blog-post' => 'BlogPostPage'
|
||||
$className = ucwords(str_replace(array('-', '_', '.'), ' ', $template->name));
|
||||
$className = __NAMESPACE__ . "\\" . str_replace(' ', '', $className) . 'Page';
|
||||
@@ -879,6 +891,7 @@ class Templates extends WireSaveableItems {
|
||||
$pageClass = $className;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($cacheable && $template->id) $this->pageClassNames[$template->id] = $pageClass;
|
||||
|
||||
@@ -1155,4 +1168,3 @@ class Templates extends WireSaveableItems {
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user