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

[ResourceBundle] Default Form builder for PHPCR-ODM #5039

Merged
merged 5 commits into from
Jun 3, 2016

Conversation

dantleech
Copy link
Contributor

@dantleech dantleech commented May 16, 2016

Q A
Bug fix? no
New feature? yes
BC breaks? no
License MIT

This PR adds a DefaultFormBuilder for the PHPCR-ODM resource.

In addition, because of the tree nature of PHPCR I have added three event
listeners which: handle the default parent path, resolve name conflcits and
remove invalid characters from the node name.

These are configured in the resource config:

    resources:
        acme.post: 
            driver: doctrine/phpcr-odm,
            classes:
                model: Acme\Document\Post
            options:
                default_parent_path: /cms/foobar # set the parent path if none is provided
                autocreate: false                # autocreate non-existing parent paths
                force: false                     # always set the parent path.
                name_resolver: true              # resolve name conflcits
                name_filter: true                # filter invalid characters

'autocreate' => false,
],
$metadata->hasParameter('options') ? $metadata->getParameter('options') : []
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would be nice to have options handled in some way that provided defaults and disallowed specification of non-valid keys.

{
$classMetadata = $this->documentManager->getClassMetadata($metadata->getClass('model'));

// the field mappings should only contain standard value mappings
Copy link
Contributor Author

Choose a reason for hiding this comment

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

.. but sadly they don't ...

@dantleech dantleech changed the title [ResourceBundle][WIP]Form builder for PHPCR-ODM [ResourceBundle][WIP] Default Form builder for PHPCR-ODM May 16, 2016
$defaultFormBuilderDefinition->setArguments([
new Reference($metadata->getServiceId('manager')),
$options['default_parent_path'],
$options['autocreate']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There options only apply to the DefaultFormBuilder - which means that as soon as the user creates a custom form type these values become meaningless.

I wonder if these should be implemented as a PHPCR-ODM EventSubscribers instead.

@@ -17,6 +17,8 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Sylius\Bundle\ResourceBundle\Doctrine\ODM\PHPCR\EventListener\Subscriber\NameResolverListener;
use Sylius\Bundle\ResourceBundle\Doctrine\ODM\PHPCR\EventListener\Subscriber\DefaultPathListener;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

dd

@dantleech dantleech changed the title [ResourceBundle][WIP] Default Form builder for PHPCR-ODM [ResourceBundle] Default Form builder for PHPCR-ODM May 19, 2016
[
'default_parent_path' => null,
'autocreate' => false,
'force' => false,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rename to force_default_parent

@dantleech
Copy link
Contributor Author

Updated, refactored to have an event listener-per-resource and added specs. This is now ready-for-review.

- Automatic generation of form
- Option to specify default path
- Resolve node name conflicts and normalize the path
@dantleech
Copy link
Contributor Author

ping @pjedrzejewski

@pjedrzejewski
Copy link
Member

@dantleech Looks good to me! Waiting for last tweaks and it is good to go. 👍 Nice work! We will be using all the PHPCR stuff for grids and resources in the new admin, your work has been a huge help!

if ($diff = array_diff(array_keys($metadataOptions), array_keys($defaultOptions))) {
throw new InvalidArgumentException(sprintf(
'Unknown PHPCR-ODM configuration options: "%s"',
implode('", "', $diff)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed the options and added this sanity check.

@pjedrzejewski pjedrzejewski merged commit 62aa667 into Sylius:master Jun 3, 2016
@pjedrzejewski
Copy link
Member

Great work, thank you Dan! 👍

@dantleech
Copy link
Contributor Author

Thanks! I am currently working on a CMS which uses only Sylius Resource/Grid + Symfony CMF, with the aim of providing an alternative to Sonata Admin. So expect more contributions :)

pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
[ResourceBundle] Default Form builder for PHPCR-ODM
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

Successfully merging this pull request may close these issues.

None yet

3 participants