Suggestion for form view helper

classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Suggestion for form view helper

Ralf Eggert
Hi,

I really loved the easy rendering of forms in ZF1. With ZF2 I need to do
a little more work. At least write custom view helpers based on the
standard view helpers.

But for easy-to-use forms why not add a automatic rendering for a form
when it is passed to the form view helper:

$this->form($myForm);

This could be done like this (untested):

----------------------------------------------------------------------
public function renderForm($form)
{
    $output = $this->openTag($form);

    foreach ($form as $element) {
        if ($element instanceof Fieldset) {
            $output.= $this->getView()->formCollection($fieldset);
        } else {
            $output.= $this->getView()->formRow($fieldset);
        }
    }

    $output.= $this->closeTag();
}
----------------------------------------------------------------------

So, with this it will be quite easy to show beginners a rendered form
with a one-liner. If you want the flexibility, then you can build the
form step by step with all the other view helpers.

Regards,

Ralf


Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

rwrz
They did this to "DESINTEGRATE" the Decorators! =)


On Tue, Dec 11, 2012 at 4:25 PM, Ralf Eggert <[hidden email]> wrote:
Hi,

I really loved the easy rendering of forms in ZF1. With ZF2 I need to do
a little more work. At least write custom view helpers based on the
standard view helpers.

But for easy-to-use forms why not add a automatic rendering for a form
when it is passed to the form view helper:

$this->form($myForm);

This could be done like this (untested):

----------------------------------------------------------------------
public function renderForm($form)
{
    $output = $this->openTag($form);

    foreach ($form as $element) {
        if ($element instanceof Fieldset) {
            $output.= $this->getView()->formCollection($fieldset);
        } else {
            $output.= $this->getView()->formRow($fieldset);
        }
    }

    $output.= $this->closeTag();
}
----------------------------------------------------------------------

So, with this it will be quite easy to show beginners a rendered form
with a one-liner. If you want the flexibility, then you can build the
form step by step with all the other view helpers.

Regards,

Ralf



Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

weierophinney
Administrator
In reply to this post by Ralf Eggert
On Tue, Dec 11, 2012 at 12:25 PM, Ralf Eggert <[hidden email]> wrote:

> I really loved the easy rendering of forms in ZF1. With ZF2 I need to do
> a little more work. At least write custom view helpers based on the
> standard view helpers.
>
> But for easy-to-use forms why not add a automatic rendering for a form
> when it is passed to the form view helper:
>
> $this->form($myForm);
>
> This could be done like this (untested):
>
> ----------------------------------------------------------------------
> public function renderForm($form)
> {
>     $output = $this->openTag($form);
>
>     foreach ($form as $element) {
>         if ($element instanceof Fieldset) {
>             $output.= $this->getView()->formCollection($fieldset);
>         } else {
>             $output.= $this->getView()->formRow($fieldset);
>         }
>     }
>
>     $output.= $this->closeTag();
> }
> ----------------------------------------------------------------------
>
> So, with this it will be quite easy to show beginners a rendered form
> with a one-liner. If you want the flexibility, then you can build the
> form step by step with all the other view helpers.

Looks pretty cool. Give me a PR for it, and I'll add it to 2.1. :)



--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Ralf Eggert
Hi Matthew,

done:

https://github.com/zendframework/zf2/pull/3203

Unfortunately, I mixed it up with a former PR. How can I fix this?

Anyway, I added the feature and wrote a small unit test for it. I am not
sure if this unit test is sufficient.

Please advise.

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Marco Pivetta
Heya Ralph,

You can cherry-pick commit 9174dd1 in a new branch rebased on master.




On 11 December 2012 22:42, Ralf Eggert <[hidden email]> wrote:
Hi Matthew,

done:

https://github.com/zendframework/zf2/pull/3203

Unfortunately, I mixed it up with a former PR. How can I fix this?

Anyway, I added the feature and wrote a small unit test for it. I am not
sure if this unit test is sufficient.

Please advise.

Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Ralf Eggert
Hi Marco,

> You can cherry-pick commit |9174dd1
> <https://github.com/RalfEggert/zf2/commit/9174dd10b1896a93563b1d53b29709b8c0db9641>|
> in a new branch rebased on master.

Could you provide more information. I don't really know how to do it.

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Sascha-Oliver Prolic


2012/12/12 Ralf Eggert <[hidden email]>
9174dd1

Hi Ralf,

very easy:
git checkout -b newbranch zf2/master
git cherry-pick 9174dd1
....
git push origin newbranch:yourrepolocation

--
Sascha-Oliver Prolic
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Ralf Eggert
Hi,

I tried the way Tomas suggested

> something like (assuming your master is up to date)
>
> git checkout master
> git branch some-branch
> git checkout some-branch
> git cherry-pick 1a2b3c4d

But what now? The PR is still mixed with the two commits which should be
split up. How can I get 9174dd1 out of it and create a separate PR for it?

The way Sascha suggested failed:

> fatal: git checkout: updating paths is incompatible with switching branches.
> Did you intend to checkout 'zf2/master' which can not be resolved as commit?

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Sascha-Oliver Prolic
Ralf:

If you cherry-picked your commit, you can push it to your github account with the --force flag.


2012/12/13 Ralf Eggert <[hidden email]>
Hi,

I tried the way Tomas suggested

> something like (assuming your master is up to date)
>
> git checkout master
> git branch some-branch
> git checkout some-branch
> git cherry-pick 1a2b3c4d

But what now? The PR is still mixed with the two commits which should be
split up. How can I get 9174dd1 out of it and create a separate PR for it?

The way Sascha suggested failed:

> fatal: git checkout: updating paths is incompatible with switching branches.
> Did you intend to checkout 'zf2/master' which can not be resolved as commit?

Regards,

Ralf



--
Sascha-Oliver Prolic
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Tomáš Fejfar
I would use 

git checkout pullrequested-branch // now you are on the old branch
git reset --hard new-branch // now is your PR'd branch reset to where your new branch with cherrypicked commit is
git push origin --force // normal push as you did before, but with --force that would overwrite anything there was in your PR with the current contents of the branch

Tomas Fejfar, w3w.cz

twitter: @tomasfejfar
email: [hidden email]
www: http://www.tomasfejfar.cz




On Thu, Dec 13, 2012 at 10:38 AM, Sascha-Oliver Prolic <[hidden email]> wrote:
Ralf:

If you cherry-picked your commit, you can push it to your github account with the --force flag.


2012/12/13 Ralf Eggert <[hidden email]>
Hi,

I tried the way Tomas suggested

> something like (assuming your master is up to date)
>
> git checkout master
> git branch some-branch
> git checkout some-branch
> git cherry-pick 1a2b3c4d

But what now? The PR is still mixed with the two commits which should be
split up. How can I get 9174dd1 out of it and create a separate PR for it?

The way Sascha suggested failed:

> fatal: git checkout: updating paths is incompatible with switching branches.
> Did you intend to checkout 'zf2/master' which can not be resolved as commit?

Regards,

Ralf



--
Sascha-Oliver Prolic

Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Ralf Eggert
Hi Tomas,

> git checkout pullrequested-branch // now you are on the old branch

What do you mean with pullrequested-branch? I currently have a master
and a tempbranch.

> git reset --hard new-branch // now is your PR'd branch reset to where
> your new branch with cherrypicked commit is
> git push origin --force // normal push as you did before, but with
> --force that would overwrite anything there was in your PR with the
> current contents of the branch

I still feel a little lost.

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Marco Pivetta
Oh... you did the pull request from master...

As a suggestion, don't do that anymore. You usually create a new branch for any pull request (otherwise, things like these happen), so that every feature/fix has its own branch.

I'd suggest closing the PR and making a new one with a new based on zf2/master branch :)




On 13 December 2012 17:23, Ralf Eggert <[hidden email]> wrote:
Hi Tomas,

> git checkout pullrequested-branch // now you are on the old branch

What do you mean with pullrequested-branch? I currently have a master
and a tempbranch.

> git reset --hard new-branch // now is your PR'd branch reset to where
> your new branch with cherrypicked commit is
> git push origin --force // normal push as you did before, but with
> --force that would overwrite anything there was in your PR with the
> current contents of the branch

I still feel a little lost.

Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Ralf Eggert
Hi Marco,

> Oh... you did the pull request from master...
>
> As a suggestion, don't do that anymore. You usually create a new branch
> for any pull request (otherwise, things like these happen), so that
> every feature/fix has its own branch.
>
> I'd suggest closing the PR and making a new one with a new based on
> zf2/master branch :)

Ok, did not know that. Git / Github and working with branches is still
all new to me.

But when I close the PR what will happen to the other commit?

  https://github.com/RalfEggert/zf2/commit/d39307a

About the branches. Is this the right way to do it?

  git checkout -b mynewbranch
  git commit -a -m "New fix"
  git push
  git checkout master

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Ludwig Ruderstaller
In reply to this post by Marco Pivetta
Hi,

i really can reccomend Git-Flow

http://nvie.com/posts/a-successful-git-branching-model/
http://nvie.com/posts/an-upgrade-of-gitflow/

br
ludwig aka rufinus


Am 13.12.2012 17:25, schrieb Marco Pivetta:

> Oh... you did the pull request from master...
>
> As a suggestion, don't do that anymore. You usually create a new branch
> for any pull request (otherwise, things like these happen), so that
> every feature/fix has its own branch.
>
> I'd suggest closing the PR and making a new one with a new based on
> zf2/master branch :)
>
> Marco Pivetta
>
> http://twitter.com/Ocramius     
>
> http://ocramius.github.com/
>
>
>
> On 13 December 2012 17:23, Ralf Eggert <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Hi Tomas,
>
>     > git checkout pullrequested-branch // now you are on the old branch
>
>     What do you mean with pullrequested-branch? I currently have a master
>     and a tempbranch.
>
>     > git reset --hard new-branch // now is your PR'd branch reset to where
>     > your new branch with cherrypicked commit is
>     > git push origin --force // normal push as you did before, but with
>     > --force that would overwrite anything there was in your PR with the
>     > current contents of the branch
>
>     I still feel a little lost.
>
>     Regards,
>
>     Ralf
>
>


--
Ludwig Ruderstaller
http://www.cwd.at
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Marco Pivetta
In reply to this post by Ralf Eggert
Yes, but the branch should be based off ZF2's master.

Assuming you're having "zf2" as a remote for the official repo:

git checkout zf2/master
git checkout -b feature-branch-name-here
git cherry-pick 9174dd1
git push origin feature-branch-name-here

And then open a PR from RalfEggert:zf2/feature-branch-name-here to zendframework/zf2:master


Anything you do on pull requests on Github shouldn't affect your branches. Remember that with GIT, even if you completely delete a repo on Github, your local one is still valid and can be cloned/pulled/etc...





On 13 December 2012 17:38, Ralf Eggert <[hidden email]> wrote:
Hi Marco,

> Oh... you did the pull request from master...
>
> As a suggestion, don't do that anymore. You usually create a new branch
> for any pull request (otherwise, things like these happen), so that
> every feature/fix has its own branch.
>
> I'd suggest closing the PR and making a new one with a new based on
> zf2/master branch :)

Ok, did not know that. Git / Github and working with branches is still
all new to me.

But when I close the PR what will happen to the other commit?

  https://github.com/RalfEggert/zf2/commit/d39307a

About the branches. Is this the right way to do it?

  git checkout -b mynewbranch
  git commit -a -m "New fix"
  git push
  git checkout master

Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Tomáš Fejfar
Ahw. That did not occur to me, that you have pullrequested from master ;)

Just in case you don't have zf2 repo as remote (use "git remote" to see list of your remotes) - you need to add it. 

git remote add zf2 [hidden email]:zendframework/zf2.git

I'm not sure if it's the same with ZF2 workflow, but it's kind of a norm (and many tutorials name it that way) to name your fork remote "origin" (that's defaultly created when you use git clone) and call the repo you forked from "upstream". So you would replace "zf2" with "upstream" in both the command above and Marco's snippet. 

git remote add upstream [hidden email]:zendframework/zf2.git

Tomas Fejfar, w3w.cz

twitter: @tomasfejfar
email: [hidden email]
www: http://www.tomasfejfar.cz




On Thu, Dec 13, 2012 at 5:41 PM, Marco Pivetta <[hidden email]> wrote:
Yes, but the branch should be based off ZF2's master.

Assuming you're having "zf2" as a remote for the official repo:

git checkout zf2/master
git checkout -b feature-branch-name-here
git cherry-pick 9174dd1
git push origin feature-branch-name-here

And then open a PR from RalfEggert:zf2/feature-branch-name-here to zendframework/zf2:master


Anything you do on pull requests on Github shouldn't affect your branches. Remember that with GIT, even if you completely delete a repo on Github, your local one is still valid and can be cloned/pulled/etc...

On 13 December 2012 17:38, Ralf Eggert <[hidden email]> wrote:
Hi Marco,

> Oh... you did the pull request from master...
>
> As a suggestion, don't do that anymore. You usually create a new branch
> for any pull request (otherwise, things like these happen), so that
> every feature/fix has its own branch.
>
> I'd suggest closing the PR and making a new one with a new based on
> zf2/master branch :)

Ok, did not know that. Git / Github and working with branches is still
all new to me.

But when I close the PR what will happen to the other commit?

  https://github.com/RalfEggert/zf2/commit/d39307a

About the branches. Is this the right way to do it?

  git checkout -b mynewbranch
  git commit -a -m "New fix"
  git push
  git checkout master

Regards,

Ralf


Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Tomáš Fejfar
For further reference: 

Feel free to suggest changes. 

Tomas Fejfar, w3w.cz

twitter: @tomasfejfar
email: [hidden email]
www: http://www.tomasfejfar.cz




On Thu, Dec 13, 2012 at 8:51 PM, Tomáš Fejfar <[hidden email]> wrote:
Ahw. That did not occur to me, that you have pullrequested from master ;)

Just in case you don't have zf2 repo as remote (use "git remote" to see list of your remotes) - you need to add it. 

git remote add zf2 [hidden email]:zendframework/zf2.git

I'm not sure if it's the same with ZF2 workflow, but it's kind of a norm (and many tutorials name it that way) to name your fork remote "origin" (that's defaultly created when you use git clone) and call the repo you forked from "upstream". So you would replace "zf2" with "upstream" in both the command above and Marco's snippet. 

git remote add upstream [hidden email]:zendframework/zf2.git

Tomas Fejfar, w3w.cz

twitter: @tomasfejfar
email: [hidden email]
www: http://www.tomasfejfar.cz




On Thu, Dec 13, 2012 at 5:41 PM, Marco Pivetta <[hidden email]> wrote:
Yes, but the branch should be based off ZF2's master.

Assuming you're having "zf2" as a remote for the official repo:

git checkout zf2/master
git checkout -b feature-branch-name-here
git cherry-pick 9174dd1
git push origin feature-branch-name-here

And then open a PR from RalfEggert:zf2/feature-branch-name-here to zendframework/zf2:master


Anything you do on pull requests on Github shouldn't affect your branches. Remember that with GIT, even if you completely delete a repo on Github, your local one is still valid and can be cloned/pulled/etc...

On 13 December 2012 17:38, Ralf Eggert <[hidden email]> wrote:
Hi Marco,

> Oh... you did the pull request from master...
>
> As a suggestion, don't do that anymore. You usually create a new branch
> for any pull request (otherwise, things like these happen), so that
> every feature/fix has its own branch.
>
> I'd suggest closing the PR and making a new one with a new based on
> zf2/master branch :)

Ok, did not know that. Git / Github and working with branches is still
all new to me.

But when I close the PR what will happen to the other commit?

  https://github.com/RalfEggert/zf2/commit/d39307a

About the branches. Is this the right way to do it?

  git checkout -b mynewbranch
  git commit -a -m "New fix"
  git push
  git checkout master

Regards,

Ralf



Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Ralf Eggert
In reply to this post by Marco Pivetta
Hi Marco,

I tried your suggested way but it all ended in a bigger mess:

https://github.com/zendframework/zf2/pull/3239

Regards,

Ralf
Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Tomáš Fejfar
//accidentaly missed reply-all

Probably because you did not create your branch from master? So you have everything you had before AND the cherry picked revision:

master---commit 1---commit 2 //wrong branch
                        \--- cherry picked  //new branch

Where you would need

master---commit 1---commit 2 //wrong branch
      \--- cherry picked  //new branch

You can use "git checkout -b fix-something master" to branch from master (see http://blog.tomasfejfar.cz/159-how-to-contribute-to-zf2)

Tomas Fejfar, w3w.cz

twitter: @tomasfejfar
email: [hidden email]
www: http://www.tomasfejfar.cz




On Mon, Dec 17, 2012 at 7:48 PM, Ralf Eggert <[hidden email]> wrote:
Hi Marco,

I tried your suggested way but it all ended in a bigger mess:

https://github.com/zendframework/zf2/pull/3239

Regards,

Ralf

Reply | Threaded
Open this post in threaded view
|

Re: Suggestion for form view helper

Andreas Möller
In reply to this post by Ralf Eggert
Hello Ralf,


Ok, did not know that. Git / Github and working with branches is still
all new to me.

Maybe this helps:



Best regards,

Andreas
12