Extended class triggering forbidden functions

Hello.

Since my custom filter was triggering an error ("$in requires an array"), i created a new PHP file containing a "CustomFilterApi" class that extends FilterApi class, so then i was able to change some FilterApi's functions and bypass my filter's error. But when i extend the FilterApi class, it triggers some forbidden functions.

There's my CustomFilterApi code:

<?php

/*
 * Your installation or use of this SugarCRM file is subject to the applicable
 * terms available at
 * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */

require_once ("clients/base/api/FilterApi.php");

class CustomFilterApi extends FilterApi
{
	protected static function addFilters(array $filterDefs, SugarQuery_Builder_Where $where, SugarQuery $q)
    {
        foreach ($filterDefs as $filterDef) {
            if (!is_array($filterDef)) {
				$filterDef = array($filterDef);
                /*throw new SugarApiExceptionInvalidParameter(
                    sprintf(
                        'Did not recognize the definition: %s',
                        print_r($filterDef, true)
                    )
                );*/
            }
            foreach ($filterDef as $field => $filter) {
                parent::addFilter($field, $filter, $where, $q);
            }
        }
    }
}

Error screenshot:

/resized-image/__size/319x137/__key/communityserver-discussions-components-files/42/EVIDENCE1.png

Parents
  • I would not recommend circumventing an error message like that, clearly it is trying to tell you that your filter is not going to work. Removing the error message would just lead to the execution of code that won't work.

    The image from your error is too small to read, and too fuzzy when zoomed in. But I would say you need to figure out why your custom filter is not defined correctly. What is it that you are trying to achineve?

    FrancescaS

Reply
  • I would not recommend circumventing an error message like that, clearly it is trying to tell you that your filter is not going to work. Removing the error message would just lead to the execution of code that won't work.

    The image from your error is too small to read, and too fuzzy when zoomed in. But I would say you need to figure out why your custom filter is not defined correctly. What is it that you are trying to achineve?

    FrancescaS

Children
  • I have the same error and the error/issue has existed since sugar 7. I followed the custom filter instructions here (https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_10.0/Architecture/Filters/#Adding_Initial_Filters_to_Lookup_Searches) to the T and end up with this error and it does not matter whether I use in, equals, contains, etc.

    The "attempted" solution in the forums, has been what the author of this question suggested, since sugar 7. I have seen confirmations that this issue existed in 9.2, and I am running 10.2 and have the same issue.

    The problem is simple. Follow the instructions for the above link I attached. Trying to pre-filter items from a "search & select" on a relate field. I can successfully pass the value, but you can see an API failure and the message is returned.

    Error: $in requires an array



    The code in my initial_filter is as follows:

    <?php
    
    $viewdefs['HG_StakeholderRole']['base']['filter']['basic']['filters'][] = array(
        'id' => 'filterOppRelatedStakeholders',
        'name' => 'LBL_FILTER_OPP_RELATED_STAKEHOLDERS',
        'filter_definition' => array(
            array(
                'hg_stakeholderrole_opportunities_name' => array(
                    '$in' => array(),
                ),
            ),
        ),    
        'editable' => true,
        'is_template' => true,
    );