craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.21k stars 624 forks source link

[5.0.0-beta.10]: Custom table column breaks 'edit' functionality in entries index #14639

Closed wsydney76 closed 5 months ago

wsydney76 commented 5 months ago

What happened?

Description

I have a custom column named 'bigImage' for the entries index that shows a bigger thumbnail:

image

It is registered analog to https://github.com/wsydney76/craft4-ddev-starter/blob/main/modules/base/BaseModule.php#L311

Works fine, however, when pressing the 'Edit' button, there is an ajax error:

image

Or maybe we have to opt out of editing in some way when registering the column?

Steps to reproduce

  1. Register a custom column
  2. Press 'Edit'

Expected behavior

No error, column is displayed as is.

Actual behavior

Error

EDIT:

Workaround for now:

if (Craft::$app->request->isAjax) {
    $isInlineEditing = Craft::$app->request->getBodyParam('viewState.inlineEditing', false);
    if (!$isInlineEditing) {
        $this->setElementIndexColumns();
    }
}

Craft CMS version

5.0.0-beta.10

PHP version

8.2.13

Operating system and version

Linux 5.15.133.1-microsoft-standard-WSL2

Database type and version

MySQL 8.0.33

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

No response

i-just commented 5 months ago

Hi, thanks for getting in touch!

In v4, you were defining your Element::EVENT_REGISTER_TABLE_ATTRIBUTES and also had to define Element::EVENT_SET_TABLE_ATTRIBUTE_HTML to specify what shows in the table column for the attribute.

In v5 you do the same with Element::EVENT_REGISTER_TABLE_ATTRIBUTES and Element::EVENT_DEFINE_ATTRIBUTE_HTML but you also need the Element::EVENT_DEFINE_INLINE_ATTRIBUTE_INPUT_HTML to specify how the table column for the attribute behaves when using the inline editing mechanism. You could, for example, pass the same HTML as used in EVENT_DEFINE_ATTRIBUTE_HTML (e.g. via$event->html = $event->sender->getAttributeHtml($attribute);) so that the image shows, but is not editable.

That being said, we’ll also discuss this internally.

wsydney76 commented 5 months ago

@i-just Thanks, works perfectly.

For me it is fine, should just be mentioned in upgrading docs.