Part of meta-issue #2016679: Expand Entity Type interfaces to provide methods, protect the properties.
See the detailed explanations there and look at the issues that already have patches or were commited.
Add get*, set* and additional methods as it makes sense to replace the public properties (e.g. isSomething() and something())
Methods to be added to the class FieldConfigBase
getBundle()
setDescription($description)
setRequired($required)
setSetting($setting_name, $value)
setSetting(array $settings)
TODO
Set the variable FieldConfigBase::default_value to protected.
| Comment | File | Size | Author |
|---|---|---|---|
| #78 | 2030637_FieldConfig_methods-78.patch | 65.25 KB | yched |
Comments
Comment #1
chertzogHere is a first attempt.
Comment #3
thomas.fleming commented#1: Expand_field_instance.patch queued for re-testing.
Comment #5
thomas.fleming commentedComment #6
thomas.fleming commentedComment #8
swentel commentedPostponing this on #1953408: Remove ArrayAccess BC layer from field config entities
Comment #9
swentel commentedPosponed on #2095303: Rename 'field_entity' to 'field_config' and 'field_instance' to 'field_instance_config' now
Comment #10
Alumei commentedAttempted re-roll of #1 with some modifications to respect the current codebase.
Hope I did not miss anything.
Comment #11
Alumei commentedComment #13
Alumei commented10: expand-field-instance-2030637-10.patch queued for re-testing.
Comment #15
Alumei commentedI get the following error on a running drupal install:

Comment #16
ofry commentedWill try to do backtrace.
Comment #17
ofry commentedComment #18
swentel commentedThat backtrace is not very useful.
This is the actual error:
Which is very normal as the config storage controller now tries to access a protected property. This won't work at all. Furthermore, if you start 'fixing' this, you'll encounter more direct property access in many other files. So we also need setters too, for instance for 'settings' and such. This won't be an easy one to get right.
Also not sure how useful the getId() method is, this should rather live on configEntityBase I think.
Comment #19
ofry commentedSorry for my last post, this bug I have with fresh git version, no patches applied :(
Comment #20
Alumei commentedHm. Apparently the ConfigStorageController.php does:
From #2054699: Ensure config entity id is set for computed composite ids.
I also just searched for some ConfigTyps that extend ConfigEntityBase: CustomBlock, Block, Breakpoint, BreakpointGroup, Contact
All those seem to implement a custom $id property.
But ConfigEntityBase also has an $originalId property which holds exactly the same info, though it seems to be for a different use-case:
Actually all config-entitys have an $id property, which could be could be, but must not is reems reasonable to move that property to ConfigEntityBase. This it must not be that way judging form the code above as the id key is generated like this:
$this->idKey = $this->entityType->getKey('id');Comment #21
Alumei commentedAlso there is:
#2016679-14: Expand Entity Type interfaces to provide methods, protect the properties
#2016679-18: Expand Entity Type interfaces to provide methods, protect the properties
#2016679-29: Expand Entity Type interfaces to provide methods, protect the properties
Comment #22
Alumei commentedWe should propably leave the properties public as suggested in #2016679-29: Expand Entity Type interfaces to provide methods, protect the properties and also done in nearly all other issues working on ConfigEntities.
In that case it's only getters for:
And setters where applicable:
right?
Comment #23
Alumei commentedThese getter exist already:
With this I'm unsure:
For these there is still a getter missing:
This setter could be resonable:
$this->label();$this->settings + $this->field->getSettings();Does this make any sense or did I miss something?
Comment #24
Alumei commentedThis patch starts from scratch and changes FieldInstanceConfig and FieldInstanceConfigInterface by
adding getters for:
$this->field->uuid();to ensure that the correct uuid is usedadding setters for:
changes getter for:
Comment #27
a.milkovskyI think the folders structure is changed.
Patch needs to be changed.
Currencly file core/modules/field/lib/Drupal/field/Entity/FieldInstanceConfig.php doesnt exist as well as the core/modules/field/lib/Drupal/field/Entity folder.
Comment #28
mile23Re-roll of #24.
Comment #30
jibranunrelated to patch
Comment #31
mile23Based on testbot: Merge failed on default.settings.php and default.services.yml. Pulled those files from HEAD and here's the new patch.
Comment #32
mile23Testbot passes because we patch classes which are deleted by the rebase.
The patch only introduces an interface and then doesn't add tests.
This might be a won't fix issue....
Comment #33
yched commentedUpdating title for the new name of the config entity.
+ meanwhile, BaseFieldOverride got added (both entity types have the same content and mostly inherit from the same FieldConfigBase base class, so they are best handled together)
Comment #34
daffie commentedThe class BaseFieldOverride needs an interface. The following function are new in the class: createFromBaseFieldDefinition() and loadByName().
The current patch introduces an interface for a class that already has an interface. So the patch no longer applies.
The class FieldStorageConfig has a lot of public variables that need to be changed to protected.
Comment #35
daffie commentedComment #36
mile23BaseFieldOverrideextendsFieldConfigBase, which implementsFieldConfigInterface, and through inheritance,ConfigEntityInterface. I doubtBaseFieldOverrideneeds its own interface.Comment #37
mile23Comment #38
mile23I did this: #2396713: Figure out how to encapsulate writable settings supplied by DataDefinitionInterface
I think that issue is blocking this one, and probably others in #2016679: Expand Entity Type interfaces to provide methods, protect the properties
Comment #39
yesct commentedThank you @Mile23 I really hope we can get these issues done before release, and this found something very tricky.
--
Removing Novice tag.
The novice parts of this have already been done, now the work is trickier.
https://drupal.org/core-mentoring/novice-tasks
--
in
#2398901-16: Image module makes fatal assumptions about EntityInterface
@yched suggests 3 ways forward.
I'm in favor of:
--
Unassigning so it is clear anyone can try to do that.
Comment #40
daffie commentedMerged this issue with #2030633: Expand FieldStorageConfig with methods. The reason why is explained in this comment. I gave it the status of "Closed (won't fix)". I that is wrong please correct me.
Comment #41
berdirAre you sure about this? I already posted a patch in #2030633: Expand FieldStorageConfig with methods that makes it not necessary to merge it, this will simply have to clean up 3 lines of code then. The patch there is already pretty large, not sure if we should make it bigger.
Comment #42
daffie commentedOn #2030633: Expand FieldStorageConfig with methods.
Comment #43
yesct commentedI'm not sure it is postponed either. I think we can work on this, and reroll if necessary if the other issue gets committed first.
Comment #44
mile23Patch in #31 still applies. Setting it to re-test.
None of the others are committed, or really even reviewed.
Comment #46
mile23Oh yeah, that was the patch that just added an interface. Doh. Let's start over. :-)
This patch basically ignores all previous patches, which have been refactored away in other issues.
So at this point
BaseFieldOverrideis already encapsulated (in that it doesn't have any public properties).FieldConfighas only one public property,$deleted, which is already encapsulated asisDeleted(). So I'll just change that to be protected and whatever other incompatibilities arise from that.Comment #47
daffie commentedIt all looks good to me.
All the variables are set to protected.
All documentation is in order.
It get a RTBC from me.
Comment #48
alexpottSo what about fieldConfigBase? I think this issue should be expanded in scope to cover that to because it is the shared base class of FieldConfig & BaseFieldOverride
Comment #49
mile23Needed a reroll.
Comment #50
berdirWhat alexpott said in #48.
I expect that this adds a setSetting() method, among other things. so that we can simplify image_entity_presave() from
To
Because we know that both interfaces/entity types that we are working with have that method.
Comment #51
mile23Comment #52
mile23The concerns in #50 will be met by any work on
FieldConfigBase, because that's where we'd implementsetSetting().However, work on
FieldConfigBasefor #48 will be major, and will conflict with this critical: #2416409: Delete dependent config entities that don't implement onDependencyRemoval() when a config entity is deletedFiled a follow-up here: #2426647: Expand FieldConfigBase with methods which is postponed on the critical.
Comment #53
alexpottRather than creating a new postponed issue I suggest that we continue here - just as long as we don't do anything with the
noFieldDeleteproperty. And I don't mind rerolling the critical - which is postponed as well.Comment #54
daffie commentedalexpott wants to expand this issue to also cover fieldConfigBase class (see comment #48).
Comment #55
daffie commentedAdded the fieldConfigBase class to the patch.
All class variables are set to protected, accept for $default_value.
Comment #56
daffie commentedFixed some mistakes in the patch and updated the issue summary.
Comment #59
daffie commentedReroll
Comment #60
yched commentedReroll for now.
Comment #61
yched commentedThen, fixing FieldConfigEditForm, that got added meanwhile.
Comment #64
yched commented- Removed the getBundle() method, it duplicates the existing getTargetBundle() we already have from FieldDefinitionInterface.
- Fixed a couple tests (i.e chasing HEAD since the last green patch)
Comment #66
yched commentedShould be green.
Comment #67
yched commentedJust reordered the methods a bit (getters before setters), and made the ordering consistent between FieldConfigInterface and FieldConfigBase.
Then I actually reviewed the changes (at last...)
I'm wondering :
- why setRequired() is not added to FieldConfigInterface like the other setters added there, but to FieldDefinitionInterface above ?
It's a fact that FDI and FSDI lack setters, but IIRC we have an issue for it, meanwhile I'd rather be consistent in our inconsistency :-/
- why FieldConfigBase::$default_value is the only property that remains public ?
Will post a patch that fixes the above, and see what fails
Comment #68
yched commentedSorry, first I forgot to upload the patch for my "Just reordered the methods a bit" comment above :-)
Comment #69
yched commentedThen, as per #67, checking what happens if
- setRequired() is added to FieldConfigInterface rather than FieldDefinitionInterface
- FieldConfigBase::$default_value goes protected
Comment #70
yched commentedEr, d.o, you must be kidding me.
Comment #74
yched commentedOK, FieldConfigBase::$default_value is tricky because we don't have a getter for "the raw array stored in the property", only for "assemble the default value to use at runtime on newly created entities, can come from FieldConfigBase::$default_value or FieldConfigBase::$default_value_callback".
And there is some code that needs to do housekeeping on the former (EntityReferenceItem::calculateDependencies() for example)
I think we have an issue for that somewhere :-/
Reverting that then.
Comment #75
yched commentedOK, this is ready for me then - I guess this will need someone else to push the RTBC button though :-/
Also, bumping to major, since the sister patch in #2030633: Expand FieldStorageConfig with methods got in, it would be pretty inconsistent to ship that way.
Comment #76
yched commentedRest assured that the irony is not lost on me, but - my turn to bump and beg for an RTBC :-)
Comment #77
berdirI don't see anywhere in this issue why we remove this? The method does exist on the parent, but it seems we're removing possibly relevant documentation here?
This seems to result in quite a few changes that aren't really related to this issue?
What we sometime do instead is document the type by overriding protected $ntity at the top of the class.
Other than that, looks ready to me.
Comment #78
yched commentedThanks @Berdir !
And damn, busted on unrelated changes :-p
1. Well, this does add information about empty items being filtered out before checking validation :
- Never been a fan of an interface overriding another interface just to add a different phpdoc :-)
- Those two paragraphs are already present and exactly duplicated in the phpdoc for FieldConfigInterface::setRequired(), where they arguably belong best (to inform the decision of setting to required or not). We usually avoid duplicate docs...
- But right, not really related :-). We can clean that up (or not) in the issue where we move setters in the FieldDefinitionInterface / FieldStorageDefinitionInterface, if we ever get there ...
2. Right, not really related either, it's just that all those $this->entity->something() get a bit old. But well apparently I didn't even consistently replaced all of them :-). Reverted to the current $this->entity.
Comment #79
berdirSorry :)
1. Would have been OK with that explanation (which makes sense), just wasn't sure if that was accidental or not.
Comment #80
alexpottCommitted f8f024e and pushed to 8.0.x. Thanks!
Committing under the maintainer discretion for fragility as per the consistency argument made in #75.
Comment #82
yched commentedAwesome. Thanks a lot @all that kept pushing this, and sorry that it took me so long to get to it
Comment #83
mpdonadioThe issue summary for this is not accurate. The patch that was committed adds new methods, but it also changed the scope for some class properties from public to protected, which is an API change. At the very least, this needs a change record.
Comment #84
andypostprobably update of CRs is better
Comment #85
daffie commentedThere is still the variable FieldConfigBase::default_value that needs to be set to protected. I know that is a difficult one and in the ycheds words (#74):
Comment #86
daffie commentedCreated a followup issue: #2529034: Replace direct access to FieldConfigBase::default_value with methods.
Only a change record is still needed.
Comment #87
arla commentedOpened another followup #2589829: Missing return $this in FieldConfigBase::setSetting and setConstraints
Comment #102
quietone commentedThis issue was committed to 8.0.x and re-opened to add a change record. Since that was for Drupal 8.0, which is now End of Life, this is now outdated.
If this is incorrect reopen the issue, by setting the status to 'Active', and add a comment explaining what still needs to be done.
Thanks!
Comment #103
quietone commentedI have come to this issue during a bugsmash group triage on #2396713: Figure out how to encapsulate writable settings supplied by DataDefinitionInterface.
I incorrectly set the status to outdated. It should be Fixed and moved to 8.0.x, per the commit on 8.0.x. Adding credit for the work done after the commit.