public function setAttributeMetadataFromForm(AttributeForm $attributeForm)
 {
     assert('$attributeForm instanceof DropDownAttributeForm');
     $modelClassName = get_class($this->model);
     $attributeName = $attributeForm->attributeName;
     $attributeLabels = $attributeForm->attributeLabels;
     $defaultValueOrder = $attributeForm->defaultValueOrder;
     $elementType = $attributeForm->getAttributeTypeName();
     $partialTypeRule = $attributeForm->getModelAttributePartialRule();
     $isRequired = (bool) $attributeForm->isRequired;
     $isAudited = (bool) $attributeForm->isAudited;
     $customFieldDataName = $attributeForm->customFieldDataName;
     if ($customFieldDataName == null) {
         $customFieldDataName = ucfirst(strtolower($attributeForm->attributeName));
         //should we do something else instead?
     }
     $customFieldDataData = $attributeForm->customFieldDataData;
     $customFieldDataLabels = $attributeForm->customFieldDataLabels;
     $defaultValue = DropDownDefaultValueOrderUtil::getDefaultValueFromDefaultValueOrder($defaultValueOrder, $customFieldDataData);
     ModelMetadataUtil::addOrUpdateCustomFieldRelation($modelClassName, $attributeName, $attributeLabels, $defaultValue, $isRequired, $isAudited, $elementType, $customFieldDataName, $customFieldDataData, $customFieldDataLabels);
     if ($attributeForm->getCustomFieldDataId() != null) {
         $oldAndNewValuePairs = array();
         foreach ($attributeForm->customFieldDataData as $order => $newValue) {
             if (isset($attributeForm->customFieldDataDataExistingValues[$order]) && $attributeForm->customFieldDataDataExistingValues[$order] != $newValue) {
                 CustomField::updateValueByDataIdAndOldValueAndNewValue($attributeForm->getCustomFieldDataId(), $attributeForm->customFieldDataDataExistingValues[$order], $newValue);
                 $oldValue = $attributeForm->customFieldDataDataExistingValues[$order];
                 $oldAndNewValuePairs[$oldValue] = $newValue;
             }
         }
         if (count($oldAndNewValuePairs) > 0) {
             DropDownDependencyDerivedAttributeDesignerUtil::updateValueInMappingByOldAndNewValue($modelClassName, $attributeName, $oldAndNewValuePairs, $attributeForm->customFieldDataDataExistingValues[$order], $newValue);
         }
         DropDownDependencyDerivedAttributeDesignerUtil::resolveValuesInMappingWhenValueWasRemoved($modelClassName, $attributeName, $attributeForm->customFieldDataData);
     }
     $this->resolveDatabaseSchemaForModel($modelClassName);
 }
 /**
  * @depends testUpdateValueInMappingByOldAndNewValue
  */
 public function testResolveValuesInMappingWhenValueWasRemoved()
 {
     //Remove a1
     $customFieldDataData = array('a2New', 'a3', 'a4');
     DropDownDependencyDerivedAttributeDesignerUtil::resolveValuesInMappingWhenValueWasRemoved('aModelClassName', 'a', $customFieldDataData);
     //Confirm a1 has been removed from the mapping.
     $metadata = DropDownDependencyDerivedAttributeMetadata::getByNameAndModelClassName('aName', 'aModelClassName');
     $unserializedData = unserialize($metadata->serializedMetadata);
     $compareData = array(array('attributeName' => 'a'), array('attributeName' => 'b', 'valuesToParentValues' => array('b1' => null, 'b2' => 'a2New', 'b3New' => 'a3', 'b4' => 'a4')), array('attributeName' => 'c', 'valuesToParentValues' => array('c1New' => 'b1', 'c2New' => 'b2', 'c3' => 'b3New', 'c4' => 'b4')));
     $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']);
     $this->assertEquals($compareData, $unserializedData['mappingData']);
     //Remove b4
     $customFieldDataData = array('b1', 'b2', 'b3New');
     DropDownDependencyDerivedAttributeDesignerUtil::resolveValuesInMappingWhenValueWasRemoved('aModelClassName', 'b', $customFieldDataData);
     //Confirm b4 has been removed from the mapping.
     $metadata = DropDownDependencyDerivedAttributeMetadata::getByNameAndModelClassName('aName', 'aModelClassName');
     $unserializedData = unserialize($metadata->serializedMetadata);
     $compareData = array(array('attributeName' => 'a'), array('attributeName' => 'b', 'valuesToParentValues' => array('b1' => null, 'b2' => 'a2New', 'b3New' => 'a3')), array('attributeName' => 'c', 'valuesToParentValues' => array('c1New' => 'b1', 'c2New' => 'b2', 'c3' => 'b3New', 'c4' => null)));
     $this->assertEquals(array('a' => 'b'), $unserializedData['attributeLabels']);
     $this->assertEquals($compareData, $unserializedData['mappingData']);
 }