New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Attempt to read property "jsWidget" on null #6941
Conversation
@ArchBlood Please check my reviews, but before apply the changes do you know what model has an old
|
protected/humhub/modules/content/widgets/stream/StreamEntryWidget.php
Outdated
Show resolved
Hide resolved
protected/humhub/modules/content/widgets/stream/StreamEntryWidget.php
Outdated
Show resolved
Hide resolved
protected/humhub/modules/content/widgets/stream/StreamEntryWidget.php
Outdated
Show resolved
Hide resolved
protected/humhub/modules/content/widgets/stream/StreamEntryWidget.php
Outdated
Show resolved
Hide resolved
To answer the main question about which model, it seems it was due to my Ticket model using public function getSearchAttributes()
{
// Define the searchable attributes
$attributes = [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
];
return $attributes;
} |
@ArchBlood As I understand you have a model like this: class Ticket extends ContentActiveRecord implements Searchable
{
...
public function getSearchAttributes()
{
// Define the searchable attributes
$attributes = [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
];
return $attributes;
}
...
} But what does the class have for the properties? : /**
* @see StreamEntryWidget
* @var string the StreamEntryWidget widget class
*/
public $wallEntryClass;
/**
* The stream channel where this content should displayed.
* Set to null when this content should not appear on streams.
*
* @since 1.2
* @var string|null the stream channel
*/
protected $streamChannel = 'default'; |
Instead of explaining it I've sent you an invite for better visibility of the code. |
Thank you for the access, what I have investigated:
I.e. the record is found but it is not rendered, yes we don't have any errors there, but it breaks at least the searching counter. I advise you either implement the But please note the applying To avoid errors I suggest to update the method private static function renderLegacyWallEntry(ContentActiveRecord $record, $options = [])
{
if (!is_array($options)) {
$options = [];
}
if (isset($options['jsWidget'])) {
$jsWidget = $options['jsWidget'];
unset($options['jsWidget']);
} else {
$wallEntryWidget = $record->getWallEntryWidget();
$jsWidget = $wallEntryWidget instanceof StreamEntryWidget ? $wallEntryWidget->jsWidget : null;
}
if ($jsWidget === null) {
Yii::error('Model ' . get_class($record) . ' must define $wallEntryClass or set $streamChannel to null!', 'content');
return '';
}
$params = [
'content' => $record instanceof ContentActiveRecord ? $record->getWallOut($options) : '',
'jsWidget' => $jsWidget,
'entry' => $record->content,
];
return Yii::$app->controller->renderPartial('@humhub/modules/content/views/layouts/wallEntry', $params);
} Could you please test how it works on your DB with already created Tickets? |
I've tested your version with both private static function renderLegacyWallEntry(ContentActiveRecord $record, $options = [])
{
$jsWidget = $options['jsWidget'] ?? $record->getWallEntryWidget()->jsWidget ?? null;
if ($jsWidget === null) {
Yii::error('Model ' . get_class($record) . ' must define $wallEntryClass or set $streamChannel to null!', 'content');
return '';
}
$content = $record instanceof ContentActiveRecord ? $record->getWallOut($options) : '';
$params = [
'content' => $content,
'jsWidget' => $jsWidget,
'entry' => $record->content,
];
return Yii::$app->controller->renderPartial('@humhub/modules/content/views/layouts/wallEntry', $params);
} |
I guess you have an error when you try to call In my code I did this: $wallEntryWidget = $record->getWallEntryWidget();
$jsWidget = $wallEntryWidget instanceof StreamEntryWidget ? $wallEntryWidget->jsWidget : null; Could you show me please what error did you get when you use my code?
Did you add it like |
I'm thrown the following error;
I've done as the error asks but it shows the error regardless whereas in my p/r code I am not getting any errors at all. 🤔 |
@ArchBlood I have tested by installing the FAQ module and create a ticket: Then I try to search it: Probably we should fix the core class public function getContentName()
{
return $this->title ?? Yii::t('FaqModule.base', 'Ticket');
} because it seems the core ok, if I update the method as I suggested above I catch the error Then I update the method private static function renderLegacyWallEntry(ContentActiveRecord $record, $options = [])
{
if (!is_array($options)) {
$options = [];
}
if (isset($options['jsWidget'])) {
$jsWidget = $options['jsWidget'];
unset($options['jsWidget']);
} else {
$wallEntryWidget = $record->getWallEntryWidget();
$jsWidget = $wallEntryWidget instanceof StreamEntryWidget ? $wallEntryWidget->jsWidget : null;
}
if ($jsWidget === null) {
Yii::error('Model ' . get_class($record) . ' must define $wallEntryClass or set $streamChannel to null!', 'content');
return '';
}
$params = [
'content' => $record instanceof ContentActiveRecord ? $record->getWallOut($options) : '',
'jsWidget' => $jsWidget,
'entry' => $record->content,
];
return Yii::$app->controller->renderPartial('@humhub/modules/content/views/layouts/wallEntry', $params);
} and I can run the search page without errors, only the Ticket record is not visible because WallEntry is not implemented for it yet. If you need to display the Ticket on the search list you should update the Ticket class by adding the line: public $wallEntryClass = WallEntry::class; Then you should add the class WallEntry with code like this: <?php
namespace gm\humhub\modules\faq\widgets;
use gm\humhub\modules\faq\models\Ticket;
use humhub\modules\content\widgets\stream\WallStreamEntryOptions;
use humhub\modules\content\widgets\stream\WallStreamEntryWidget;
use humhub\modules\content\widgets\stream\WallStreamModuleEntryWidget;
class WallEntry extends WallStreamModuleEntryWidget
{
/**
* @inheritdoc
*/
public $createRoute = '/faq/ticket/create';
/**
* @inheritdoc
* @var Ticket
*/
public $model;
/**
* @inheritdoc
*/
public $editRoute = '/faq/ticket/update';
/**
* @inheritdoc
*/
public $editMode = WallStreamEntryWidget::EDIT_MODE_NEW_WINDOW;
/**
* @inheritdoc
*/
public function renderContent()
{
return $this->render('wall-entry', [
'ticket' => $this->model,
'isDetailView' => $this->renderOptions->isViewContext(WallStreamEntryOptions::VIEW_CONTEXT_DETAIL),
]);
}
/**
* @inheritdoc
*/
protected function getTitle()
{
return $this->model->title;
}
} and also a view file <?php
use gm\humhub\modules\faq\models\Ticket;
use humhub\modules\content\widgets\richtext\RichText;
/* @var $ticket Ticket */
/* @var $isDetailView bool */
?>
<div data-news="<?= $ticket->id ?>" data-content-key="<?= $ticket->content->id ?>">
<div data-ui-markdown<?= $isDetailView ? '' : ' data-ui-show-more' ?>>
<?= RichText::output($ticket->description) ?>
</div>
</div> Then a Tciket record will be visbile on the search page like this: I see the wall entry of the Ticket(as you can see on my screenshot above) even without the modifications in the core method, but it would be better to keep such fixes for some unexpected errors in the broken model like the Ticket, so I hope you update this PR to that my suggested code and I will approve this PR, otherwise please show me why it doesn't work for you, thanks. But if you don't need to search ticket records then you can just remove Please let me know if have some questions else, thanks. |
The reason why the ticket was made searchable is so that it was easier for the user to find, of course we didn't want it to return the actual ticket information through a Going back to using What @GreenMeteor wants to do is make use of the search function without the use of displaying the actual information in the search stream which both of the above does with the added error applied. This P/R fixes the original reported error and makes it possible to use the search function how we needed it without using either |
PR Summary
|
I'll have to go with your suggestion and implement some restrictions @yurabakhtin so that only the creator can view their own Tickets. |
@ArchBlood I see you updated this PR as I recommended, thanks, I can approve it now, so it works like this without changes in the It may be a confused in the counter part, because Ticket records are not visible. But as I understand you don't want to implement @luke- Currently we index content records only with What do you think if we will introduce new So then @ArchBlood could make the Tickets are visbile only on the search list and hidden on Dashboard stream: class Ticket extends ContentActiveRecord implements Searchable
{
public $wallEntryClass = WallEntry::class;
public $streamChannel = Content::STREAM_CHANNEL_SEARCH; // 'search' |
@yurabakhtin If the content should not appear on the dashboard, can't we just use the new Visbility flag? Otherwise, we also have modules that simply implement a separate stream channel in such cases: https://github.com/humhub/translation/blob/master/models/TranslationLog.php#L41 Do we need to change anything else in the PR in this regard? |
protected/humhub/modules/content/widgets/stream/StreamEntryWidget.php
Outdated
Show resolved
Hide resolved
@yurabakhtin Why do we need the new checks for instanceof |
@yurabakhtin Ok the error is fine but why we need |
@luke- I confirm, we don't need this change at all because I don't know how such case may happens, I already answered about this here, so the change can be reverted. |
Ok, thanks for the explanation: From my side, we can either:
|
I've reverted it back the line mentioned incase of this P/R being accepted. |
What kind of change does this PR introduce? (check at least one)
fixes #6940
Does this PR introduce a breaking change? (check one)
If yes, please describe the impact and migration path for existing applications:
The PR fulfills these requirements:
develop
branch, not themaster
branch if no hotfixFix #xxx[,#xxx]
, where "xxx" is the Github issue number)If adding a new feature, the PR's description includes:
Other information: