Ozzy47
Well-known member
I'm working on an addon to turn widgets on/off (toggle) like we do with template modifications. I have that part working, my column in the DB shows 0 for the one I toggled off. But I am having difficulty getting it to not show. I tried extending
I get this in the logs due to debug code:
I also have a few other things extended:
XF\Widget\WidgetRenderer
like this:
PHP:
<?php
namespace OzzModz\ToggleWidgets\XF\Widget;
class WidgetRenderer extends XFCP_WidgetRenderer
{
public function render()
{
\XF::logError('ToggleWidgets: Renderer called');
try {
$widget = $this->getCurrentWidget();
\XF::logError('ToggleWidgets: Widget ' . ($widget ? 'FOUND ID ' . $widget->widget_id : 'NOT FOUND'));
if ($widget) {
\XF::logError(sprintf(
'ToggleWidgets: Widget ID %d - Active: %d, Defined: %d',
$widget->widget_id,
$widget->ozzmodz_widget_active,
isset($widget->ozzmodz_widget_active)
));
if (!$widget->ozzmodz_widget_active) {
\XF::logError('ToggleWidgets: BLOCKING widget ID ' . $widget->widget_id);
return '<!-- WIDGET DISABLED -->';
}
}
$result = parent::render();
\XF::logError('ToggleWidgets: Rendered normally');
return $result;
} catch (\Throwable $e) {
\XF::logError('ToggleWidgets ERROR: ' . $e->getMessage());
return parent::render();
}
}
protected function getCurrentWidget()
{
// Check all possible widget locations with explicit logging
if (property_exists($this, 'widget') && isset($this->widget)) {
\XF::logError('ToggleWidgets: Found widget in $this->widget');
return $this->widget;
}
if (property_exists($this, 'positionContext')
&& isset($this->positionContext['widget'])
) {
\XF::logError('ToggleWidgets: Found widget in positionContext');
return $this->positionContext['widget'];
}
if (property_exists($this, 'params')
&& isset($this->params['widget'])
) {
\XF::logError('ToggleWidgets: Found widget in params');
return $this->params['widget'];
}
\XF::logError('ToggleWidgets: No widget found in any standard location');
return null;
}
}
I get this in the logs due to debug code:
Code:
ToggleWidgets: Widget NOT FOUND A moment ago src/XF/Error.php:81
ToggleWidgets: No widget found in any standard location A moment ago src/XF/Error.php:81
ToggleWidgets: Renderer called A moment ago src/XF/Error.php:81
I also have a few other things extended:
Code:
XF\Admin\Controller\Widget
OzzModz\ToggleWidgets\XF\Admin\Controller\Widget
XF\Entity\Widget
OzzModz\ToggleWidgets\XF\Entity\Widget
XF\Repository\Widget
OzzModz\ToggleWidgets\XF\Repository\Widget
XF\Widget\WidgetRenderer
OzzModz\ToggleWidgets\XF\Widget\WidgetRenderer