/** * @param Field $field * * @return bool */ protected function appendField(Field $field) { if (isset($this->fields[$field->getName()]) && !$this->isClone) { trigger_error(sprintf('Entity `%s` already has Field with name `%s`.', $this->getFullName(), $field->getName()), E_USER_WARNING); return false; } if ($field instanceof ReferenceField) { // references cache $this->references[$field->getRefEntityName()][] = $field; } $this->fields[$field->getName()] = $field; if ($field instanceof ScalarField && $field->isPrimary()) { $this->primary[] = $field->getName(); if ($field->isAutocomplete()) { $this->autoIncrement = $field->getName(); } } // add reference field for UField iblock_section if ($field instanceof UField && $field->getTypeId() == 'iblock_section') { $refFieldName = $field->getName() . '_BY'; if ($field->isMultiple()) { $localFieldName = $field->getValueFieldName(); } else { $localFieldName = $field->getName(); } $newFieldInfo = array('data_type' => 'Bitrix\\Iblock\\Section', 'reference' => array($localFieldName, 'ID')); $newRefField = new ReferenceField($refFieldName, $newFieldInfo['data_type'], $newFieldInfo['reference'][0], $newFieldInfo['reference'][1]); $newRefField->setEntity($this); $this->fields[$refFieldName] = $newRefField; } return true; }