Added ability to define custom element options #1893

Merged
merged 8 commits into from Jul 20, 2012

Conversation

Projects
None yet
5 participants
@ghost
Contributor

ghost commented Jul 15, 2012

added $options property with appropriate getters and setters to allow for adding of custom options to an element.

This allows the user to then add additional data that can then be utilised in other ways and makes form elemets much more flexible for personal implementations

e.g. $this->add(array(
    'name'  => 'name',
    'attributes' => array(
        'type' => 'text',
    ),
    'options' => array(
        'label' => 'Name',
        'description' => 'The name of the domain', // not currently handled 
    ),
));

phpboyscout added some commits Jul 15, 2012

Added storage for custom element options
added $options property with appropriate getters and setters
to allow for adding of custom options to an element.
@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request fails (merged 0116a92 into d6b0afe).

This pull request fails (merged 0116a92 into d6b0afe).

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request fails (merged 8ac7346 into d6b0afe).

This pull request fails (merged 8ac7346 into d6b0afe).

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request fails (merged 5e847c2 into d6b0afe).

This pull request fails (merged 5e847c2 into d6b0afe).

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request passes (merged 38f2296 into d6b0afe).

This pull request passes (merged 38f2296 into d6b0afe).

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request passes (merged 0b69f2d into d6b0afe).

This pull request passes (merged 0b69f2d into d6b0afe).

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request fails (merged de1d8c9 into d6b0afe).

This pull request fails (merged de1d8c9 into d6b0afe).

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request passes (merged 4c8ffb7 into d6b0afe).

This pull request passes (merged 4c8ffb7 into d6b0afe).

+ *
+ * @return array()
+ */
+ public function getOptions()

This comment has been minimized.

@weierophinney

weierophinney Jul 16, 2012

Member

This method should be added to ElementInterface.

@weierophinney

weierophinney Jul 16, 2012

Member

This method should be added to ElementInterface.

This comment has been minimized.

@ghost

ghost Jul 16, 2012

Contributor

have added to ElementInterface

@ghost

ghost Jul 16, 2012

Contributor

have added to ElementInterface

+ * @param string $option
+ * @return NULL|multitype:
+ */
+ public function getOption($option)

This comment has been minimized.

@weierophinney

weierophinney Jul 16, 2012

Member

This method should be added to ElementInterface.

@weierophinney

weierophinney Jul 16, 2012

Member

This method should be added to ElementInterface.

This comment has been minimized.

@ghost

ghost Jul 16, 2012

Contributor

have added to ElementInterface

@ghost

ghost Jul 16, 2012

Contributor

have added to ElementInterface

@travisbot

This comment has been minimized.

Show comment
Hide comment
@travisbot

travisbot Jul 16, 2012

This pull request passes (merged b9731fc into d6b0afe).

This pull request passes (merged b9731fc into d6b0afe).

@bakura10

This comment has been minimized.

Show comment
Hide comment
@bakura10

bakura10 Jul 16, 2012

Contributor

When this would be useful exactly ? Why not creating a new element if you need specific options ?

Contributor

bakura10 commented Jul 16, 2012

When this would be useful exactly ? Why not creating a new element if you need specific options ?

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Jul 16, 2012

Contributor

The main reason I implemented this change is due to some view helpers I'm creating to allow easier rendering using twitters bootstrap.

https://github.com/zucchi/Zucchi-Framework/tree/master/src/Zucchi/Form/View/Helper

I shouldn't have to create a whole new element to add some prettyness.

This then allows me to add some data programatically to my element that can then be used elsewhere.

This results in me being able to define an element such as

    $this->add(array(
        'name'  => 'price',
        'attributes' => array(
            'type' => 'text',
            'required' => 'required',
            'placeholder' => '9.99',
        ),
        'options' => array(
            'label' => 'Price',
            'bootstrap' => array( // options for bootstrap form
                'help' => array(
                    'style' => 'block',
                    'content' => 'The price of the product',
                ),
                'prepend' => array('$'),
                'append => array('c'),
            )
        ),
    ));

which can then be consumed by my view helpers to generate complex bootstrap style forms.

I'm pretty sure that there will be other use cases.

My main concern is that without having the ability to define arbitrary "options" we are then closing off the way that the elements work and can be used/manipulated, meaning it is not easy to do some pretty straight forward things without having to subclass tons of elements.

Once this PR is accepted I'll be putting out a blog about it to go into more detail

Contributor

ghost commented Jul 16, 2012

The main reason I implemented this change is due to some view helpers I'm creating to allow easier rendering using twitters bootstrap.

https://github.com/zucchi/Zucchi-Framework/tree/master/src/Zucchi/Form/View/Helper

I shouldn't have to create a whole new element to add some prettyness.

This then allows me to add some data programatically to my element that can then be used elsewhere.

This results in me being able to define an element such as

    $this->add(array(
        'name'  => 'price',
        'attributes' => array(
            'type' => 'text',
            'required' => 'required',
            'placeholder' => '9.99',
        ),
        'options' => array(
            'label' => 'Price',
            'bootstrap' => array( // options for bootstrap form
                'help' => array(
                    'style' => 'block',
                    'content' => 'The price of the product',
                ),
                'prepend' => array('$'),
                'append => array('c'),
            )
        ),
    ));

which can then be consumed by my view helpers to generate complex bootstrap style forms.

I'm pretty sure that there will be other use cases.

My main concern is that without having the ability to define arbitrary "options" we are then closing off the way that the elements work and can be used/manipulated, meaning it is not easy to do some pretty straight forward things without having to subclass tons of elements.

Once this PR is accepted I'll be putting out a blog about it to go into more detail

@weierophinney

This comment has been minimized.

Show comment
Hide comment
@weierophinney

weierophinney Jul 16, 2012

Member

@bakura10 I think it's reasonable, particularly considering the "description" use case.

Member

weierophinney commented Jul 16, 2012

@bakura10 I think it's reasonable, particularly considering the "description" use case.

@bakura10

This comment has been minimized.

Show comment
Hide comment
@bakura10

bakura10 Jul 16, 2012

Contributor

Let's go for it, so :).

Contributor

bakura10 commented Jul 16, 2012

Let's go for it, so :).

@weierophinney weierophinney merged commit b9731fc into zendframework:master Jul 20, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment