Skip to content

Commit

Permalink
Merge pull request #100 from w-vision/child-definitions
Browse files Browse the repository at this point in the history
Child definitions
  • Loading branch information
dpfaffenbauer authored Oct 31, 2018
2 parents ade5333 + a716e5c commit b65aed8
Show file tree
Hide file tree
Showing 24 changed files with 926 additions and 46 deletions.
2 changes: 2 additions & 0 deletions src/ImportDefinitionsBundle/Command/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
};

$eventDispatcher->addListener('import_definition.status', $imStatus);
$eventDispatcher->addListener('import_definition.status.child', $imStatus);
$eventDispatcher->addListener('import_definition.total', $imTotal);
$eventDispatcher->addListener('import_definition.progress', $imProgress);
$eventDispatcher->addListener('import_definition.finished', $imFinished);

$this->getContainer()->get('import_definition.importer')->doImport($definition, json_decode($params, true));

$eventDispatcher->removeListener('import_definition.status', $imStatus);
$eventDispatcher->removeListener('import_definition.status.child', $imStatus);
$eventDispatcher->removeListener('import_definition.total', $imTotal);
$eventDispatcher->removeListener('import_definition.progress', $imProgress);
$eventDispatcher->removeListener('import_definition.finished', $imFinished);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private function addPimcoreResourcesSection(ArrayNodeDefinition $node)
->ignoreExtraKeys(false)
->children()
->scalarNode('startup')->defaultValue('/bundles/importdefinitions/pimcore/js/startup.js')->end()
->scalarNode('resource_definition')->defaultValue('/bundles/importdefinitions/pimcore/js/resource/definition.js')->end()
->scalarNode('definition_panel')->defaultValue('/bundles/importdefinitions/pimcore/js/definition/panel.js')->end()
->scalarNode('definition_item')->defaultValue('/bundles/importdefinitions/pimcore/js/definition/item.js')->end()
->scalarNode('definition_config')->defaultValue('/bundles/importdefinitions/pimcore/js/definition/configDialog.js')->end()
Expand All @@ -103,6 +104,7 @@ private function addPimcoreResourcesSection(ArrayNodeDefinition $node)
->scalarNode('provider_external_sql')->defaultValue('/bundles/importdefinitions/pimcore/js/provider/externalSql.js')->end()
->scalarNode('provider_json')->defaultValue('/bundles/importdefinitions/pimcore/js/provider/json.js')->end()
->scalarNode('provider_xml')->defaultValue('/bundles/importdefinitions/pimcore/js/provider/xml.js')->end()
->scalarNode('provider_raw')->defaultValue('/bundles/importdefinitions/pimcore/js/provider/raw.js')->end()
->scalarNode('interpreter_abstract')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/abstract.js')->end()
->scalarNode('interpreter_href')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/href.js')->end()
->scalarNode('interpreter_multihref')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/multihref.js')->end()
Expand All @@ -119,6 +121,8 @@ private function addPimcoreResourcesSection(ArrayNodeDefinition $node)
->scalarNode('interpreter_object_resolver')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/objectresolver.js')->end()
->scalarNode('interpreter_mapping')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/mapping.js')->end()
->scalarNode('interpreter_iterator')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/iterator.js')->end()
->scalarNode('interpreter_definition')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/definition.js')->end()
->scalarNode('interpreter_conditional')->defaultValue('/bundles/importdefinitions/pimcore/js/interpreters/conditional.js')->end()
->scalarNode('setter_abstract')->defaultValue('/bundles/importdefinitions/pimcore/js/setters/abstract.js')->end()
->scalarNode('setter_fieldcollection')->defaultValue('/bundles/importdefinitions/pimcore/js/setters/fieldcollection.js')->end()
->scalarNode('setter_objectbrick')->defaultValue('/bundles/importdefinitions/pimcore/js/setters/objectbrick.js')->end()
Expand Down
60 changes: 60 additions & 0 deletions src/ImportDefinitionsBundle/Event/EventDispatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2017 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace ImportDefinitionsBundle\Event;

use CoreShop\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use CoreShop\Component\Resource\Metadata\MetadataInterface;
use CoreShop\Component\Resource\Model\ResourceInterface;
use ImportDefinitionsBundle\Model\DefinitionInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;

final class EventDispatcher implements EventDispatcherInterface
{
/**
* @var SymfonyEventDispatcherInterface
*/
private $eventDispatcher;

/**
* @param SymfonyEventDispatcherInterface $eventDispatcher
*/
public function __construct(SymfonyEventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}

/**
* {@inheritdoc}
*/
public function dispatch(DefinitionInterface $definition, $eventName, $subject = '', $params = [])
{
$event = $this->getEvent($definition, $subject, $params);

$this->eventDispatcher->dispatch(
sprintf('%s%s', $eventName, isset($params['child']) && $params['child'] ? '.child' : ''),
$event
);
}

/**
* @param DefinitionInterface $definition
* @param string $subject
* @param array $params
* @return ImportDefinitionEvent
*/
private function getEvent(DefinitionInterface $definition, $subject = '', $params = [])
{
return new ImportDefinitionEvent($definition, $subject, $params);
}
}
32 changes: 32 additions & 0 deletions src/ImportDefinitionsBundle/Event/EventDispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* CoreShop.
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2015-2017 Dominik Pfaffenbauer (https://www.pfaffenbauer.at)
* @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3)
*/

namespace ImportDefinitionsBundle\Event;

use CoreShop\Bundle\ResourceBundle\Event\ResourceControllerEvent;
use CoreShop\Component\Resource\Metadata\MetadataInterface;
use CoreShop\Component\Resource\Model\ResourceInterface;
use ImportDefinitionsBundle\Model\DefinitionInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;

interface EventDispatcherInterface
{
/**
* @param DefinitionInterface $definition
* @param $eventName
* @param string $subject
* @param array $params
* @return mixed
*/
public function dispatch(DefinitionInterface $definition, $eventName, $subject = '', $params = []);
}
17 changes: 16 additions & 1 deletion src/ImportDefinitionsBundle/Event/ImportDefinitionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ final class ImportDefinitionEvent extends Event
*/
protected $subject;

/**
* @var array
*/
protected $options;

/**
* @param DefinitionInterface $definition
* @param mixed $subject
* @param array $options
*/
public function __construct(DefinitionInterface $definition, $subject = null)
public function __construct(DefinitionInterface $definition, $subject = null, $options = [])
{
$this->definition = $definition;
$this->subject = $subject;
$this->options = $options;
}

/**
Expand All @@ -54,4 +61,12 @@ public function getSubject()
{
return $this->subject;
}

/**
* @return array
*/
public function getOptions()
{
return $this->options;
}
}
90 changes: 90 additions & 0 deletions src/ImportDefinitionsBundle/Form/Type/DefinitionChoiceType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Import Definitions.
*
* LICENSE
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
*/

namespace ImportDefinitionsBundle\Form\Type;

use CoreShop\Component\Resource\Repository\RepositoryInterface;
use ImportDefinitionsBundle\Model\DefinitionInterface;
use Symfony\Bridge\Doctrine\Form\DataTransformer\CollectionToArrayTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;

final class DefinitionChoiceType extends AbstractType
{
/**
* @var RepositoryInterface
*/
private $definitionRepository;

/**
* @param RepositoryInterface $definitionRepository
*/
public function __construct(RepositoryInterface $definitionRepository)
{
$this->definitionRepository = $definitionRepository;
}

/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['multiple']) {
$builder->addModelTransformer(new CollectionToArrayTransformer());
}
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults(
[
'choices' => function (Options $options) {
return array_map(function(DefinitionInterface $def) {
return $def->getId();
}, $this->definitionRepository->findAll());
},
'choice_label' => function($val) {
$def = $this->definitionRepository->find($val);

return $def->getName();
},
'choice_translation_domain' => false,
'active' => true,
]
);
}

/**
* {@inheritdoc}
*/
public function getParent()
{
return ChoiceType::class;
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'import_definitions_definition_choice';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Import Definitions.
*
* LICENSE
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
*/

namespace ImportDefinitionsBundle\Form\Type\Interpreter;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

final class ConditionalInterpreterType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('condition', TextType::class)
->add('true_interpreter', InterpreterType::class)
->add('false_interpreter', InterpreterType::class)
;
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'import_definitions_interpreter_conditional';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Import Definitions.
*
* LICENSE
*
* This source file is subject to the GNU General Public License version 3 (GPLv3)
* For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt
* files that are distributed with this source code.
*
* @copyright Copyright (c) 2016-2018 w-vision AG (https://www.w-vision.ch)
* @license https://github.com/w-vision/ImportDefinitions/blob/master/gpl-3.0.txt GNU General Public License version 3 (GPLv3)
*/

namespace ImportDefinitionsBundle\Form\Type\Interpreter;

use ImportDefinitionsBundle\Form\Type\ClassChoiceType;
use ImportDefinitionsBundle\Form\Type\DefinitionChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;

class DefinitionType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('definition', DefinitionChoiceType::class)
;
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'import_definitions_interpreter_definition';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace ImportDefinitionsBundle\Form\Type\Interpreter;

use ImportDefinitionsBundle\Form\Type\ClassChoiceType;
use ImportDefinitionsBundle\Form\Type\DefinitionChoiceType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
Expand All @@ -30,7 +31,8 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder
->add('class', ClassChoiceType::class)
->add('field', TextType::class)
->add('match_unpublished', CheckboxType::class);
->add('match_unpublished', CheckboxType::class)
;
}

/**
Expand Down
Loading

0 comments on commit b65aed8

Please sign in to comment.