Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
C
Core
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 927
    • Issues 927
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Operations
    • Operations
    • Incidents
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • Development
  • Core
  • Issues
  • #1132

Closed
Open
Opened Jul 19, 2019 by Don Wijesooriya@chamilwijesooriya

fieldOptions hook fatal error

Using fieldOptions hook in an extension crashes or generates a fatal error.

I've come across 2 issues:

  1. Using a method defined in a class created in the extension generates fatal error
  2. Using API crashes the website

Steps to reproduce:

  1. Create a new module
  2. Create a class with a static method inside CRM/extension-short-name/
  3. Call that method inside fieldOptions hook. For eg: CRM_extension-short-name_Class::method()
  4. Refresh civicrm home page
  5. Server error log will have an error similar to the following

Class 'CRM_Myextension_MyClass' not found in /var/www/drupal/sites/default/files/civicrm/ext/uk.co.millertech.myextension/myextension.php on line 159, referer: http://chamil.drupal.local/civicrm/dashboard?reset=1

  1. Next inside the fieldOptions hook, use the API to obtain any random data. For eg:
    $result = civicrm_api3('OptionValue', 'get', [
        'sequential' => 1,
        'option_group_id' => "contribution_status",
    ]);
  1. Refresh civicrm home page

CiviCRM 5.15.1
Drupal 7

Issue

For the first issue, it seems extension files are not loaded before invoking fieldOptions hook. Calling _extension-short-name_civix_civicrm_config(); seems to fix that issue.

function myextension_civicrm_fieldOptions($entity, $field, &$options, $params)
{
     _myextension_civix_civicrm_config();
    CRM_Myextension_MyClass::myMethod();

}

Could not find a workaround for the second issue

Edited Jul 19, 2019 by Don Wijesooriya
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: dev/core#1132