Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Collection support #10

Merged
merged 1 commit into from
Aug 23, 2016
Merged

Collection support #10

merged 1 commit into from
Aug 23, 2016

Conversation

dantleech
Copy link
Collaborator

Support for storing collections.

For example:

Mapping:

    'mapping' => [
        Article::class => [
            'properties' => [
                'title' => [
                    'type' => 'text',
                ],
                'slideshow' => [
                    'type' => 'collection',
                ]
            ],
        ],


```php
$article = new Article();
$article->title = 'Hello World';
$article->slideshow = [ $image1, $image2, $image3 ];

$dm->persist($article);
$dm->flush();
| cmfct:slideshow-0    | nt:unstructured |                                                                             |
| | height             | LONG (3)        | 200                                                                         |
| | mimetype           | STRING (10)     | image/jpeg                                                                  |
| | path               | STRING (15)     | /path/to/image1                                                             |
| | width              | LONG (3)        | 100                                                                         |
| cmfct:slideshow-1    | nt:unstructured |                                                                             |
| | height             | LONG (3)        | 200                                                                         |
| | mimetype           | STRING (10)     | image/jpeg                                                                  |
| | path               | STRING (15)     | /path/to/image2                                                             |
| | width              | LONG (3)        | 100                                                                         |
| cmfct:slideshow-2    | nt:unstructured |                                                                             |
| : height             | LONG (3)        | 200                                                                         |
| : mimetype           | STRING (10)     | image/jpeg                                                                  |
| : path               | STRING (15)     | /path/to/image3                                                             |
| : width              | LONG (3)        | 100                                                                         |
| title                | STRING (5)      | Hello                                                                       |

$metadata->mapChildren([
'fieldName' => $fieldName,
'fetchDepth' => 1,
'filter' => 'cmfct:' . $fieldName . '-*',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use constant.

@dantleech dantleech force-pushed the collection_storage branch 6 times, most recently from 4a96bdb to 36464ae Compare July 24, 2016 21:04
];
}

public function getType($type)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing doc

@dantleech
Copy link
Collaborator Author

dantleech commented Jul 27, 2016

This is failing with SF 2.8 because of the Form changes.

In this PR we instantiate the form type (via a form extension) based on the model, e.g. $formFactory->get(MyContent::class) - it then returns a SurrogateType" This works fine on 3.0, but not in 2.8.

I thought about adding some BC hacks of our own, but then it is going to be some months (years?) before this is stable and 3.0 is already out.

I think we should pin this at 3.0. wdyt @wouterj @dbu ?

@dantleech dantleech force-pushed the collection_storage branch 3 times, most recently from 92b82a9 to 46726f5 Compare July 27, 2016 19:01
@dbu
Copy link

dbu commented Jul 28, 2016 via email

@wouterj
Copy link

wouterj commented Aug 3, 2016

2.8 should behave exactly the same as 3.0, can you please show where we need BC hacks here?

@dantleech
Copy link
Collaborator Author

@wouterj it is because of the BC hacks in 2.8. In 3.0 the extension is directly responsible for providing the form, and it can therefore return any type, in this case a SurrogateType which is a "dynamic" form type.

In 2.8 this is not possible.. Afraid I havn't got much time to look into it and remember exactly why now. But will try and have a look before merging this.

@dantleech
Copy link
Collaborator Author

dantleech commented Aug 20, 2016

@wouterj it is because the 2.8 system uses the class name of the object returned by the extension as the "type name". In this case that object is always of type SurrogateType.

The 3.* series will use the given name as the "form type", in this case Post::class, which means that when requesting a form for Post::class we will reveive a SurrogateType which is ready to add the fields configured for the Post::class as mapped in the content-type component.

In 2.8 we would never find a form type for Post::class as they would be regstered under SurrogateType "form name".

3.x allows us to request a form type for "X" and it doesn't matter what "X" is, and it doesn't matter what the form type is. In our case it can be dynamic and primed with the metadata for "X".

Does that sound OK?

/cc @webmozart

));
}

$surrogteType = new SurrogateType(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo $surrogteType

- Added CollectionField
- Support for storing collections in PHPCR-ODM
- Added form extension.
@dantleech
Copy link
Collaborator Author

Merging this now -- as for the method used to resolve the form type, I am not even sure it is the best solution, it might ultimately be better to have a dedicated form factory here at the cost of not being able to seamlessly integrate with things like the Sylius resource bundle. But lets see how things pan out.

@dantleech dantleech merged commit 81c2896 into master Aug 23, 2016
@dantleech dantleech deleted the collection_storage branch August 23, 2016 17:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants