Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony admin generator-- a button for save and back to list

How can I add a save and back to list button in the view for creating new record? In general, I want more buttons so I'm looking for a generic answer.

EDIT: Default generator provides me with two buttons:

  1. save
  2. save and add

I want a button that saves and takes me back to the list. And I also want a custom button with a custom action.

Let me explain the actual situation:

I have a list action create that takes me to a form having some input fields. Now I want to make an image using these fields' data. I want to display this image as preview on the right side of the form. For that I need a preview button so that whenever pressed, it submits the data to itself for preview and further modification.

I hope it's clearer now.

like image 457
prongs Avatar asked Dec 08 '11 10:12

prongs


1 Answers

You have first to add in generator.yml your save_and_back_to_list and other custom my_other_action actions:

    config:
      actions: ~
      fields:  ~
      list:    ~
      filter:  ~
      form:    ~
      edit:
        actions:
          _save: ~
          _list: ~
          save_and_back_to_list: ~
          my_other_action: ~
      new:
        actions:
          _save: ~
          _save_and_add: ~
          _list: ~
          save_and_back_to_list: ~
          my_other_action: ~

Then you have to add your customized helper functions to create your buttons in /apps/myapplication/modules/mymodule/lib/mymoduleGeneratorHelper.class.php

  public function linkToSaveAndBackToList($object, $params)
  {
    return '<li class="sf_admin_action_save_and_back_to_list"><input type="submit" value="'.__($params['label'], array(), 'sf_admin').'" name="save_and_back_to_list" /></li>';
  }

  public function linkToMyOtherAction($object, $params)
  {
    return '<li class="sf_admin_action_my_other_action"><input type="submit" value="'.__($params['label'], array(), 'sf_admin').'" name="my_other_action" /></li>';
  }

Now you get two submit buttons both in New and Edit form.

Finally you have to override the function processForm(sfWebRequest $request, sfForm $form), that you can find in /cache/dev/modules/autoMymodule/actions/actions.class.php, to manage your new submit actions. I guess your create function overrides the admin generator one.

I hope I don't forget nothing.

like image 169
macgyver Avatar answered Nov 04 '22 13:11

macgyver