Ejemplo n.º 1
0
 /**
  * Prepare the widgets used by this action
  * Model $model
  */
 protected function initWidgets($model)
 {
     $config = $model->getFieldConfig();
     $config->model = $model;
     $config->arrayName = class_basename($model);
     $config->context = 'update';
     $widget = $this->makeWidget('Backend\\Widgets\\Form', $config);
     $widget->bindToController();
     $this->formWidget = $widget;
     $plugins = MenuManager::instance()->listItemTypes();
     foreach ($plugins as $class => $details) {
         $class = new $class();
         $class->extendSettingsForm($this->formWidget);
         $class->extendSettingsModel($model);
     }
 }
Ejemplo n.º 2
0
 public function onLoadEditItem()
 {
     try {
         $id = post('id', 0);
         if (!($item = MenuItem::find($id))) {
             throw new Exception('Menu item not found.');
         }
         $this->vars['id'] = $id;
         $this->vars['type'] = $type = $item->master_object_class;
         $itemTypes = MenuManager::instance()->listItemTypes();
         $this->vars['typeInfo'] = $itemTypes[$type];
         /*
          * Create a form widget to render the form
          */
         $config = $this->makeConfig('@/plugins/flynsarmy/menu/models/menuitem/fields.yaml');
         $config->model = $item;
         $config->context = 'edit';
         $form = $this->makeWidget('Backend\\Widgets\\Form', $config);
         $form->bindEvent('form.extendFields', function () use($type, $form) {
             $itemTypeObj = new $type();
             $itemTypeObj->extendItemForm($form);
         });
         $this->vars['form'] = $form;
     } catch (Exception $ex) {
         $this->vars['fatalError'] = $ex->getMessage();
     }
     return $this->makePartial('update_item');
 }