Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Definition with checkbox type and multiple options #35

Closed
DavidG04 opened this issue Nov 16, 2015 · 2 comments
Closed

Definition with checkbox type and multiple options #35

DavidG04 opened this issue Nov 16, 2015 · 2 comments

Comments

@DavidG04
Copy link

Hi,

I use your bundle in my project with SonataAdminBundle. I create Admin class to populate a schema with definition and options. All it's ok but when i try to use a definition with multiple options an error occured on database persist.

In fact the system try to register an array in string value.

In AttributeSubscriber class the createValueField method transform checkbox definition in choice definition with multiple and expanded options to true. All it's ok to display the field but not to persist the data.

Maybe i will try to serialize the data before persist and deserialize in pre set data ?

if you want my admin code and my template, it's with pleasure.

Excuse me for my english but it's very poor.

@Padam87
Copy link
Owner

Padam87 commented Nov 16, 2015

Hi David,

I've created a PR for this. #36

I'm not quite ready to merge it yet, because of the varchar(255) type of the value field. This could run out on occasion. Upgrading it to text would result in performance loss.

You can use that branch if you want before I merge it :)

@DavidG04
Copy link
Author

thx

all it' ok, I just add a get method in the 'trait' to retrieve a value of attribute shortly

    /**
     * get an attribute value by this key
     *
     * @param string $string
     *
     * @return mixed
     */
    public function get($string)
    {
        $result = null;
        foreach ($this->getAttributes() as $attribute) {
            if ($string == $attribute->getDefinition()->getName()) {
                $result = $attribute->getValue();
            }
        }

        return $result;
    }

the call

$valueAttribute = $myObject->get('keyAttribute');

thank's again for this PR, and i try to send the admin code quickly :)

@DavidG04 DavidG04 closed this as completed Dec 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants