View Issue Details

IDProjectCategoryView StatusLast Update
0021887mantisbtplug-inspublic2017-04-04 12:11
Reportermcmo Assigned To 
PrioritynormalSeverityminorReproducibilityN/A
Status newResolutionopen 
Summary0021887: Dynamic values for Enumeration Custom Fields using a Plugin
Description

In MantisBT 2.0.0, the Custom Functions are deprecated in favor of Plugins. In this case, how to create a dynamic list for an enumeration custom field using a plugin?
Thanks in advance

TagsNo tags attached.

Activities

vboctor

vboctor

2016-11-08 15:40

manager   ~0054479

We haven't disabled custom functions yet, but this is a good feature request for plugin-ins support for the scenario.

mcmo

mcmo

2016-11-14 08:42

reporter   ~0054525

Is it currently possible to create a custom function using a plug-in, i.e. having a custom_functions_inc.php file per plugin?
This would make it easy to package changes which require a plug-in and custom fields.
Thanks in advance

kevcrou

kevcrou

2017-01-30 11:23

reporter   ~0055401

I'm currently working on a plugin that dynamically give the values of enumeration custom fields in function of the current project.

As for now I use the custom function to redirect it to my plugin but as you said it's deprecated.

But I found where in the core code that is calling the custom function for custom field and I modified it in a way that don't break actual fonctionnement but call my plugin function if it's installed.

the actual code is : ( in custom_field_api.php)

function custom_field_prepare_possible_values( $p_possible_values ) {
    if( !is_blank( $p_possible_values ) && ( $p_possible_values[0] == '=') ){
        return helper_call_custom_function( 'enum' . utf8_substr( $p_possible_values, 1 ), array() );
    }

    return $p_possible_values;
}

And I modified it to be :

function custom_field_prepare_possible_values( $p_possible_values ) {
    if( !is_blank( $p_possible_values ) && ( $p_possible_values[0] == '=') ){
        if( plugin_is_installed( 'ProjectCustomFieldList' ) ){
            require_once( 'plugins/ProjectCustomFieldList/api/CustomFieldBeanDao.php' );
            $customFieldBeanDao = new CustomFieldBeanDao();
            return $customFieldBeanDao->custom_field_get_values( helper_get_current_project(), utf8_substr( $p_possible_values, 1 ) );
        }else{
            return helper_call_custom_function( 'enum' . utf8_substr( $p_possible_values, 1 ), array() );
        }       
    }

    return $p_possible_values;
}

Once I finalized my plugin I can push it to git if you want and with the modification in the core code you can answer to the need of dynamic custom field without custom function.

Do you think you can integrate this plugin to the mantis core in the futur ?

ps: I'm currently developing in the 1.3.5 version of mantis but I can adapt it to the 2.0 if there a need to.

kevcrou

kevcrou

2017-02-08 11:39

reporter   ~0055585

Hi, I finalized my plugin so I leave it in attachement.

Note that this plugin work only if you do the modification is core/custom_field_api.php

you have to replace :

function custom_field_prepare_possible_values( $p_possible_values ) {
    if( !is_blank( $p_possible_values ) && ( $p_possible_values[0] == '=') ){
        return helper_call_custom_function( 'enum' . utf8_substr( $p_possible_values, 1 ), array() );
    }

    return $p_possible_values;
}

by :

function custom_field_prepare_possible_values( $p_possible_values ) {
    if( !is_blank( $p_possible_values ) && ( $p_possible_values[0] == '=') ){
        if( plugin_is_installed( 'ProjectCustomFieldList' ) ){
            plugin_require_api( 'api/CustomFieldBeanDao.php', 'ProjectCustomFieldList' );
            $t_customFieldBeanDao = new CustomFieldBeanDao();
            return $t_customFieldBeanDao->custom_field_get_values( helper_get_current_project(), utf8_substr( $p_possible_values, 1 ) );
        }else{
            return helper_call_custom_function( 'enum' . utf8_substr( $p_possible_values, 1 ), array() );
        }       
    }

    return $p_possible_values;
}

A READ_ME.txt in the .zip indicate how to use the plugin.

if you qualify this plugin suitable @vboctor I can do a PR for the core function and I can also create a git repository for code review.

mcmo

mcmo

2017-04-04 12:11

reporter   ~0056374

Hi
I was rather thinking at a change in the core functions of MantisBT to be able to include a custom_functions_inc.php file in each plugin (probably in the pages subfolder)
I have currently a plugin that requires a custom function to work properly as the plugin creates custom fields, whose values are given by custom functions.

A quick check in the code seems to indicate the change should be in core.php

# Load custom functions
require_api( 'custom_function_api.php' );

if( file_exists( $g_config_path . 'custom_functions_inc.php' ) ) {
    require_once( $g_config_path . 'custom_functions_inc.php' );
}

that code should be extended to scan the subfolders of all plugins to include the custom functions files.

Issue History

Date Modified Username Field Change
2016-11-08 14:58 mcmo New Issue
2016-11-08 15:40 vboctor Category custom fields => plug-ins
2016-11-08 15:40 vboctor Note Added: 0054479
2016-11-14 08:42 mcmo Note Added: 0054525
2017-01-18 18:12 atrol Severity major => minor
2017-01-30 11:23 kevcrou Note Added: 0055401
2017-02-08 11:39 kevcrou File Added: ProjectCustomFieldList.zip
2017-02-08 11:39 kevcrou Note Added: 0055585
2017-04-04 12:11 mcmo Note Added: 0056374