ExpressionEngine icon indicating copy to clipboard operation
ExpressionEngine copied to clipboard

Adding a Tab without an existing Channel Layout throws an error

Open swierczek opened this issue 1 year ago • 1 comments

Description of the problem If a Channel doesn't have a Publish Layout created, then when viewing a saved entry with a custom Tab throws an error:

image

Error at https://github.com/ExpressionEngine/ExpressionEngine/blob/7.dev/system/ee/ExpressionEngine/Model/Content/Display/DefaultLayout.php#L72 because $fields[$field_id] is not set.

How To Reproduce Steps to reproduce the behavior:

  1. Create a custom field with a tab as described at https://docs.expressionengine.com/latest/development/tab-files.html
  2. Install the add-on/field
  3. Create a new channel and don't create a Publish Layout
  4. Create a new entry in that channel. The create page should load as expected. But after you click Save and it reloads the new entry, the error should appear.

Error Messages


Error Caught
Call to a member function getId() on null

ee/ExpressionEngine/Model/Content/Display/LayoutTab.php:49
Stack Trace: Please include when reporting this error

    #0 ee/ExpressionEngine/Model/Content/Display/DefaultLayout.php(73): ExpressionEngine\Model\Content\Display\LayoutTab->addField(NULL)
    #1 ee/ExpressionEngine/Model/Channel/Display/DefaultChannelLayout.php(229): ExpressionEngine\Model\Content\Display\DefaultLayout->transform(Array)
    #2 ee/ExpressionEngine/Model/Channel/ChannelEntry.php(835): ExpressionEngine\Model\Channel\Display\DefaultChannelLayout->transform(Array)
    #3 ee/ExpressionEngine/Controller/Publish/Edit.php(509): ExpressionEngine\Model\Channel\ChannelEntry->getDisplay(Object(ExpressionEngine\Model\Channel\Display\DefaultChannelLayout))
    #4 [internal function]: ExpressionEngine\Controller\Publish\Edit->entry('83676')
    #5 ee/ExpressionEngine/Core/Core.php(268): call_user_func_array(Array, Array)
    #6 ee/ExpressionEngine/Core/Core.php(124): ExpressionEngine\Core\Core->runController(Array)
    #7 ee/ExpressionEngine/Boot/boot.php(184): ExpressionEngine\Core\Core->run(Object(ExpressionEngine\Core\Request))

Environment Details:

  • Version: 7.3.12
  • PHP Version: 8.0.30
  • Web Server: Apache

Possible Solution The solution is to create a Publish Layout for the channel. But that isn't obvious given the error message. I'd suggest either a more graceful error in this case to guide the user to create a Publish Layout manually, or to handle the error gracefully in code so it doesn't actually prevent the entry from loading.

swierczek avatar Sep 30 '24 15:09 swierczek

@swierczek does your upd. file include tabs() method and install() method has necessary code as according to https://docs.expressionengine.com/latest/development/add-on-update-file.html#add-publish-tabs-with-your-add-on-tabs ?

intoeetive avatar Oct 05 '24 11:10 intoeetive

@intoeetive I tried adding the tabs() function to the upd file, but that didn't seem to change anything here. I haven't tried adjusting the install/update functions though, as this error happens when the channel doesn't have any layouts .

Image

As soon as I create a layout, then it works as expected (even without tabs()).

Image

swierczek avatar Feb 27 '25 21:02 swierczek

@swierczek I believe this still belongs to the side of add-ons. If the add-on provides tabs, the upd file should consider that as per the docs

intoeetive avatar Mar 22 '25 10:03 intoeetive