Add @property statements to FieldType classes for better IDE completion

Created on 10 September 2014, almost 10 years ago
Updated 22 May 2024, 4 months ago

Problem/Motivation

Suggested commit message

Issue #2336101 by benjy, chx: Add @property declarations to field types.

Problem/Motivation

Entity classes (for example Drupal\node\Entity\Node) do not have any of the fields (for example title) added as a class property. This is impossible anyways because some fields might be configurable fields. So, in any IDE, even if you know a certain object is a Node entity, you can't autocomplete for $node->. phpdoc uses @property to resolve this exact situation. Further, even if you have a module that generates the @property definitions for a certain node type, you still can't autocomplete in $node->title-> because the field item classes also need @property on them. The latter is added by the patch in the issue.

Benefits

If we adopted this change, the Drupal Project would benefit by ...

Three supporters required

  1. https://www.drupal.org/u/ {userid} (yyyy-mm-dd they added support)
  2. https://www.drupal.org/u/ {userid} (yyyy-mm-dd they added support)
  3. https://www.drupal.org/u/ {userid} (yyyy-mm-dd they added support)

Proposed changes

Provide all proposed changes to the Drupal Coding standards . Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:

1. Tag reference

There is no text fof '@property'

Add the following after @param: Function parameters.

@property: Dynamic properties

The @property tag is used to document properties made available via __get, which are not class member variables. One example is the base field 'title' of the Node entity. The Node entity class does not declare the 'title' property but you can access $node->title as if there was one.

Example:

 * @property \Drupal\Core\Field\FieldItemList title
 *   The title of the node.
 * @property \Drupal\Core\Field\FieldItemList nid
 *   The nid of the node.

2. Repeat the above for each page or sub-page that needs to be changed.

Remaining tasks

  1. Add supporters
  2. Create a Change Record
  3. Review by the Coding Standards Committee
  4. Coding Standards Committee takes action as required
  5. Discussed by the Core Committer Committee, if it impacts Drupal Core
  6. Final review by Coding Standards Committee
  7. Documentation updates
    1. Edit all pages
    2. Publish change record
    3. Remove 'Needs documentation edits' tag
  8. If applicable, create follow-up issues for PHPCS rules/sniffs changes

For a full explanation of these steps see the Coding Standards project page

Feature request
Status

Needs review

Component

Coding Standards

Created by

🇦🇺Australia benjy

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024