Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions core/libraries/Hubzero/Component/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ class View extends AbstractView
*/
public function __construct($config = array())
{
// Look for overrides under the component that owns the view, not
// the one the request is for: a group's wiki is com_wiki's views
// rendered inside com_groups, and belongs in html/com_wiki/
if (!array_key_exists('override_path', $config) && !empty($config['base_path']))
{
if ($component = self::componentFromPath($config['base_path']))
{
$config['override_path'] = $component;
}
}

parent::__construct($config);

// Set a base path for use by the view
Expand All @@ -76,6 +87,25 @@ public function __construct($config = array())
$this->_basePath = $config['base_path'];
}

/**
* The component (com_*) a path lies inside, if any
*
* @param string $path A component path, such as core/components/com_wiki/site
* @return string|null
*/
protected static function componentFromPath($path)
{
foreach (array_reverse(preg_split('#[/\\\\]+#', $path)) as $segment)
{
if (preg_match('/^com_[A-Z0-9_\.-]+$/i', $segment))
{
return strtolower($segment);
}
}

return null;
}

/**
* Create a component view and return it
*
Expand Down
24 changes: 24 additions & 0 deletions core/libraries/Hubzero/View/Tests/OverrideRootsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ public function testDirectlyConstructedComponentViewSeesEveryRoot()
);
}

/**
* A component's views rendered inside another component's request (a
* group's wiki: com_wiki views under option=com_groups) are overridden
* from the owning component's directory, not the request's
*
* @return void
*/
public function testComponentViewOverridesFollowItsOwnComponent()
{
$view = new ComponentView([
'name' => 'pages',
'base_path' => $this->env->root . '/components/com_wiki/site',
]);

$this->assertSame(
$this->expectedOverrides('com_wiki', 'pages'),
array_slice($this->templatePaths($view), 0, 2)
);

$child = $this->templatePaths($view->view('wikimenu'));

$this->assertSame($this->expectedOverrides('com_wiki', 'pages'), array_slice($child, 0, 2));
}

/**
* @return void
*/
Expand Down
Loading