Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions formwidgets/MenuItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ class MenuItems extends FormWidgetBase

public $newItemTitle = 'winter.pages::lang.menuitem.new_item';

/**
* The form widget used to edit a single menu item.
*/
protected $itemFormWidget = null;

/**
* {@inheritDoc}
*/
public function init()
{
$this->getItemFormWidget();
}

/**
Expand Down Expand Up @@ -69,11 +75,30 @@ public function prepareVars()

$this->vars['emptyItem'] = $emptyItem;

$this->vars['itemFormWidget'] = $this->getItemFormWidget();
}

/**
* Returns the form widget used by the menu item editor popup. Made on init
* rather than at render time so the item form's own widgets are bound to the
* controller on AJAX requests too, allowing their handlers to run.
*
* @return \Backend\Widgets\Form
*/
protected function getItemFormWidget()
{
if ($this->itemFormWidget !== null) {
return $this->itemFormWidget;
}

$widgetConfig = $this->makeConfig('~/plugins/winter/pages/classes/menuitem/fields.yaml');
$widgetConfig->model = $menuItem;
$widgetConfig->model = new MenuItem();
$widgetConfig->alias = $this->alias . 'MenuItem';

$this->vars['itemFormWidget'] = $this->makeWidget('Backend\Widgets\Form', $widgetConfig);
$widget = $this->makeWidget('Backend\Widgets\Form', $widgetConfig);
$widget->bindToController();

return $this->itemFormWidget = $widget;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions formwidgets/menuitems/assets/js/menu-items-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
self.$popupForm = self.$popupContainer.find('form')
self.itemSaved = false

// The popup lives outside the editor's own form, so carry the object
// context over: requests fired from here need it to rebind the widget.
$('input[name="formWidgetAlias"], input[name="objectType"], input[name="objectPath"], input[name="theme"]', self.$el.closest('form'))
.clone()
.appendTo(self.$popupForm)

var $titleField = $('input[name=title]', self.$popupContainer).focus().select()
var $typeField = $('select[name=type]', self.$popupContainer).change(function(){
self.loadTypeInfo(false, true)
Expand Down
Loading