function __construct($oContentFieldsContainer) { parent::__construct($oContentFieldsContainer); }
/** * You can put all default values into a php array and just call this method on the top contentFieldsContainer. * This will initialize all contentFields's default values with values found in php array. */ function setContentFieldsDefaultValuesFromArray($cfg, $bOnlyForSubContents = false) { $aoContentFields = $this->getContentFields(); foreach ($aoContentFields as $oContentField) { $sFieldName = $oContentField->getName(); if (isset($cfg[$sFieldName])) { if ($oContentField instanceof AnwStructuredContentField_atomic) { if (!$bOnlyForSubContents) { /* * ATOMIC field */ //get values from config $asValues = AnwStructuredContent::getContentFieldValuesFromArrayItems($oContentField, $cfg[$sFieldName]); //set default values for the contentfield $oContentField->setDefaultValues($asValues); } } else { /* * COMPOSED field */ if (!$oContentField->isMultiple()) { // monovalued composed field: just create a temporary subcontent to loop on it's contentfields and set default values on it. $oContentField->setContentFieldsDefaultValuesFromArray($cfg[$sFieldName], $bOnlyForSubContents); //recursive call } else { // composed and multivalued $aoSubContents = AnwStructuredContent::getSubContentsFromArrayItems($oContentField, $cfg[$sFieldName]); foreach ($aoSubContents as $oSubContent) { // recursive call, only for setting defaultSubContents, but NOT for setting atomic contentfield's default values! $mSubCfg = array_shift($cfg[$sFieldName]); $oContentField->setContentFieldsDefaultValuesFromArray($mSubCfg, true); //recursive call //print htmlentities($oSubContent->toXmlString()); } $oContentField->setDefaultSubContents($aoSubContents); // more than 1 multivalued value: we can't do anything, it wouldn't make sense, // every subcontents are linked to the same subcontentfields, so iterating on subcontents // would just override subcontentfields default values set from previous subcontent. // To conclude, contentfields from multivalued composed fields can't have distinct default values for each default subcontent. /* $nCountSubContents = count($cfg[$sFieldName]); if ($nCountSubContents>1) { // more than 1 multivalued value: we can't do anything, it wouldn't make sense, // every subcontents are linked to the same subcontentfields, so iterating on subcontents // would just override subcontentfields default values set from previous subcontent. // To conclude, contentfields from multivalued composed fields can't have distinct default values for each default subcontent. } else { // ok, we can allow it if there is no more than 1 value if ($nCountSubContents==1) { $oContentField->setDefaultSubContentsNumber(1); //remind the number of subcontents for restituing it back in getSubContents() $oContentField->setContentFieldsDefaultValuesFromArray($cfg[$sFieldName][0]); //recursive call } else { //0 subcontents, nothing to do... } }*/ } } } } }