Example #1
0
 /**
  * Modify control config before control creation.
  *
  * @param IControlConfig $config
  * @return mixed
  */
 public function beforeCreateControl(IControlConfig $config)
 {
     foreach ($config->getConstraints() as $constraint) {
         if (!$constraint instanceof Constraint) {
             continue;
         }
         foreach ($this->constraints as $constraintName) {
             if (is_a($constraint, $this->constraintsNamespace . '\\' . $constraintName)) {
                 if (method_exists($this, $method = 'map' . $constraintName)) {
                     $this->{$method}($constraint, $config);
                 }
             }
         }
     }
 }
 /**
  * Opportunity to influence control after control creation.
  *
  * @param BaseControl    $control
  * @param IControlConfig $config
  * @return mixed
  */
 public function afterCreateControl(BaseControl $control, IControlConfig $config)
 {
     foreach ($config->getConstraints() as $constraint) {
         if (!$constraint instanceof Constraint) {
             continue;
         }
         foreach ($this->constraints as $constraintName) {
             if (is_a($constraint, $this->constraintsNamespace . '\\' . $constraintName)) {
                 if ($this->mapToNetteRules && method_exists($this, $method = 'mapToNette' . $constraintName)) {
                     $this->{$method}($constraint, $control);
                 } elseif (method_exists($this, $method = 'map' . $constraintName)) {
                     $this->{$method}($constraint, $control);
                 } else {
                     $this->mapDefault($constraint, $control);
                 }
             }
         }
     }
 }