Error messages (..type null, undefined index) when board made a sub-board

Started by Julius_2000, January 10, 2023, 08:50:51 AM

Previous topic - Next topic

Julius_2000

Hi all,

I noticed that when I make any board a sub-board of another, I get the following error messages for the MessageIndexTemplate.php

Quote8: Trying to access array offset on value of type null
and
Quote8: Undefined index: first_post

and it refers to this line of code:
You cannot view this attachment.

I suspect it has something to do with the way I modifed the MessageIndexTemplate.
This is the code (based on the Pelikan Theme one)
/*changed added class "started by" */
function template_bi_board_lastpost($board)
{
if (empty($board['last_post']['id']))
return;

echo '
<div class="node-extra-icon"><a href="',$board['last_post']['href'],'" title="Last post by ',$board['last_post']['member']['name'],'">', $board['last_post']['member']['avatar']['image'], '</a></div>
<div class="topic-item-content">
<div class="topic-item-title">', $board['last_post']['link'], '</div>
<div class="topic-item-details">
<div class="started_by">', $board['first_post']['member']['link'], '</div>
<div class="topic-item-poster">', $board['last_post']['member']['link'], '</div>
<div class="topic-item-time"><a href="',$board['last_post']['href'],'" title="Last post #',$board['replies'],'">', icon('far fa-clock'), ' ', timeformat($board['last_post']['timestamp']), '</a></div>

</div>

</div>';

What I did is I added a div to show the member who "started" a topic in the message index inside the "last post" content rather than where it was before as a separate p element under the topic title.
It was one of my first edits ever and I inferred from other codes elsewhere in the MessageIndex file and/or other SMF php files. And because it apparently worked outside the sub-board environment (indeed showing the starter of a topic) I never questioned my approach. But now that I have Error Log enabled, I noticed that it might be a faulty one.
What I believe to understand is that the sub-board is now residing within a message index as a board, which might confuse the code that I use, not knowing what the first post is (as it's not a topic index but rather a board?).
The Dev tool of my browser shows that the $board['first_post']... variable does not work on the sub-board (showing an empty div, maybe the type null error reference?). Only in the rest of the message index it is applied correctly, showing the starter of a topic as intended.

I tried replacing the $board['first_post'] with $topic['first_post'] which exists within MessageIndexTemplate.php but then I get an error stating that the variable is undefined.

What would I need to do to make the error go away and still display a topic starter in the last post section?

Julius_2000

Bump. Does anyone have an idea what I did wrong or how I could avoid those errors? Thank you so much!

Sesquipedalian

Put simply, you are trying to use information that isn't provided about sub-boards. The array of information about a sub-board includes data about the latest post that was made in that board. It doesn't include any information about the first post that was made in that board (which is what your code seems to be trying to get), nor about the original post of the topic of the latest post in the board (which is what your explanation indicates you actually want).

In order to get information about the first post in the topic that the board's latest post belongs to, you will need to run another database query to fetch that information. If you know how to do so, the best way to accomplish this would be via the integrate_getboardtree hook. If you don't know how to do that, you should probably ask for help in the Help Wanted board.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Advertisement: