- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/entity/base.php
- Класс: BitrixMainEntityBase
- Вызов: Base::appendField
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' => 'BitrixIblockSection',
'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;
}