dnagirl
dnagirl

Reputation: 20456

extending a bundle with additional services

I'm attempting to extend akeneo/MeasureBundle via the method described here. I've added a couple of methods to the MeasureManager and added a compiler pass to substitute my version of the MeasureManager for the original. This all works.

I've also created some custom form types: UnitFamiliesType, MeasurementType, UnitType. I want these to be services so I put them in my services.yml file which looks like this:

services:
  acrdMeas.form.measurement.type:
    class: ACRD\MeasureBundle\Form\Type\MeasurementType
    scope: prototype
    arguments: [ "@akeneo_measure.manager" ]  
    tags:
      - { name: form.type, alias: acrdMeas_measurement }
  acrdMeas.form.unitfamilies.type:
    class: ACRD\MeasureBundle\Form\Type\UnitFamilyType
    arguments: ["@akeneo_measure.manager"]
    tags:
      - { name: form.type, alias: acrdMeas_unitfamilies }
  acrdMeas.form.units.type:
    class: ACRD\MeasureBundle\Form\Type\UnitFamilyType
    arguments: ["@akeneo_measure.manager"]
    tags:
      - { name: form.type, alias: acrdMeas_units }

Unfortunately, these formtypes do not show up as services when I run app/console container:debug. Attempting to create a form with any of them results in a "Could not load type ..." error. I did test the form types by instantiating them directly via new and that worked fine.

Upvotes: 1

Views: 92

Answers (1)

dnagirl
dnagirl

Reputation: 20456

It turns out that extending the BundleExtension file is what works:

namespace ACRD\MeasureBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader;
use Akeneo\Bundle\MeasureBundle\DependencyInjection\AkeneoMeasureExtension as Extension;

class ACRDMeasureExtension extends Extension {

    public function load(array $configs, ContainerBuilder $container){
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
}

I'm not really clear why the child load() method doesn't clobber parent::load(), but it doesn't. But hopefully this helps someone.

Upvotes: 1

Related Questions