Problem/Motivation
The \Drupal\Core\TypedData\DataDefinition implements ArrayAccess with a 'this is for bc support only' comment thus:
/**
* {@inheritdoc}
*
* This is for BC support only.
* @todo: Remove in https://www.drupal.org/node/1928868.
*/
public function offsetExists($offset) {
// PHP's array access does not work correctly with isset(), so we have to
// bake isset() in here. See https://bugs.php.net/bug.php?id=41727.
return array_key_exists($offset, $this->definition) && isset($this->definition[$offset]);
}
/**
* {@inheritdoc}
*
* This is for BC support only.
* @todo: Remove in https://www.drupal.org/node/1928868.
*/
public function &offsetGet($offset) {
if (!isset($this->definition[$offset])) {
$this->definition[$offset] = NULL;
}
return $this->definition[$offset];
}
/**
* {@inheritdoc}
*
* This is for BC support only.
* @todo: Remove in https://www.drupal.org/node/1928868.
*/
public function offsetSet($offset, $value) {
$this->definition[$offset] = $value;
}
/**
* {@inheritdoc}
*
* This is for BC support only.
* @todo: Remove in https://www.drupal.org/node/1928868.
*/
public function offsetUnset($offset) {
unset($this->definition[$offset]);
}
However the referenced issue is closed - fixed - #1928868: Typed config incorrectly implements Typed Data interfaces
So do we want to remove it or just remove the comment?
Proposed resolution
- throw deprecation in ArrayAccess methods (like patch in comment #7)
- add deprecation test
- file issue to get rid of the methods in next major core release
Doing the deprecation-dance breaks just about every test known to Drupal CI: See #18.
Let's remove the comment and leave it in.
Let's trigger a deprecation error and observe what fails?
Result from #18: https://dispatcher.drupalci.org/job/drupal_patches/203233/#showFailuresLink
Test Result (2,578 failures / +2576)
It means ~10% so challenging but doable
Remaining tasks
patch/review/commit
User interface changes
no
API changes
accessing ArrayAccess methods directly or indirectly will throw deprecation
- \Drupal\Core\TypedData\DataDefinition::offsetExists()
- \Drupal\Core\TypedData\DataDefinition::offsetGet()
- \Drupal\Core\TypedData\DataDefinition::offsetSet()
- \Drupal\Core\TypedData\DataDefinition::offsetUnset()
Data model changes
no
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3032503
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
Comment #2
larowlanPersonally, I'm +1 on retaining it and removing the comment
Comment #3
larowlanComment #4
larowlanWhat does this break?
Obviously we can't do this, but we can do the trigger_error deprecation mambo
Comment #6
wim leersInteresting! Linking that issue.
Indeed. Any simplification we can make would be very welcome I think.🕺
Comment #7
andypostLet's see how many things affected by "mambo"))
Comment #18
spokjeComment #19
spokjeComment #21
spokjeComment #22
andypostLooks there's no way to remove it, so removal of todo probably is enough
Comment #23
smustgrave commentedRemoval of todo seems good.
Comment #24
lauriiiIt looks like even the typed data internals rely on the array access, like for example
\Drupal\Core\Config\TypedConfigManager::buildDataDefinition. I guess if we could get rid of the typed data system not internally using array access, we could get a real list of test fails.If we decide that's not worth it, I wonder if we should remove the "This is for BC support only." comment too.
Comment #25
wim leersAgreed with @lauriii.
I don't understand why it'd make sense to keep BC support forever and simply remove the
@todo.Let's trigger a deprecation error and observe what fails?
Comment #26
spokjeAll patches in this issue did exactly that.
Result from #18: https://dispatcher.drupalci.org/job/drupal_patches/203233/#showFailuresLink
Comment #27
andypostIt means ~10% so challenging but doable
Comment #29
spokjeComment #30
spokjeClosed MR now other direction is chosen, updated IS.
Comment #31
andypostthe real goal
Comment #32
andypostupdated IS
Comment #33
andypostDrafted CR to extend with examples and created MR to iterate
Comment #35
andypostIn MR I started deprecation, looks it also will need API addition
offsetUnset()- has no usage in core but has not replacement even using definition's methods,because, for example
DataDefinition::setConstraints(), require array so not useful to unset key in$this->definition-
offsetGet()is replaceable withtoArray(), example fixes in commitComment #36
andypostbtw there's problem with
toArray()- it is not defined by any interface(probably needs separate issue
Comment #37
andypostThe only tricky place is
offsetSet()which has only one usage in\Drupal\Core\Config\TypedConfigManager::buildDataDefinition()which could be changedOTOH
createFromDataType()has 5 overrides and could change signature to pass initial values so the raw setter is not neededComment #38
wim leersComment #39
lauriiiSeems like this change was definitely planned to be made given the inline comment. Regardless of that it would be great to get a framework manager review on this. 😇
Comment #40
catchCouple of comments on the deprecation method itself but I think the overall change is fine. That we only have to update code in the config system and config_translation module suggests this won't affect a lot of contrib modules.
Comment #41
lauriiiMoving to needs work to get the feedback addressed.
Comment #42
andypostRebased and squashed commits, updated deprecation wording and 10.4 core
maybe it should be deprecated in 11.1?
Comment #43
andypostTests are green and looking at changes there are only properties
nullable,translatable,mappingAlso
mappingproperty used to validaterequiredKeyso replaced with a hack to track changes in array processing, probably need Wim Leers to reviewComment #44
andypostUpdated to use
static::classto get the real data-class nameComment #45
andypostlegacy test added
Comment #46
smustgrave commentedReviewing the MR appears all threads have been addressed.
Deprecation appears to have test coverage.
Change record appears clear, also examples are always appreciated.
Believe this is ready.
Comment #47
longwaveIn two minds whether we should even do this given we have multiple workarounds in this MR that look a bit weird, and we've had to add an explicit setter method.
Comment #48
catchMoving back to needs review, looks like this needs more discussion.
Comment #49
andypostI think we should do it anyway but amount of workarounds are debatable.
Glad to get more opinions
Comment #50
smustgrave commentedThink we missed the 11.1 window, mind updating to 11.2, feel free to ping me to re-look at.
Comment #51
michaellander commentedDo we need to add
toArray()to the\Drupal\Core\TypedData\DataDefinitionInterface()? I'm needing eithertoArray()oroffsetGet()but the former isn't under contract.