Problem/Motivation

There are class properties in \Drupal\views\Plugin\views\style\StylePluginBase that violate the Drupal Coding standards. These properties are preceded by a phpcs ignore line, // phpcs:ignore Drupal.NamingConventions.ValidVariableName.LowerCamelName

Steps to reproduce

Proposed resolution

Rename each property
Deprecate. The Deprecation policy shows how to deprecate properties.

Remaining tasks

Create child issues

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

andypost created an issue. See original summary.

andypost’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: -Needs change record
StatusFileSize
new6.27 KB

Filed CR https://www.drupal.org/node/3344579

patch initial attempt, looks better to introduce a trait for that like DeprecatedServicePropertyTrait

longwave’s picture

+1 to adding a DeprecatedPropertyTrait similar to the service one, if we are going to do this everywhere in Views.

andypost’s picture

Thanks! The only trick is that trait will provide only one link to change record but maybe it should be enough

longwave’s picture

Maybe $deprecatedProperties can include the change record ID? Something like:

  protected $deprecatedProperties = [
    'rendered_fields' => ['renderedFields', 3344579],
    'render_tokens' => ['renderTokens', 3344579],
  ];
andypost’s picture

StatusFileSize
new3.74 KB
new7.43 KB

Guess kinda it

andypost’s picture

StatusFileSize
new571 bytes
new7.29 KB

property should not be defined in trait

lendude’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/src/Plugin/views/DeprecatedPropertyTrait.php
    @@ -0,0 +1,40 @@
    +namespace Drupal\views\Plugin\views;
    

    Feel useful outside Views to maybe? Currently not doing anything that would make this Views only, so maybe move it somewhere more generic?

  2. +++ b/core/modules/views/src/Plugin/views/DeprecatedPropertyTrait.php
    @@ -0,0 +1,40 @@
    +/**
    + * Provides a standard way to announce deprecated properties.
    + */
    

    Maybe expand on this that the 'deprecatedProperties' property must be set on all classes that implement this trait?

  3. +++ b/core/modules/views/src/Plugin/views/DeprecatedPropertyTrait.php
    @@ -0,0 +1,40 @@
    +   * Allows to get deprecated/removed properties.
    ...
    +   * Allows to set deprecated/removed properties.
    

    'Allows throwing an exception when a property is accessed that has been marked as deprecated.'

  4. +++ b/core/modules/views/src/Plugin/views/DeprecatedPropertyTrait.php
    @@ -0,0 +1,40 @@
    +    if (!isset($this->deprecatedProperties)) {
    +      throw new \LogicException('The deprecatedProperties property must be defined to use this trait.');
    +    }
    

    This bit is only in __get not __set, shouldn't it be in both?

  5. +++ b/core/modules/views/src/Plugin/views/DeprecatedPropertyTrait.php
    @@ -0,0 +1,40 @@
    +      @trigger_error("The property $name is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use $property instead. See https://www.drupal.org/node/$link", E_USER_DEPRECATED);
    

    Hardcoding the Drupal version means we can't use this in 10.2 without existing deprecation messages also changing, so I think that needs to be dynamic as well

quietone’s picture

Version: 8.0.x-dev » 10.1.x-dev

I only found this issue because I was checking if there were any issues filed on Drupal 8. I am changing the version to 10.

So, this issue is scoped by file but we now make coding standard fixes by sniff and with a different scope. That would make this issue a won't fix. For reference, the issue for the relevant sniff is #2937514: Fix Drupal.NamingConventions.ValidVariableName.LowerCamelName in tests.

But this issue is also proposing a way to deprecate properties. I think that should be discussed in it's own issue and work on the above issue is postponed on that. What do you think?

larowlan’s picture

Neat!

  1. +++ b/core/modules/views/src/Plugin/views/DeprecatedPropertyTrait.php
    @@ -0,0 +1,40 @@
    +    if (!isset($this->deprecatedProperties)) {
    

    any reason not to put deprecatedProperties on the trait and make it empty?

    I assume to prevent using the trait by accident?

  2. +++ b/core/modules/views/src/Plugin/views/DeprecatedPropertyTrait.php
    @@ -0,0 +1,40 @@
    +      @trigger_error("The property $name is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Use $property instead. See https://www.drupal.org/node/$link", E_USER_DEPRECATED);
    

    What if it is deprecated in 10.2.0? Do we need more than $property and $link? Should we have a simple value object?

  3. +++ b/core/modules/views/src/Plugin/views/style/StylePluginBase.php
    @@ -109,6 +111,23 @@ abstract class StylePluginBase extends PluginBase {
    +   * Keyed array pf replacements where key is deprecated property name.
    

    of

rishabh vishwakarma’s picture

StatusFileSize
new7.29 KB
new514 bytes

Addressed #10.3

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Component: views.module » other
Issue summary: View changes
Status: Needs work » Active
Issue tags: +Coding standards

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.