/**
  * Build a data definition and store it into the environments container.
  *
  * @param \ContaoCommunityAlliance\DcGeneral\DataDefinition\ContainerInterface $container
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function build(ContainerInterface $container, BuildDataDefinitionEvent $event)
 {
     if (!$this->loadDca($container->getName(), $this->getDispatcher())) {
         return;
     }
     if ($container->hasDefinition(PalettesDefinitionInterface::NAME)) {
         $palettesDefinition = $container->getDefinition(PalettesDefinitionInterface::NAME);
     } else {
         $palettesDefinition = new DefaultPalettesDefinition();
         $container->setDefinition(PalettesDefinitionInterface::NAME, $palettesDefinition);
     }
     $parser = new LegacyPalettesParser();
     $selectorFieldNames = (array) $this->getFromDca('palettes/__selector__');
     $palettesDca = (array) $this->getFromDca('metapalettes');
     $subPalettesDca = (array) $this->getFromDca('metasubpalettes');
     $subSelectPalettesDca = (array) $this->getFromDca('metasubselectpalettes');
     // extend the selector field names with subpalettes field names
     $selectorFieldNames = array_merge($selectorFieldNames, array_keys($subPalettesDca));
     $subSelectPalettes = $this->parseSubSelectPalettes($subSelectPalettesDca);
     $subPalettes = $this->parseSubPalettes($parser, $subPalettesDca, $selectorFieldNames);
     $palettes = $this->parsePalettes($palettesDefinition, $parser, $palettesDca, $subPalettes, $subSelectPalettes, $selectorFieldNames);
     if (empty($palettes)) {
         return;
     }
     $palettesDefinition->addPalettes($palettes);
 }
 /**
  * Parse the defined palettes and populate the definition.
  *
  * @param ContainerInterface $container The container where the data shall be stored.
  *
  * @return void
  *
  * @SuppressWarnings(PHPMD.LongVariable)
  */
 protected function parsePalettes(ContainerInterface $container)
 {
     $palettesDefinitionArray = $this->getFromDca('palettes');
     $subPalettesDefinitionArray = $this->getFromDca('subpalettes');
     // Skip while there is no legacy palette definition.
     if (!is_array($palettesDefinitionArray)) {
         return;
     }
     // Ignore non-legacy sub palette definition.
     if (!is_array($subPalettesDefinitionArray)) {
         $subPalettesDefinitionArray = array();
     }
     if ($container->hasDefinition(PalettesDefinitionInterface::NAME)) {
         $palettesDefinition = $container->getDefinition(PalettesDefinitionInterface::NAME);
     } else {
         $palettesDefinition = new DefaultPalettesDefinition();
         $container->setDefinition(PalettesDefinitionInterface::NAME, $palettesDefinition);
     }
     $palettesParser = new LegacyPalettesParser();
     $palettesParser->parse($palettesDefinitionArray, $subPalettesDefinitionArray, $palettesDefinition);
 }
 /**
  * Parse and build the backend view definition for the old Contao2 backend view.
  *
  * This method expects to find an instance of Contao2BackendViewDefinitionInterface in the container.
  *
  * @param ContainerInterface $container The container where the data shall be stored.
  *
  * @return void
  *
  * @throws DcGeneralInvalidArgumentException If the stored definition in the container is of invalid type.
  */
 protected function parseBackendView(ContainerInterface $container)
 {
     if ($container->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)) {
         $view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
     } else {
         $view = new Contao2BackendViewDefinition();
         $container->setDefinition(Contao2BackendViewDefinitionInterface::NAME, $view);
     }
     if (!$view instanceof Contao2BackendViewDefinitionInterface) {
         throw new DcGeneralInvalidArgumentException('Configured BackendViewDefinition does not implement Contao2BackendViewDefinitionInterface.');
     }
     $this->parseListing($view);
 }