Page MenuHomePhabricator

Inconsistency in how child content is added to widgets
Closed, ResolvedPublic

Description

Another slight inconsistency regards how child content is added to widgets. For most widgets, the PHP appendContent / JS $element.append() / 'content' config option is treated as an 'internal' method -- that is, the widget itself manages its content, and the enduser is not expected to directly add or mutate the contents of the $element / use appendContent.

But in other places (FormLayout for instance), the widget is entirely useless if you don't use $element.append / appendContent. And in the PHP demo app, a raw instance of Widget is created, and content is added to it.

It would probably be best if directly manipulating content were deprecated, and new initializers/methods added where previously the end user was expected to manipulate content. For example, FormLayout should probably take an items parameter. For the usage in the PHP demo app, a special ContentWidget subclass of Widget might be appropriate -- really what's wanted in the demo app is a Widget, but the FieldLayout insists that fieldWidget is a Widget, not a Layout. So maybe a LayoutWidget is needed to bridge the gap?

I think FormLayout is the only case where that happens, and indeed it should not happen anywhere. The only reason it doesn't take 'items' (containing FieldsetLayouts) is because I haven't done that yet.

@matmarex: grepping for serializeContent in my patch shows that FormLayout, PanelLayout, and DropdownInputWidget all require serializeContent. Plus the bare Widget in the demo.

Event Timeline

matmarex raised the priority of this task from to Needs Triage.
matmarex updated the task description. (Show Details)
matmarex added a project: OOUI.
matmarex added subscribers: matmarex, cscott.
matmarex triaged this task as High priority.
matmarex set Security to None.

Change 191832 had a related patch set uploaded (by Bartosz Dziewoński):
FormLayout: Allow adding child layouts via config

https://gerrit.wikimedia.org/r/191832

Patch-For-Review

@matmarex: grepping for serializeContent in my patch shows that FormLayout, PanelLayout, and DropdownInputWidget all require serializeContent.

  • I submitted the patch for FormLayout above.
  • PanelLayout is a weird case – it is never used alone, but only as "glue code" inside some bigger widget/dialog/layout. With GridLayout gone, there isn't really any use case for it in PHP. We might remove it, or port something from JS that would make it useful, but in the meantime, I think it just shouldn't be infusable.
  • DropdownInputWidget doesn't require serializeContent. The labels may not be Elements, so they can be just serialized as strings or HTML.

Change 191832 merged by jenkins-bot:
FormLayout: Allow adding child layouts via config

https://gerrit.wikimedia.org/r/191832