/** * Add a custom condition to last created palette. * * @param PaletteConditionInterface $condition The condition to add. * * @return void * * @throws DcGeneralRuntimeException If the palette is missing. */ protected function addPaletteCondition(PaletteConditionInterface $condition) { if (!$this->palette) { throw new DcGeneralRuntimeException('Palette is missing, please create a palette first'); } $event = new AddConditionEvent($condition, $this->palette, $this); $this->dispatchEvent($event); $condition = $event->getCondition(); $previousCondition = $this->palette->getCondition(); if (!$previousCondition) { $this->palette->setCondition($condition); } elseif ($previousCondition instanceof PropertyConditionChain) { $previousCondition->addCondition($condition); } else { $chain = $this->paletteConditionChainClass->newInstance(); $chain->addCondition($previousCondition); $chain->addCondition($condition); $this->palette->setCondition($chain); } }