Follow-up to #2488568: Add a TypedDataManagerInterface and use it for typed parameters

Problem/Motivation

There are a few places in TypedData plugins where we are using the typed data manager from the container instead of having it injected properly.
On top of that there is a full set of TypedConfig objects where some methods use the wrong 'manager' because of this (TypedDataManager instead of TypedConfigManager), preventing them from implementing properly the TypedDataInterface. Some of these methods are: validate(), getConstraints()

This dependency issue had been partially fixed in typed config objects -not all of them- by adding a workaround, setTypedConfig() method in \Drupal\Core\Config\Schema\ArrayElement, while it should have been added instead in the base class TypedData, and then reused. But reusing was not possible before because we didn't have a proper interface to use instead of TypedDataManager, which is addressed in the previous issue.

Example in \Drupal\Core\TypedData\TypedData.

abstract class TypedData implements TypedDataInterface, PluginInspectionInterface {
....
  /**
   * {@inheritdoc}
   */
  public function validate() {
    // @todo: Add the typed data manager as proper dependency.
    return \Drupal::typedDataManager()->getValidator()->validate($this);
  }

There are some @todo's in \Drupal\Core\TypedData\TypedData:
- Add the typed data manager as proper dependency.

Proposed resolution

1. Add the typed data manager as a proper dependency for typed data objects
2. Reuse TypedDataTrait where we already have the methods we need to implement
3. Reuse this new depedency instead of the workaround that has been implemented in TypedConfigManager & ArrayElement
4. (Follow up) Fix broken validate() getConstraints() in typed config classes.

Remaining tasks

Test, Review
Fill D8 beta evaluation template?

User interface changes

None.

API changes

Minimal, internal to TypedData objects.
- Adds two new methods in TypedData base class: getTypedDataManager(), setTypedDataManager()
- Use $this->getTypedDataManager() instead of \Drupal::typedDataManager()

Comments

Jose Reyero’s picture

FileSize
8.43 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 94,360 pass(es). View
Jose Reyero’s picture

Issue summary: View changes

Surprisingly, this patch passes tests without applying the previous one :-)

It doesn't mean it doesn't need the other for interface consistency though.

Updating description, fixing api changes.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markdorison’s picture

Version: 8.1.x-dev » 8.3.x-dev

Patch no longer applies cleanly.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
Jo Fitzgerald’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
943 bytes

Re-rolled, but not sure if there is any point in this anymore.

Status: Needs review » Needs work

The last submitted patch, 7: 2489748-7.patch, failed testing.

Jo Fitzgerald’s picture

Status: Needs work » Needs review
FileSize
353 bytes
590 bytes

Removed repeated use statement.

Status: Needs review » Needs work

The last submitted patch, 9: 2489748-9.patch, failed testing.

Jo Fitzgerald’s picture

Status: Needs work » Needs review
FileSize
534 bytes
588 bytes

Rename the function to match existing code.