Skip to main content

Extending Form Builder

As Form Builder relies on Symfony, the best approach for extending it is to add a Symfony bundle, where all custom code can live. This ensures that custom code can use Symfony's service loading to register custom extensions without database changes.

In this section, our example custom bundle will live at Jadu\Custom\CustomXFormsProBundle.

Steps to create a Bundle

  • Create a folder - /path/to/jadu/jadu/custom/CustomXFormsProBundle
  • Add a file into this folder, called CustomXFormsProBundle.php:
namespace Jadu\Custom\CustomXFormsProBundle;

use Jadu\Symfony\Kernel\Bundle\Bundle;

class CustomXFormsProBundle extends Bundle
{
}

This file (and the class it contains) determine the name of the Bundle. This is usually the same as the name of the bundle's folder, which, in this example, is CustomXFormsProBundle.

  • Create a sub folder within the bundle called DependencyInjection. The full path to this should be /path/to/jadu/jadu/custom/CustomXFormsProBundle/DependencyInjection
  • In this sub folder, create a new class called CustomXFormsProExtension in the file CustomXFormsProExtension.php:
namespace Jadu\Custom\CustomXFormsProBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class CustomXFormsProExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}

Registering the bundle

Once we have created our custom bundle, we need to register it. This is achieved by creating a new file, /path/to/jadu/config/bundles.xml:

<?xml version="1.0" encoding="utf-8"?>
<bundles xmlns:config="http://www.jadu.co.uk/schema/config">
<core config:type="array"/>
<cc config:type="array">
<item key="custom.xfp">Jadu\Custom\CustomXFormsProBundle\CustomXFormsProBundle</item>
</cc>
<frontend config:type="array">
<item key="custom.xfp">Jadu\Custom\CustomXFormsProBundle\CustomXFormsProBundle</item>
</frontend>
</bundles>

This file registers the bundle definition, and loads it in the Control Center and on the front end. These are the correct places to load the bundle for Jadu Central forms, as they do not support Galaxies Sites.

The bundles.xml file can either be placed under version control and included in Meteor patches, or be created/modified by a filesystem migration.