Problem/Motivation

Wanted to use with better exposed form
Getting this error after enabling the module

ypeError: Unsupported operand types: string - int in Drupal\views_ef_fieldset\Plugin\views\display_extender\ViewsEFFieldset->buildOptionsForm() (line 201 of /var/www/web/modules/contrib/views_ef_fieldset/src/Plugin/views/display_extender/ViewsEFFieldset.php)

#0 /var/www/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(1871): Drupal\views_ef_fieldset\Plugin\views\display_extender\ViewsEFFieldset->buildOptionsForm(Array, Object(Drupal\Core\Form\FormState))
#1 /var/www/web/core/modules/views/src/Plugin/views/display/PathPluginBase.php(440): Drupal\views\Plugin\views\display\DisplayPluginBase->buildOptionsForm(Array, Object(Drupal\Core\Form\FormState))
#2 /var/www/web/core/modules/views/src/Plugin/views/display/Page.php(257): Drupal\views\Plugin\views\display\PathPluginBase->buildOptionsForm(Array, Object(Drupal\Core\Form\FormState))
#3 /var/www/web/core/modules/views_ui/src/Form/Ajax/Display.php(74): Drupal\views\Plugin\views\display\Page->buildOptionsForm(Array, Object(Drupal\Core\Form\FormState))
#4 [internal function]: Drupal\views_ui\Form\Ajax\Display->buildForm(Array, Object(Drupal\Core\Form\FormState))
#5 /var/www/web/core/lib/Drupal/Core/Form/FormBuilder.php(531): call_user_func_array(Array, Array)
#6 /var/www/web/core/lib/Drupal/Core/Form/FormBuilder.php(278): Drupal\Core\Form\FormBuilder->retrieveForm('views_ui_edit_d...', Object(Drupal\Core\Form\FormState))
#7 /var/www/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(215): Drupal\Core\Form\FormBuilder->buildForm('Drupal\\views_ui...', Object(Drupal\Core\Form\FormState))
#8 /var/www/web/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\views_ui\Form\Ajax\ViewsFormBase->Drupal\views_ui\Form\Ajax\{closure}()
#9 /var/www/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(217): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#10 /var/www/web/core/modules/views_ui/src/Form/Ajax/ViewsFormBase.php(127): Drupal\views_ui\Form\Ajax\ViewsFormBase->ajaxFormWrapper('Drupal\\views_ui...', Object(Drupal\Core\Form\FormState))
#11 /var/www/web/core/modules/views_ui/src/Form/Ajax/Display.php(46): Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm(Object(Drupal\views_ui\ViewUI), 'application_lis...', 'ajax')
#12 [internal function]: Drupal\views_ui\Form\Ajax\Display->getForm(Object(Drupal\views_ui\ViewUI), 'application_lis...', 'ajax', 'exposed_form_op...')
#13 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#14 /var/www/web/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#15 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#16 /var/www/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#17 /var/www/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#18 /var/www/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#19 /var/www/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#20 /var/www/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /var/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /var/www/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /var/www/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /var/www/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /var/www/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /var/www/web/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /var/www/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#28 {main}

Steps to reproduce

1. enable module
2. Click views exposed form setting in advanced section

Proposed resolution

N/A

Remaining tasks

fix code

User interface changes

N/A

API changes

N/A

Data model changes

N/A

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

sarbazx created an issue. See original summary.

sarbazx’s picture

Issue summary: View changes
jlo101’s picture

Hi,
The problem is only associated with PHP8
In PHP v8 you are informed with a FATAL error that "Uncaught TypeError: Unsupported operand types: string + int"
Details:
https://stackoverflow.com/questions/66238017/fatal-error-uncaught-typeer...

Temporary solution:
/modules/views_ef_fieldset/src/Plugin/views/display_extender/ViewsEFFieldset.php
line 201:
$field->weight : $index - count($exposed_fields)),
change to:
$field->weight : intval($index) - count($exposed_fields)),

avpaderno’s picture

Version: 8.x-1.5 » 8.x-1.x-dev
Issue tags: -Drupal 9 compatibility +PHP 8.1
s_bhandari’s picture

StatusFileSize
new920 bytes

Hi,

Added the patch for the same. Please review.

Thanks.

pol’s picture

Hello,

I'm not working with Drupal anymore since a couple of year, I switched to Symfony, read the story at: https://not-a-number.io/about/

Also, Drupal.org is now using the amazing Gitlab since 2018: https://about.gitlab.com/blog/2018/08/16/drupal-moves-to-gitlab/
Submitting changes through a patch file is counter productive and a waste of time.

Therefore, could you please provide a proper merge request if you want your contribution to be taken in account?

I'm doing this to reduce the amount of time I dedicate to this ecosystem.

Thanks.

avpaderno’s picture

Status: Active » Needs work
-        'weight' => isset($field_options['weight']) ? $field_options['weight'] : (isset($field->weight) ? $field->weight : $index - count($exposed_fields)),
+        'weight' => isset($field_options['weight']) ? $field_options['weight'] : (isset($field->weight) ? $field->weight : intval($index) - count($exposed_fields)),

The code should use the null coalescing operator.

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

attisan’s picture

Status: Needs work » Needs review

added MR

avpaderno’s picture

Status: Needs review » Needs work
     foreach ($exposed_fields as $index => $field) {
       $field_options = $options['options']['sort'][$field['id']];
-      $label = ($field['expose']['label']) ? $field['expose']['label'] : $field['id'];
+      $label = ($field['admin_label'] ?? '')
+        ?: ($field['expose']['label'] ?? '')
+        ?: $field['id'];

The original code doesn't use $field['admin_label'], but $field['id'].

Then, the error reported in this issue is caused from the following code. (See comment #3.)

'weight' => isset($field_options['weight']) ? $field_options['weight'] : (isset($field->weight) ? $field->weight : $index - count($exposed_fields)),

That is the code to change to fix this issue.

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

osopolar’s picture

The expressions in MR5 from #10 like ($field_options['title'] ?? '') ?: $label, look strange to me. @attisan: Why did you change this? Also, as apaderno already noticed, why should one want to show the admin label, that is something internal for views administration and is not meant to be shown to the end-user.

@attisan In #7 you said:

The code should use the null coalescing operator.

Do you mean something like the following code? 'weight' => $field_options['weight']) ?? $field->weight ?? intval($index) - count($exposed_fields),

I created a separate branch for patch #5 + feedback from #7:

osopolar’s picture

StatusFileSize
new1.34 KB
osopolar’s picture

Status: Needs work » Needs review
osopolar’s picture

StatusFileSize
new2.46 KB

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

gaddman’s picture

Status: Needs review » Reviewed & tested by the community

@Pol, updated as requested and tested OK.

zarpele’s picture

#17 Works like a charm +1

Eli-T made their first commit to this issue’s fork.

  • Eli-T committed 336691dd on 8.x-1.x authored by osopolar
    Issue #3269083 by osopolar, gaddman, S_Bhandari, apaderno, Pol:...
eli-t’s picture

Priority: Critical » Major
Status: Reviewed & tested by the community » Fixed

Thanks everyone!

Status: Fixed » Closed (fixed)

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

jglynn’s picture

This needs to be committed to the 8.x-1.6 version, it's a pretty major bug

eli-t’s picture

Well I can't change what's in 8.x-1.6 but I can give you a shiny new 8.x-1.7 with this fix in: https://www.drupal.org/project/views_ef_fieldset/releases/8.x-1.7