/** * Get the widget instance. * * @param string $fieldName The property name. * * @param string $serializedId The serialized id of the model. * * @param string $propertyValue The property value. * * @return \Widget */ protected function getWidget($fieldName, $serializedId, $propertyValue) { $environment = $this->getEnvironment(); $property = $environment->getDataDefinition()->getPropertiesDefinition()->getProperty($fieldName); $propertyValues = new PropertyValueBag(); if ($serializedId !== null) { $model = $this->getModelFromSerializedId($serializedId); } else { $dataProvider = $environment->getDataProvider(); $model = $dataProvider->getEmptyModel(); } $widgetManager = new ContaoWidgetManager($environment, $model); // Process input and update changed properties. $treeType = substr($property->getWidgetType(), 0, 4); $propertyValue = $this->getTreeValue($treeType, $propertyValue); if ($treeType == 'file' || $treeType == 'page') { $extra = $property->getExtra(); if (is_array($propertyValue) && !isset($extra['multiple'])) { $propertyValue = $propertyValue[0]; } else { $propertyValue = implode(',', (array) $propertyValue); } } $propertyValues->setPropertyValue($fieldName, $propertyValue); $widgetManager->processInput($propertyValues); $model->setProperty($fieldName, $propertyValues->getPropertyValue($fieldName)); $widget = $widgetManager->getWidget($fieldName); return $widget; }
public function testGetMatch() { $condition = new PaletteConditionChain(); $condition->setConjunction(PaletteConditionChain::AND_CONJUNCTION); $condition->addCondition(new PropertyValueCondition('prop1', '0')); $condition->addCondition(new PropertyValueCondition('prop2', '1')); $this->assertEquals(0, $condition->getMatchCount()); $model = new DefaultModel(); $model->setProperty('prop1', '0'); $model->setProperty('prop2', '1'); $this->assertEquals(2, $condition->getMatchCount($model)); $model->setProperty('prop2', '0'); $this->assertEquals(0, $condition->getMatchCount($model)); $propertyValueBag = new PropertyValueBag(); $propertyValueBag->setPropertyValue('prop1', '0'); $propertyValueBag->setPropertyValue('prop2', '1'); $this->assertEquals(2, $condition->getMatchCount(null, $propertyValueBag)); $propertyValueBag->setPropertyValue('prop2', '3'); $this->assertEquals(0, $condition->getMatchCount(null, $propertyValueBag)); }
/** * Load property values. * * @return void */ private function loadPropertyValues() { $flatten = $this->flatten($this->getData()); $this->propertyValues = new PropertyValueBag($flatten); $this->model->setPropertiesAsArray($flatten); foreach ($this->getForms() as $form) { foreach ($form->getFields() as $field) { $defintion = $this->environment->getDataDefinition()->getPropertiesDefinition(); $defintion->addProperty($field); if (!$this->isSubmit()) { continue; } $value = $this->environment->getInputProvider()->getValue($field->getName(), true); // Set value to property values and to model. If validation failed, the widget manager loads data // from the model. $this->model->setProperty($field->getName(), $value); $this->propertyValues->setPropertyValue($field->getName(), $value); } } }
/** * Process input and return all modified properties or null if there is no input. * * @param ContaoWidgetManager $widgetManager The widget manager in use. * * @return null|PropertyValueBag */ protected function processInput($widgetManager) { $input = $this->getEnvironment()->getInputProvider(); if ($input->getValue('FORM_SUBMIT') == $this->getDataDefinition()->getName()) { $propertyValues = new PropertyValueBag(); $propertyNames = array_intersect($this->getDataDefinition()->getPropertiesDefinition()->getPropertyNames(), $input->getValue('FORM_INPUTS')); // Process input and update changed properties. foreach ($propertyNames as $propertyName) { $propertyValue = $input->hasValue($propertyName) ? $input->getValue($propertyName, true) : null; $propertyValues->setPropertyValue($propertyName, $propertyValue); } $widgetManager->processInput($propertyValues); return $propertyValues; } return null; }