civicrm / org.civicrm.contactlayout

Customize the contact summary screen
Other
15 stars 20 forks source link

PHP 8.0 fix #122

Closed Freewindrider closed 2 years ago

Freewindrider commented 2 years ago

Bug When running Contact Layout in an environment using PHP 8.0 (support for PHP 7.4 is running out), the following error shows up when trying to load a contact-view: 0 array_intersect(): Argument #2 must be of type array, null given

Reproduce Steps to reproduce the behaviour:

  1. Run CiviCRM site / installation in PHP 8.0
  2. Contact Layout Extension activated
  3. Load a contact
  4. Error shows up immediately

Additional information

Call stack
--
1 | () | JROOT/media/civicrm/ext/org.civicrm.contactlayout-2.1.1/CRM/Contactlayout/BAO/ContactLayout.php:343
2 | array_intersect() | JROOT/media/civicrm/ext/org.civicrm.contactlayout-2.1.1/CRM/Contactlayout/BAO/ContactLayout.php:343
3 | CRM_Contactlayout_BAO_ContactLayout::loadAllBlocks() | JROOT/media/civicrm/ext/org.civicrm.contactlayout-2.1.1/CRM/Contactlayout/BAO/ContactLayout.php:124
4 | CRM_Contactlayout_BAO_ContactLayout::getAllBlocks() | JROOT/media/civicrm/ext/org.civicrm.contactlayout-2.1.1/CRM/Contactlayout/BAO/ContactLayout.php:145
5 | CRM_Contactlayout_BAO_ContactLayout::getBlock() | JROOT/media/civicrm/ext/org.civicrm.contactlayout-2.1.1/CRM/Contactlayout/BAO/ContactLayout.php:96
6 | CRM_Contactlayout_BAO_ContactLayout::loadBlocks() | JROOT/media/civicrm/ext/org.civicrm.contactlayout-2.1.1/CRM/Contactlayout/BAO/ContactLayout.php:40
7 | CRM_Contactlayout_BAO_ContactLayout::getLayout() | JROOT/media/civicrm/ext/org.civicrm.contactlayout-2.1.1/contactlayout.php:100
...

Fix for PHP 8.0 Change line 343 in ContactLayout.php from $profileType = array_intersect($contactTypes, $profile['uf_group_id.group_type']);

to $profileType = array_intersect($contactTypes, $profile['uf_group_id.group_type'] ?? []);

Test Tested this successfully on CiviCRM 5.55.1 with Contact Layout version 2.1.1 on PHP 8.0.25

Please consider to include this change in future releases.

Best regards

colemanw commented 2 years ago

Thanks for reporting. In the future can you please create a pull-request? You can do this on GitHub simply by clicking the edit button on the file in question and making the suggested change.

Fixed via c74f0db