Problem/Motivation

When Selecting View Mode in Paragraph it doesn't change, it is always Default, even though I have custom view modes which are enabled

Steps to reproduce

I created a paragraph
Added view modes
Enable the flag to use Paragraph View Mode
Went to Form Display and try selecting additional view modes

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#4 3163807-4.patch1.18 KBgranik

Comments

UriDrupal created an issue. See original summary.

sayco’s picture

Hi @UriDrupal, could you verify first if your issue is similar to:
https://www.drupal.org/project/paragraph_view_mode/issues/3157506
especially if you could verify if you enabled those view modes on your paragraph type.

sayco’s picture

Status: Active » Postponed (maintainer needs more info)

@UriDrupal I would be very glad if you can answer my question or provide me with any additional information to debug your issue.

granik’s picture

Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new1.18 KB

The error has been fixed. I added the patch.

sayco’s picture

Thank you for introducing the patch. I maybe not follow, but could you explain why the __CLASS__ is better then get_called_class()? The second one is more flexible, as it allows to call the method from the current class - so it's usefull in case of inheritance. I would rather stick to get_called_class, but I would like to know opinion from the community.
I also don't understand why did you change the method to a static one? Even in Ajax Form API examples a non-static methods are used.

granik’s picture

why the __CLASS__ is better then get_called_class()

It's my personal opinion. I'm used to see php callable array with this constant. Maybe it's not a very good style in drupal context.

I also don't understand why did you change the method to a static one?

It was the reason of the error. How are you going to use a non-static method in php callable? In this case you have to set an object as the first element of callable-array. But as you already said, get_called_class() returns the classname string, not object, __CLASS__ is the same.

Even in Ajax Form API examples a non-static methods are used.

It's just a callback. You can use any callable. Read more about ajax callbacks

sayco’s picture

Ok I see your point. IMO get_called_class() could better because it's like with a static vs self so basicaly get_called_class will return the current executed class, the __CLASS__ will return the specific class - ParagraphViewModeWidget.
Of course, it can be altered - it's a matter of changing the callback in the form element, but I think that the current solution is a bit more clean solution. What is your opinion on this?

In terms of changing a method into static, yes I totally get it now, so it's definitely a great thing :-)

  • sayco committed aa38b48 on 8.x-1.x authored by Granik
    Issue #3163807 by Granik: Can't select viewmode
    
sayco’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.