Skip to content

Commit b44353d

Browse files
committed
check for actual class name or fallback to class name with '_cell' omitted
1 parent 21b8c76 commit b44353d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

system/View/Cells/Cell.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ final protected function view(?string $view, array $data = []): string
7373

7474
// If no view is specified, we'll try to guess it based on the class name.
7575
if (empty($view)) {
76-
$view = decamelize((new ReflectionClass($this))->getShortName());
77-
$view = str_replace('_cell', '', $view);
76+
// According to the docs, the name of the view file should be the
77+
// snake_cased version of the cell's class name, but for backward
78+
// compactibility, the name also accepts '_cell' being omitted.
79+
$ref = new ReflectionClass($this);
80+
$view = decamelize($ref->getShortName());
81+
$viewPath = dirname($ref->getFileName()) . DIRECTORY_SEPARATOR . $view . '.php';
82+
$view = file_exists($viewPath) ? $viewPath : str_replace('_cell', '', $view);
7883
}
7984

8085
// Locate our view, preferring the directory of the class.

0 commit comments

Comments
 (0)