You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
namespace Zitec\RuleEngineBundle\Admin;
use Zitec\RuleEngineBundle\DoctrineBehaviors\PreconditionInterface;use Zitec\RuleEngineBundle\DoctrineBehaviors\RuleInterface;use Zitec\RuleEngineBundle\Service\RuleConditionsManager;use Zitec\RuleEngineBundle\Service\RuleJsonConverter;use Sonata\AdminBundle\Datagrid\ListMapper;use Sonata\AdminBundle\Form\FormMapper;use Sonata\AdminBundle\Form\Type\AdminType;use Sonata\AdminBundle\Form\Type\CollectionType;
/** * Class RuleAdminTrait * A trait that should be used in Sonata Admin classes for RuleEngine-aware entities. */trait PreconditionAdminTrait{ /** * @param PreconditionInterface $subject * @return array */ public function formatPrecondition(PreconditionInterface $subject) { $ruleManager = $this->getRuleManager($subject); $formatter = new RuleJsonConverter(); if($subject->getPrecondition()===null){ return $formatter->formatForDisplay('{}', $ruleManager); } return $formatter->formatForDisplay($subject->getPrecondition()->getJson(), $ruleManager); }
/** * @param FormMapper $formMapper * @param array $options */ protected function addPreconditionFormElement(FormMapper $formMapper, array $options = []) { $ruleManager = $this->getRuleManager(); $options = $options + ['label' => false];
$formMapper->add('precondition', AdminType::class, $options, ['rule_manager' => $ruleManager,'admin_code' => 'precondition.admin']); }
/** * @param ListMapper $list */ protected function addPreconditionListColumns(ListMapper $list) { $list->add('precondition.name') ->add('precondition.active', 'boolean', ['editable' => true]) ->add('precondition', null, ['template' => 'ZitecRuleEngineBundle:Admin:json_precondition_field.html.twig']); // In dev environment, display the expression too.
if ($this->getConfigurationPool()->getContainer()->has('kernel.debug')) {
$list->add('precondition.expression', null, ['header_style' => 'width: 20%; text-align: center']); } }
}
|