Problem/Motivation

At composer install I get following warnings :

PHP Deprecated:  Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getPossibleOptions(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 162

Deprecated: Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getPossibleOptions(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 162
PHP Deprecated:  Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getPossibleValues(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 183

Deprecated: Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getPossibleValues(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 183
PHP Deprecated:  Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getSettableOptions(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 195

Deprecated: Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getSettableOptions(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 195
PHP Deprecated:  Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getSettableValues(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 230

Deprecated: Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItem::getSettableValues(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItem.php on line 230
PHP Deprecated:  Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItemInterface::getSettableOptions(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItemInterface.php on line 62

Deprecated: Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItemInterface::getSettableOptions(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItemInterface.php on line 62
PHP Deprecated:  Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItemInterface::getSettableValues(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItemInterface.php on line 76

Deprecated: Drupal\view_mode_switch\Plugin\Field\FieldType\ViewModeSwitchItemInterface::getSettableValues(): Implicitly marking parameter $account as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/web/modules/contrib/view_mode_switch/src/Plugin/Field/FieldType/ViewModeSwitchItemInterface.php on line 76

Steps to reproduce

composer require 'drupal/view_mode_switch:^2.1'

on Drupal 11.3

CommentFileSizeAuthor
#3 view_mode_switch.png89.37 KBdebdeep.mukhopadhyay
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

g4mbini created an issue. See original summary.

debdeep.mukhopadhyay’s picture

I am working on this.

debdeep.mukhopadhyay’s picture

StatusFileSize
new89.37 KB

@g4mbini
I tested this locally with DDEV (PHP 8.3) and view_mode_switch 2.1.1.

I updated the nullable $account parameters in
ViewModeSwitchItem.php and verified in the UI by adding a View mode switch field to the Article content type and creating a node (/node/add/article). The field works correctly and no errors occur.

It is working fine on my local setup.

hctom’s picture

Thanks for the catch. This is somewhat related to #3502724: Fix code quality issues reported by PHPStan, so linking it here as well.

@debdeep.mukhopadhyay: Unfortunately I do not see any changes in the issue fork to review. Did you forget to commit them?

debdeep.mukhopadhyay’s picture

@hctom Thank you for your message.

I did not add any new commits, because the changes are already present in the issue branch/fork. That is why you do not see additional commits from my side.

Please let me know if I can help further. I will be happy to do so.

hctom’s picture

@debdeep.mukhopadhyay There are no changes in the issue fork ;)

https://git.drupalcode.org/issue/view_mode_switch-3570280/-/compare/2.x....

That's why I'm asking... Or am I missing something?

hctom’s picture

Ahhhh... now I understand what's going on here ;) The required changes for fixing the deprecated code are already included in the dev release of the module. I did not release them yet, because I wanted to fix #3502724: Fix code quality issues reported by PHPStan first ;)

...but I found some inconsistencies in the @param docs not naming the possible NULL values, which I'll fix with this issue.

@g4mbini: Please use the dev release for now and I'll try to get the code issues from the other ticket fixed asap to release a new version.

  • hctom committed ff47e663 on 2.x
    fix: #3570280 Deprecated code
    
    By: g4mbini
    By: debdeep.mukhopadhyay
    By:...
hctom’s picture

Status: Active » Fixed

Closing this issue as fixed, because the dev release already has all required changes

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

hctom’s picture

Status: Fixed » Closed (fixed)
debdeep.mukhopadhyay’s picture

@hctom Thank you very much for the fix and for the clarification.

I verified the changes locally using DDEV with PHP 8.3 and tested the View mode switch field on a node form to confirm that everything is working as expected.

If appropriate, I would be grateful if my local testing and verification could be credited.
Please let me know if I can help further in any way.

hctom’s picture

@debdeep.mukhopadhyay: Sorry, I thought I already credited all of you by creating the commit message via the contribution record... haven't been committing/merging things since the credit system update and was quite confused about the new UI, which does not really explain what to do where... and I am still confused, why I can put all the credits into the commit message, but they are actually not used for crediting.

So I hope, I have done it right now and you got your credits ;)

g4mbini’s picture

Thanks guys !

@hctom I hope you are doing good since Barcelona !