Function to apply defaults and complete field definition.

@param string $field_code
Field code.
@param array $field
Field definition.

@return array
Field definition with all defaults applied.
431193
private function applyDefaults($field_code, array $field) {
    $defaults = $this->getDefaults();

    if (empty($field['source'])) {
      $field['source'] = $field_code;
    }

    // We will always have label, still we do a check to avoid errors.
    if (empty($field['label'])) {
      $field['label'] = $field_code;
    }

    // Add description if empty.
    if (empty($field['description'])) {
      $field['description'] = str_replace('[label]', $field['label'], $defaults['description']);
    }

    // Merge all other defaults.
    $field += $defaults;

    return $field;
  }
444469
public function definition() {
        global $PAGE;
        $mform = $this->_form;

        $field = $this->_customdata['field'];
        if (!($field && $field instanceof field_controller)) {
            throw new \coding_exception('Field must be passed in customdata');
        }
        $handler = $field->get_handler();

        $mform->addElement('header', '_commonsettings', get_string('commonsettings', 'core_customfield'));

        $mform->addElement('text', 'name', get_string('fieldname', 'core_customfield'), 'size="50"');
        $mform->addRule('name', null, 'required', null, 'client');
        $mform->setType('name', PARAM_TEXT);

        // Accepted values for 'shortname' would follow [a-z0-9_] pattern,
        // but we are accepting any PARAM_TEXT value here,
        // and checking [a-zA-Z0-9_] pattern in validation() function to throw an error when needed.
        $mform->addElement('text', 'shortname', get_string('fieldshortname', 'core_customfield'), 'size=20');
        $mform->addHelpButton('shortname', 'shortname', 'core_customfield');
        $mform->addRule('shortname', null, 'required', null, 'client');
        $mform->setType('shortname', PARAM_TEXT);

        $desceditoroptions = $handler->get_description_text_options();
        $mform->addElement('editor', 'description_editor', get_string('description', 'core_customfield'), null, $desceditoroptions);
        $mform->addHelpButton('description_editor', 'description', 'core_customfield');

        // If field is required.
        $mform->addElement('selectyesno', 'configdata[required]', get_string('isfieldrequired', 'core_customfield'));
        $mform->addHelpButton('configdata[required]', 'isfieldrequired', 'core_customfield');
        $mform->setType('configdata[required]', PARAM_BOOL);

        // If field data is unique.
        $mform->addElement('selectyesno', 'configdata[uniquevalues]', get_string('isdataunique', 'core_customfield'));
        $mform->addHelpButton('configdata[uniquevalues]', 'isdataunique', 'core_customfield');
        $mform->setType('configdata[uniquevalues]', PARAM_BOOL);

        // Field specific settings from field type.
        $field->config_form_definition($mform);

        // Handler/component settings.
        $handler->config_form_definition($mform);

        // We add hidden fields.
        $mform->addElement('hidden', 'categoryid');
        $mform->setType('categoryid', PARAM_INT);

        $mform->addElement('hidden', 'type');
        $mform->setType('type', PARAM_COMPONENT);

        $mform->addElement('hidden', 'id');
        $mform->setType('id', PARAM_INT);

        $this->add_action_buttons(true);
    }
934620
public function getFieldFunctionSQLType(MetadataField $metadata_field = null, $function_name)
    {
        $function = $this->getFieldFunctionById($function_name);

        $function_type = $function->getReturnedValueType();

        return ($function_type != '' && $function_type != null) ? $function_type : $metadata_field->getType();
    }
136657
public function setFieldList($field_list = array())
    {
        if (empty($field_list)) $this->_field_list = array('*');
        $this->_field_list = (array)$field_list;

        return $this;
    }
102138
function create_new_field_keys( &$field )
	{
		// update key
		$field['key'] = 'field_' . uniqid();
		
		
		if( isset($field['sub_fields']) && is_array($field['sub_fields']) )
		{
			foreach( $field['sub_fields'] as $f )
			{
				$this->create_new_field_keys( $f );
			}
		}
		elseif( isset($field['layouts']) && is_array($field['layouts']) )
		{
			foreach( $field['layouts'] as $layout )
			{
				if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) )
				{
					foreach( $layout['sub_fields'] as $f )
					{
						$this->create_new_field_keys( $f );
					}
				}
				
			}
		}
	}
437640
public String[] generateCodes(final String code, final String objectName, final String field, final Class<?> fieldType) {
        
        final String baseCode = getPrefix().isEmpty() ? code : getPrefix() + code;
        final List<String> codeList = new ArrayList<>();
        
        final List<String> objectNameList = Arrays.asList(generateObjectNameCodes(objectName));
        final List<String> fieldList = new ArrayList<>();
        buildFieldList(field, fieldList);
        
        if(Utils.isNotEmpty(field)) {
            // 最後のフィールド名のみを取得する
            int dotIndex = field.lastIndexOf('.');
            if(dotIndex > 0) {
                buildFieldList(field.substring(dotIndex + 1), fieldList);
            }
        }
        
        for(final String name : objectNameList) {
            addCodes(codeList, baseCode, name, fieldList);
        }
        
        addCodes(codeList, code, null, fieldList);
        
        if(fieldType != null) {
            addCode(codeList, code, null, fieldType.getName());
            
            if(Enum.class.isAssignableFrom(fieldType)) {
                // 列挙型の場合は、java.lang.Enumとしてクラスタイプを追加する。
                addCode(codeList, code, null, Enum.class.getName());
                
            } else if(fieldType.isArray()) {
                // 配列の場合は、"配列のクラスタイプ+[]"を追加する。
                Class<?> componentType = fieldType.getComponentType();
                addCode(codeList, code, null, componentType.getName() + "[]");
                addCode(codeList, code, null, "java.lang.Object[]");
            }
        }
        
        addCode(codeList, code, null, null);
        
        return codeList.toArray(new String[codeList.size()]);
    }
1087303
public static function createDefaultField($fieldName, $fieldConfig)
    {
        /** @var UserField $fieldType */
        $fieldType = $fieldConfig['FieldType'];

        $field = $fieldType::create();
        $field->Name = $fieldName;
        if (is_array($fieldConfig)) {
            foreach ($fieldConfig as $property => $value) {
                $field->setField($property, $value);
            }
        }

        return $field;
    }
628636
public function getFieldType($field)
    {
        $definition = $this->getFieldDefinition($field);
        if ($definition && isset($definition['type'])) {
            return $definition['type'];
        }
    }
88555
function createCheckDefaultValue(fieldDefinition, fieldName) {
  const defaultValue = fieldDefinition.defaultValue;

  // -----------------------------------------------------------------------
  // Set default value
  // -----------------------------------------------------------------------
  return function (content) {

    const valueToCheck = content[fieldName];
    // If the value is defined, we need to check it
    if (valueToCheck === undefined || valueToCheck === null) {
      if (defaultValue !== undefined) {
        content[fieldName] = defaultValue;
      }
    } else {
      if (Array.isArray(valueToCheck)) {
        valueToCheck.forEach(function (item, idx, arr) {
          if (item === undefined || item === null) {
            arr[idx] = defaultValue;
          }
        });
      }
    }
  };
}
1113547
public void add(final Field _field)
    {
        this.fields.put(_field.getId(), _field);
        this.fieldName2Field.put(_field.getName(), _field);
        if (_field.getReference() != null && _field.getReference().length() > 0) {
            final String ref = _field.getReference();
            int index;
            int end = 0;
            while ((index = ref.indexOf("$<", end)) > 0) {
                index += 2;
                end = ref.indexOf(">", index);
                addFieldExpr(ref.substring(index, end));
            }
        }
        _field.setCollectionUUID(getUUID());
    }
951283
function(opt, field_name, default_value) {
    if(typeof field_name === 'string') {
      // case of single string
      return (typeof opt[field_name] !== 'undefined') ? opt[field_name] : default_value;
    } else {
      // assume we are given a list of string instead
      var ret = default_value;
      for(var i=0;i<field_name.length;i++) {
        var f = field_name[i];
        if (typeof opt[f] !== 'undefined') {
          ret = opt[f]; // overwrite return value
        }
      }
      return ret;
    }
  }
183641
public function extractDefault(ColumnSchema $field, $defaultValue)
    {
        if (strncmp($field->dbType, 'bit', 3) === 0) {
            $field->defaultValue = bindec(trim($defaultValue, 'b\''));
        } else {
            parent::extractDefault($field, $defaultValue);
        }
    }
766787
public static function get_theme_field( $field_name, $default = false ) {

		if ( ! empty( self::$theme ) ) {
			return self::$theme->get( $field_name );
		}

		return $default;
	}
964741
private function completeFieldDefaultValue(Input $field, ReflectionParameter $param, string $fieldName): void
    {
        if (!$field->hasDefaultValue() && $param->isDefaultValueAvailable()) {
            $field->setDefaultValue($param->getDefaultValue());
        }

        if (!$field->hasDefaultValue()) {
            $defaultValue = $this->getPropertyDefaultValue($fieldName);
            if ($defaultValue !== null) {
                $field->setDefaultValue($defaultValue);
            }
        }
    }
526574
public function getDefaultClause($xmldb_field) {

        $defaultvalue = $this->getDefaultValue ($xmldb_field);

        if ($defaultvalue !== null) {
            return ' DEFAULT ' . $defaultvalue;
        } else {
            return null;
        }
    }
213543
public function sf($code, $default = null)
    {

        // In PHP, ("a" == 0) will evaluate to TRUE, so it's actually very important that we ensure type here!
        $code = (string) $code;

        $subfield = $this->getSubfield($code);
        if (!$subfield) {
            return $default;
        }

        return trim($subfield->getData());
    }
1235484
static public function formatValue($field, $field_value=null)
    {
        $methods = [];
        if (isset($field['data_format']) && $field['data_format']) {
            $methods[] = $field['data_format'];
        }
        $methods[] = $field['field_name'];
        if (isset($field['base_type']) && $field['base_type']) {
            $methods[] = $field['base_type'];
        }
        $methods[] = $field['data_type'];
        
        foreach ($methods as $m) {
            if (method_exists(get_called_class(), $m)) {
                return static::$m($field_value);
            }
        }
        
        $data_type = strtolower($field['data_type']);
        if (preg_match('/int/', $data_type)) {
            $field_value = intval($field_value);
        } else {
            $field_value = static::output($field_value);
        }
        
        return $field_value;
    }