I had a thread a couple of weeks ago where I am overriding how link building for thread works using the router_public_setup code even listener:
Now I thought I could use the same mechanism for overriding breadcrumb links to special type of forums/nodes but I found that breadcrumb links do not work this way.
snippet from Entity/Node.php:
(So looking at this code, I realized I was probably doing this entire thing the wrong way and I should be adding a new Node Type but I couldn't find any examples of how to add custom node type and my experiment adding an entry in the xf_node_type table didn't work. If anyone has any examples of this, please share.)
So I get that I need to override this function in my extended class but it looks like I just need to straight up copy-paste it and add in my modification? Because what I really need to do is modify the $route when a custom node property matches my condition (I've already extended Service\Node\RebuildNestedSet to add the custom node property).
The other way I can think of is stubbing out app() in my Node class extension but that also feels like I'm going overboard.
Any pointers?
XF 2.1 - router_public_setup to override buildLink/route?
My addon extends threads controller as well as xf_threads table and has its own route. My goal is to "override" links to threads in all templates, for example: link('threads', $threads) So that conditionally, it can use the correct route and return the overridden link if the thread is the...
xenforo.com
Now I thought I could use the same mechanism for overriding breadcrumb links to special type of forums/nodes but I found that breadcrumb links do not work this way.
snippet from Entity/Node.php:
PHP:
public function getBreadcrumbs($includeSelf = true, $linkType = 'public')
{
/** @var \XF\Mvc\Router $router */
$router = $this->app()->container('router.' . $linkType);
$nodeTypes = $this->app()->container('nodeTypes');
(snip)
$route = $linkType == 'public' ? $nodeType['public_route'] : $nodeType['admin_route'];
$output[] = [
'value' => $crumb['title'],
'href' => $router->buildLink($route, $crumb),
'node_id' => $crumb['node_id']
];
(snip)
(So looking at this code, I realized I was probably doing this entire thing the wrong way and I should be adding a new Node Type but I couldn't find any examples of how to add custom node type and my experiment adding an entry in the xf_node_type table didn't work. If anyone has any examples of this, please share.)
So I get that I need to override this function in my extended class but it looks like I just need to straight up copy-paste it and add in my modification? Because what I really need to do is modify the $route when a custom node property matches my condition (I've already extended Service\Node\RebuildNestedSet to add the custom node property).
The other way I can think of is stubbing out app() in my Node class extension but that also feels like I'm going overboard.
Any pointers?