Warning: This issue is dependent on, and caused by, issue #2030633: Expand FieldStorageConfig with methods
Problem
In an ongoing effort to provide classes/interfaces with methods that get and set their properties, see #2016679: Expand Entity Type interfaces to provide methods, protect the properties, the FieldConfig class was expanded to have getters and setters, see #2030633: Expand FieldStorageConfig with methods. However, there are still an unknown number of references directly to the public properties that should be updated to use these new methods.
One way to see where the methods are directly called is to set the properties to be protected and see what blows up. This was done in comment 39 of #2030633: Expand FieldStorageConfig with methods. The test bot will fail at the first instance so a better approach to testing should be found rather than repeatedly submitting intentionally broken patches.
Proposed resolution
Find places in the code that call the properties directly and update them to use the methods instead. For example, the ContentEntityDatabaseStorage class references the $field->deleted property directly instead of using the $field->isDeleted() method.
Remaining tasks
The magnitude of this issue is not yet known. Someone should figure out how to run the full test suite against code that has the FieldConfig properties set to protected to see the extent of the problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2282299_AccessingFieldConfig.patch | 23.3 KB | acrosman |
Comments
Comment #1
carsonevans commentedComment #2
carsonevans commentedComment #3
cilefen commentedOne can search the source code for likely usages with something like this:
grep -rl "use Drupal\\\field\\\Entity\\\FieldConfig" core/ |xargs grep -i "\\->cardinality"Where cardinality is one of the soon-to-be-former public properties such as:
id, cardinality, name, entity_type, type, module, settings, translatable, locked, indexes, deleted
Comment #4
acrosmanShould be able to find all the effected lines with something along the lines of:
\$field->(id|cardinality|name|entity_type|type|module|settings|translatable|locked|indexes|deleted)(?!\(\))My review comes back with something on the order of 25 references across the core directory.
Comment #5
acrosmanThis patch should resolve all the references I found. It assumes the patch from comment 64 on #2030633: Expand FieldStorageConfig with methods has been applied first.
Comment #6
acrosmanComment #8
swentel commentedLooks like this also contains another patch that shouldn't be here.
Comment #9
daffie commentedThe class variable "deleted" is now public and needs to be changed to protected. We want to use the principle of encapsulation.
Comment #10
yesct commentedClosing this since the other issue #2030633: Expand FieldStorageConfig with methods will have to remove direct accesses of the properties since it will be making them protected. (this is a change from how we were approaching the issues originally.)