Skip to content

Custom fields for Issues when creating #15

@janson-git

Description

@janson-git

We have use some custom fields it redmine tasks for some projects, and I was needs to add this functionality in php-redmine-api quickly.

Probably you find this functionality is allowed to add for php-redmine-api. Of course in more presentable format. :)

My solution is next:

  • in Redmine\Api\Issue class added this code in 'create' (and something like this in 'update') method:
...
       $params = $this->cleanParams($params);
        $params = array_filter(array_merge($defaults, $params));

        $xml = new \SimpleXMLElement('');
        foreach ($params as $k => $v) {

            // CUSTOMIZED: added custom fields
            if ($k == 'custom_fields' && is_array($v)) {
                $custom_fields_item = $xml->addChild('custom_fields', '');
                $custom_fields_item->addAttribute('type', 'array');

                foreach ($v as $field) {
                    $item = $custom_fields_item->addChild('custom_field', '');
                    $item->addAttribute('id', $field['id']);
                    $item->addChild('value', $field['value']);
                }

            } else {
                $item = $xml->addChild($k, $v);
            }
        }


        return $this->post('/issues.xml', $xml->asXML());
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions