Problem/Motivation

The website encountered an unexpected error. Please try again later.
Error: Call to undefined function Drupal\block_class\Service\str_contains() in Drupal\block_class\Service\BlockClassHelperService->validateDynamicClasses() (line 1001 of modules/contrib/block_class/src/Service/BlockClassHelperService.php).

Error: Call to undefined function Drupal\block_class\Service\str_contains() in Drupal\block_class\Service\BlockClassHelperService->validateDynamicClasses() (line 1001 of /home/.../public_html/modules/contrib/block_class/src/Service/BlockClassHelperService.php)

#0 /home/.../public_html/modules/contrib/block_class/src/Service/BlockClassHelperService.php(904): Drupal\block_class\Service\BlockClassHelperService->validateDynamicClasses(Array, Object(Drupal\Core\Form\FormState), Object(Drupal\Core\Config\Config))
#1 /home/.../public_html/modules/contrib/block_class/block_class.module(145): Drupal\block_class\Service\BlockClassHelperService->blockClassFormValidate(Array, Object(Drupal\Core\Form\FormState))
#2 [internal function]: block_class_form_block_form_validate(Array, Object(Drupal\Core\Form\FormState))
#3 /home/.../public_html/core/lib/Drupal/Core/Form/FormValidator.php(82): call_user_func_array('block_class_for...', Array)
#4 /home/.../public_html/core/lib/Drupal/Core/Form/FormValidator.php(273): Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object(Drupal\Core\Form\FormState))
#5 /home/.../public_html/core/lib/Drupal/Core/Form/FormValidator.php(118): Drupal\Core\Form\FormValidator->doValidateForm(Array, Object(Drupal\Core\Form\FormState), 'block_form')
#6 /home/.../public_html/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormValidator->validateForm('block_form', Array, Object(Drupal\Core\Form\FormState))
#7 /home/.../public_html/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm('block_form', Array, Object(Drupal\Core\Form\FormState))
#8 /home/.../public_html/core/lib/Drupal/Core/Entity/EntityFormBuilder.php(61): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\block\BlockForm), Object(Drupal\Core\Form\FormState))
#9 /home/.../public_html/core/modules/block/src/Controller/BlockAddController.php(27): Drupal\Core\Entity\EntityFormBuilder->getForm(Object(Drupal\block\Entity\Block))
#10 [internal function]: Drupal\block\Controller\BlockAddController->blockAddConfigureForm('views_exposed_f...', 'intrepidnetwork')
#11 /home/.../public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#12 /home/.../public_html/core/lib/Drupal/Core/Render/Renderer.php(573): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#13 /home/.../public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#14 /home/.../public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#15 /home/.../public_html/vendor/symfony/http-kernel/HttpKernel.php(151): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#16 /home/.../public_html/vendor/symfony/http-kernel/HttpKernel.php(68): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#17 /home/.../public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(57): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#18 /home/.../public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(47): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#19 /home/.../public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /home/.../public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /home/.../public_html/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /home/.../public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(47): Drupal\ban\BanMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /home/.../public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(52): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /home/.../public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /home/.../public_html/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /home/.../public_html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#27 {main}

Steps to reproduce

Updated from 8.x-1.3 to 2.0.0 - running Drupal 8.9.20 PHP version 7.4.30

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

joshuautley created an issue. See original summary.

joshuautley’s picture

Issue summary: View changes
renatog’s picture

Priority: Normal » Major
Issue tags: +Novice

@joshuautley thank you so much for reporting

Steps to reproduce
Updated from 8.x-1.3 to 2.0.0 - running Drupal 8.9.20 PHP version 7.4.30

Just one question, after update what do you did to reproduce that? E.g. Only open any page? Running drush updb, Editing the Block in the CMS, etc?

Just to help in the fix

joshuautley’s picture

To reproduce I placed a block from views on (admin/structure/block). Let me know if you need more details.

victorml’s picture

Assigned: Unassigned » victorml

I'll try to fix.

victorml’s picture

Assigned: victorml » Unassigned
Status: Active » Needs review

The str_contains function works only from php 8 above, so I changed the validation to use strpos function.

I believe the logic still the same but now using a function supported by older php versions.

lucasbaralm’s picture

Assigned: Unassigned » lucasbaralm

I will review this.

lucasbaralm’s picture

Assigned: lucasbaralm » Unassigned
Status: Needs review » Reviewed & tested by the community

Tested and concluding, considering the modification made, the logic of the return of the conditional that had the undefined function problem is equivalent to the previous one, but without the undefined function problem in versions earlier than PHP 8.

Before:

if (str_contains($key, 'classes_')) {

After:

if (strpos($key, 'classes_') != FALSE) {
renatog’s picture

Status: Reviewed & tested by the community » Fixed

Amazing contribution!

Thank so much @joshuautley for reporting, @victorml for the fix and @lucasbaralm for the validation

Moved to the dev branch

joshuautley’s picture

Great to hear. Thank you!

renatog’s picture

New version 2.0.2 released with this fix.

Have a great day

anybody’s picture

This wasn't implemented correctly, I think!

if (strpos($key, 'classes_') != FALSE) {
must be
if (strpos($key, 'classes_') !== FALSE) {

see https://www.php.net/manual/de/function.strpos.php

anybody’s picture

Status: Fixed » Needs work
renatog’s picture

Yeah, good catch @anybody you're absolutely right

rpayanm made their first commit to this issue’s fork.

rpayanm’s picture

Status: Needs work » Needs review

Please review.

renatog’s picture

Status: Needs review » Reviewed & tested by the community

Awesome. Thanks a lot

  • RenatoG committed d582e4f on 2.0.x authored by rpayanm
    Issue #3301667 by victorml, rpayanm, RenatoG, joshuautley, lucasbaralm,...
renatog’s picture

Status: Reviewed & tested by the community » Fixed

Merged to the dev branch

Thanks everyone

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.