We want to leverage annotations to ease providing data types to the typed data API. Right now, plugins are not found below core component directories, so the API uses hook discovery and an ugly system_data_type_info() implementation.

Let's resolve #1828616: AnnotatedClassDiscovery is not finding plugins in Drupal\(Core|Component)\COMPONENT_NAME\Plugin directory, then switch discovery over. Postponed on this issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fago’s picture

Component: base system » typed data system
Status: Postponed » Active

Given that we already can pass custom namespace to the annotation discovery, we do not have to postpone this on the proper solution of #1828616: AnnotatedClassDiscovery is not finding plugins in Drupal\(Core|Component)\COMPONENT_NAME\Plugin directory any more.

fago’s picture

Issue tags: +Typed sanity

discussed with berdir and we thinkg going with "DataType" as directory name here should be fine.

EclipseGc’s picture

What are you going to name your annotation class?

fago’s picture

We'd go with @DataType ?

fubhy’s picture

Assigned: Unassigned » fubhy
fubhy’s picture

Assigned: fubhy » Unassigned
Status: Active » Needs review
FileSize
446.04 KB
141.45 KB
fubhy’s picture

Note: I wrote the patch based on #1969728: Implement Field API "field types" as TypedData Plugins as suggested by @fago. Please review 1867856-including-field-type-plugins.patch

Status: Needs review » Needs work
Issue tags: -Entity Field API, -typed data, -Typed sanity

The last submitted patch, 1867856-including-field-type-plugins.patch, failed testing.

fubhy’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
Issue tags: +Entity Field API, +typed data, +Typed sanity

The last submitted patch, 1867856-including-field-type-plugins.patch, failed testing.

fubhy’s picture

Status: Needs review » Needs work

The last submitted patch, 1867856-11-including-field-type-plugins.patch, failed testing.

fubhy’s picture

Status: Needs work » Needs review
FileSize
152.65 KB

#1969728: Implement Field API "field types" as TypedData Plugins just got commited. Here is a re-roll including fixes for those test fails.

Berdir’s picture

Same patch, just with moves, so that the patch is much easier to review.

fubhy’s picture

+++ b/core/lib/Drupal/Core/TypedData/Annotation/DataType.phpundefined
@@ -0,0 +1,35 @@
+/**
+ * Defines a data type annotation object.
+ *
+ * @Annotation
+ */
+class DataType extends Plugin {
+
+  /**
+   * The name of the module providing the type.
+   *
+   * @var string
+   */
+  public $module;
+
+  /**
+   * The name of the data type class.
+   *
+   * This is not provided manually, it will be added by the discovery mechanism.
+   *
+   * @var string
+   */
+  public $class;
+
+}

We probably want to put more in there (like constraints, etc.). The rest is mostly moving things around.

dawehner’s picture

+++ b/core/lib/Drupal/Core/TypedData/Annotation/DataType.phpundefined
@@ -0,0 +1,35 @@
+class DataType extends Plugin {

+++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Any.phpundefined
@@ -15,6 +17,11 @@
+ * @DataType(
...
+ *   label = @Translation("Any data")
+ * )

The point is to document each property, so please add label and maybe also description.

fubhy’s picture

This issue just moves stuff around. That documentation was not introduced here. Lets fix it in a follow-up.

EclipseGc’s picture

FileSize
8.34 KB
156.85 KB

Ok, I reviewed this and then managed to lose my review so, me--

The short version is this:

The Annotation class is all wrong, none of the stuff in it needs to be there and the stuff that should be there isn't.

The TypedDataManager should extend DefaultPluginManager and leverage the goodness there. The TypedDataManager should also stop proxying its stuff to TypedDataFactory. We should just move the contents of TypedDataFactory into the manager and call it good. Likewise all references to $this->discovery and $this->factory should go once that cleanup is done.

It should all look a little something like this:

Eclipse

fago’s picture

The TypedDataManager should extend DefaultPluginManager and leverage the goodness there. The TypedDataManager should also stop proxying its stuff to TypedDataFactory. We should just move the contents of TypedDataFactory into the manager and call it good. Likewise all references to $this->discovery and $this->factory should go once that cleanup is done.

Agreed - it should not hold up this patch through as it's nothing that has to go through before code freeze, so I'm not sure we should deal with it here or in a follow-up issue.

fago’s picture

ops, just realised you re-rolled the patch, so forget my comment about holding anything up.. :D

interdiff looks good except for:

+++ b/core/lib/Drupal/Core/TypedData/Annotation/DataType.php
@@ -17,19 +17,34 @@
+   * The human-readable name of the data type.
+   *
+   * @ingroup plugin_translatable
+   *
+   * @var \Drupal\Core\Annotation\Translation
    */
-  public $class;
+  public $description;

That's not the name, it's description.

EclipseGc’s picture

FileSize
1.19 KB
156.9 KB

After a little discussion with fago in irc I found that there should be an alter hook for the definitions, so I readded that back in. if 18 comes back green, then we're obviously missing tests. This patch also fixes his description issue from 20

Eclipse

Status: Needs review » Needs work

The last submitted patch, 1867856-21.patch, failed testing.

fgm’s picture

Just wanted to note that, should this issue does not reach resolution, hook_data_type_info() would need to be documented: it current has two implementations, but no definition in a .api.php file.

Berdir’s picture

@fgm: This patch removes a hook_data_type_info() in system.api.php?

fgm’s picture

@berdir : yes, I can see that now. Don't know why I could not find it yesternight, must have been too late. Just ignore my remark.

fubhy’s picture

Status: Needs work » Needs review
FileSize
10.68 KB
76.86 KB

Refactoring TypedConfigManager to include SchemaDiscovery and that factory and extended PluginManagerBase directly instead.

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

Ok, that whole manager is totally weird, but if we have to hack around it for the time being, I'm 100% ++ My contributions to this were specifically around using DefaultPluginManager which is pretty straight forward and well represented elsewhere in core, so I feel pretty comfortable rtbcing this.

Eclipse

fago’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/TypedData/Annotation/DataType.php
@@ -0,0 +1,50 @@
+ * @Annotation
+ */
+class DataType extends Plugin {

This is incomplete (constraints) - be sure to replicate all the docs from hook_data_type_info().

Else this looks good to me.

fubhy’s picture

Status: Needs work » Needs review
FileSize
2.25 KB
77.84 KB
Jose Reyero’s picture

Though I don't really understand the full extent of this patch, the TypedConfigManager changes look ok to me

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

Ok then, let's try this again.

Eclipse

fago’s picture

Yep, this looks good now!

Jose Reyero’s picture

Related, as we are moving around SchemaDiscovery, there's some issue with that class: it loads all the data from the constructor instead of from getDefinitions(), and that's the reason why just instantiating it adds some processing and creates lots of plugins...
(That could be another patch I guess, just in case this needs some reroll it could be fixed here too, otherwise I'll create some follow up...)

EclipseGc’s picture

That entire PluginType (TypedConfigManager) needs some serious review. I think that needs its own issue though.

Eclipse

fubhy’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
78.93 KB
5.33 KB

Fixing some problems with TypedConfigManager. Jose found a performance problem with TypedConfigManager which we can fix right here. The schema should not always be loaded on construct directly but rather only when it's requested in ::getDefinitions(). Also, ::getDefinition() should not alter $this->definitions. In fact, there should probably be another method that covers these fallback scenariors. But that's follow-up material.

fubhy’s picture

Status: Needs review » Reviewed & tested by the community

Okay, RTBC for #29 again. Let's fix the performance issues in a follow-up so we can get this in now.

Please commit the patch from comment #29

fubhy’s picture

Opened a follow-up for the TypedConfigManager and uploaded the patch there: #2030859: Improve TypedConfigManager. Let's get #29 in asap (very helpful for param converter / typed data).

fubhy’s picture

*meow*

kfritsche’s picture

Assigned: Unassigned » kfritsche
kfritsche’s picture

Assigned: kfritsche » Unassigned
fubhy’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
77.81 KB
705 bytes

I blame the reviewers.

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

Assuming that passes, this is still rtbc. It was just a comment change.

Eclipse

Berdir’s picture

Priority: Normal » Major

Raising to major, as discussed with @xjm.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 2c2f5f5 and pushed to 8.x. Thanks!

andypost’s picture

Berdir’s picture

Updated https://drupal.org/node/1806650 and added an example of how to define a data type, did not exist before.

Automatically closed -- issue fixed for 2 weeks with no activity.