Override Visibility Strategy while initializing Sugar Bean

Hello Folks,

I wanted to override visibility strategy defined in module bean class definition while initializing that bean.

For eg: I have a module called Test and I have defined following visibility in bean class.

class Test extends SugarBean

{

    public function __construct()

    {

         $this->addVisibilityStrategy("OwnerVisibility");

         parent::__construct();

    }

}

Now, while initializing bean, I wanted to override this strategy in some scenarios.

$testBean = BeanFactory::newBean("Test");

$testBean->addVisibilityStrategy("OwnerOrAdminVisibility");

But the above line is not working. I am not sure how to override the visibility already defined in bean definition.

Any help or idea would be greatly appreciated.

Regards.

Hats

Parents Reply Children
  • hats,

    After additional review it looks like ./data/visibility/OwnerOrAdminVisibility.php (that extends OwnerVisibility) are internal only visibility classes that you should not use.

    They are applied to modules that do not have real data requirements and do not implement search engine filtering for that reason. As I was saying before, you need to make sure you implement correctly the visibility also on the search engine Elasticsearch. I encourage you to look at the previously posted example where it implements 

    the required "elastic*" methods.

    If I had different needs that change based on some user's parameters I would write my own visibility class and apply my conditional logic in there to behave differently based on the required conditions and that implement correctly the visibility on the search engine as well.

    As mentioned previously I highly recommend you to complete profiling at scale as any visibility change (if not completed correctly) might make the system under perform.

    Hope it helps

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Thank you Enrico Simonetti. This helps. I will write my own visibility class as OwnerVisibility and OwnerOrAdminVisibiltiy doesn't seem to serve the purpose for me. I will follow the uncon example shared above. Thank you so much for directing me to the right path.

    Regards.

    Hats