Max Koovert
Max Koovert

Reputation: 3

Unset with embedded forms

I have in my Form class:

public function configure()
{
        $emb = $this->getEmbeddedForms();
        foreach($emb as $key => $form)
        {
             unset($form['backup']);
        }
}

But this not working - not unset. In $emb i have:

oneForm
twoForm

In oneForm and twoForm i have widget backup. I want unset this with getEmbeddedForms. I can't unset this in oneForm.class and twoForm.class.

Upvotes: 0

Views: 726

Answers (2)

j0k
j0k

Reputation: 22756

You should re-embed your form after the unset.

public function configure()
{
  $emb = $this->getEmbeddedForms();

  foreach($emb as $key => $form)
  {
    unset($form['backup']);

    // re-embed the current form (it will override the previous one)
    $this->embedForm($key, $form);
  }
}

Upvotes: 1

thedom
thedom

Reputation: 2518

No wonder at all. You assign the content of $this->getEmbeddedForms() the local variable $emb ;-))... Think about it.

So:

<?php
// ...

public function configure() {
 foreach($this->getEmbeddedForms() as $key => &$form) {
  unset($form['backup']);
 }
}
?>

Upvotes: 0

Related Questions