1

I've used the "doctrine:generate-admin" task. Everything is working but I want to use the generator.yml file to unset some form fields there rather than having to unset them in the Form class itself. Things like "updated_at" I only ever need saved when the object is updated but I don't want them displayed on any forms, and therefore I won't get any form validation errors.

Is this possible? I can't find anything on the reference page for the generator that would let me do this, the fields configuration only seems to allow for changing the label/credentials etc.

joe1
  • 11
  • 1
  • 2

3 Answers3

6

You need to simply choose fields you want to display:

config:
  form:
    display:
      Content: [title, body, author]
      Admin:   [is_published, expires_at]

It's weird you didn't find it on the reference page. Here you go: http://www.symfony-project.org/reference/1_4/en/06-Admin-Generator (navigate to form -> display).

Edit:

Admin generator uses sfModelGeneratorConfiguration::getFormFields() method to retrieve list of fields to render. It only takes all fields if you won't specify the 'display' option.

Is it all the fields are rendered or just some of them? If it's the later than you might have something overloaded in your form (for example configure() method).

Jakub Zalas
  • 35,761
  • 9
  • 93
  • 125
2

try this:

config:
  list:
    hide: [created_at, updated_at]

http://www.symfony-project.org/reference/1_4/en/06-Admin-Generator#chapter_06_sub_hide

martin
  • 93,354
  • 25
  • 191
  • 226
1

Apart from hiding the fields in config/generator.yml of the admin module, as stated above, you should unset them in the related form. So if you want to hide the created_at and updated_at fields of a Timestampable model, alter the configure() method in lib/form/doctrine/ModelForm.class.php to

public function configure()
{
    unset($this['created_at'],$this['updated_at']);
}
Webler
  • 21
  • 2
  • 3
  • $this is not an array in object context. – Edson Medina Oct 05 '12 at 08:58
  • We can find references to $this as an array all over Symfony 1.x docs, particularly regarding forms. – Webler Dec 14 '12 at 15:54
  • I get "PHP Fatal error: Cannot use object of type xxx as array" when trying to use $this as an array. Could you share some code that runs? – Edson Medina Dec 15 '12 at 15:11
  • The link you sent me shows $this being used as an object (and having array properties). – Edson Medina Jan 17 '13 at 10:31
  • That's $this->whatever['xxx'], and not $this['whatever']['xxx'] – Edson Medina Jan 17 '13 at 10:32
  • If you'd just execute it you'd see that unset($obj['two']) will work as fine as unset($this['created_at']) does **in Symfony form classes**. I don't care if it's not true for every object in PHP, it is for Symfony forms and that's how it's made possible. – Webler Jan 17 '13 at 13:28
  • It throws a fatal error. And the symfony class you're talking about doesn't use it like that (http://code.google.com/p/symfonycrm/source/browse/trunk/lib/form/doctrine/ModelForm.class.php) – Edson Medina Jan 17 '13 at 17:55
  • 3
    This is becoming a thread on its own right. ModelForm ultimately implements ArrayAccess which is the interface I tried to tell you that allows objects to behave as arrays. [Here's another attempt at showing just that](https://gist.github.com/4558139) – Webler Jan 17 '13 at 18:10
  • 1
    Webler, you're absolutely right. I didn't know that was possible. Sorry. – Edson Medina Jan 18 '13 at 11:27