| 613 | | $this->form->bind( |
| 614 | | $request->getParameter('a_media_items'), |
| 615 | | $request->getFiles('a_media_items')); |
| 616 | | if ($this->form->isValid()) |
| 617 | | { |
| 618 | | $request->setParameter('first_pass', true); |
| 619 | | // Saving embedded forms is weird. We can get the form objects |
| 620 | | // via getEmbeddedForms(), but those objects were never really |
| 621 | | // bound, so getValue will fail on them. We have to look at the |
| 622 | | // values array of the parent form instead. The widgets and |
| 623 | | // validators of the embedded forms are rolled into it. |
| 624 | | // See: |
| 625 | | // http://thatsquality.com/articles/can-the-symfony-forms-framework-be-domesticated-a-simple-todo-list |
| 626 | | $items = $request->getParameter("a_media_items"); |
| 627 | | for ($i = 0; ($i < aMediaTools::getOption('batch_max')); $i++) |
| 628 | | { |
| 629 | | $values = $this->form->getValues(); |
| 630 | | $file = $values["item-$i"]['file']; |
| 631 | | if ($file) |
| 632 | | { |
| 633 | | // Humanize the original filename |
| 634 | | $title = $file->getOriginalName(); |
| 635 | | $title = preg_replace('/\.\w+$/', '', $title); |
| 636 | | $title = aTools::slugify($title, false, false, ' '); |
| 637 | | $items["item-$i"]['title'] = $title; |
| 638 | | } |
| 639 | | else |
| 640 | | { |
| 641 | | // So the editImagesForm validator won't complain about these |
| 642 | | unset($items["item-$i"]); |
| 643 | | } |
| 644 | | } |
| 645 | | $request->setParameter("a_media_items", $items); |
| | 618 | $count = 0; |
| | 619 | $request->setParameter('first_pass', true); |
| | 620 | // Saving embedded forms is weird. We can get the form objects |
| | 621 | // via getEmbeddedForms(), but those objects were never really |
| | 622 | // bound, so getValue will fail on them. We have to look at the |
| | 623 | // values array of the parent form instead. The widgets and |
| | 624 | // validators of the embedded forms are rolled into it. |
| | 625 | // See: |
| | 626 | // http://thatsquality.com/articles/can-the-symfony-forms-framework-be-domesticated-a-simple-todo-list |
| | 627 | $items = $request->getParameter("a_media_items"); |
| | 628 | $files = $request->getFiles("a_media_items"); |
| | 629 | for ($i = 0; ($i < aMediaTools::getOption('batch_max')); $i++) |
| | 630 | { |
| | 631 | $values = $this->form->getValues(); |
| | 632 | // This is how we check for the presence of a file upload without a full form validation |
| | 633 | $file = $files["item-$i"]['file']; |
| | 634 | if (isset($file['newfile']['tmp_name']) && strlen($file['newfile']['tmp_name'])) |
| | 635 | { |
| | 636 | // Humanize the original filename |
| | 637 | $title = $file['newfile']['name']; |
| | 638 | $title = preg_replace('/\.\w+$/', '', $title); |
| | 639 | $title = aTools::slugify($title, false, false, ' '); |
| | 640 | $items["item-$i"]['title'] = $title; |
| | 641 | $count++; |
| | 642 | } |
| | 643 | else |
| | 644 | { |
| | 645 | // So the editImagesForm validator won't complain about these |
| | 646 | unset($items["item-$i"]); |
| | 647 | } |
| | 648 | } |
| | 649 | $request->setParameter("a_media_items", $items); |
| | 650 | if ($count) |
| | 651 | { |
| 648 | | // |
| 649 | | // // We'd like to just do this... |
| 650 | | // // $this->forward('aMedia', 'edit'); |
| 651 | | // // But we need to break out of the iframe, and |
| 652 | | // // modern browsers ignore Window-target: _top which |
| 653 | | // // would otherwise be perfect for this. |
| 654 | | // // Fortunately, the persistent file upload widget can tolerate |
| 655 | | // // a GET-method redirect very nicely as long as we pass the |
| 656 | | // // persistids. So we make the current parameters available |
| 657 | | // // to a template that breaks out of the iframe via |
| 658 | | // // JavaScript and passes the prameters on. |
| 659 | | // $this->parameters = $request->getParameterHolder('a_media_items')->getAll(); |
| 660 | | // // If I don't do this I just get redirected back to myself |
| 661 | | // unset($this->parameters['module']); |
| 662 | | // unset($this->parameters['action']); |
| 663 | | // return 'Redirect'; |
| | 654 | } |
| | 655 | else |
| | 656 | { |
| | 657 | $this->mustUploadSomething = true; |