Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Preparing for
#2208609: Move Json utility class into Drupal\Component\Serialization
#1920902: Add a Drupal Yaml wrapper so we can default to PECL Yaml component if it is available
#2190723: Add a KeyValueStore\FileStorage to replace e.g. ConfigStorage
Problem
- Various classes are needlessly instantiating
Symfony\Component\Yaml\Dumper
andSymfony\Component\Yaml\Parser
. - ...but only to set parameters to produce YAML that is consistent with Drupal coding standard.
Yaml
is actually a serialization format we want to standardize on.
Proposed solution
- Add a generic
Drupal\Component\Serialization\Yaml
helper class.
Ultimate goal
Drupal\Component\Serialization\Json
Drupal\Component\Serialization\PhpSerialize
Drupal\Component\Serialization\Yaml
Drupal\Component\Serialization\Xml
Comment | File | Size | Author |
---|---|---|---|
#37 | yaml.37.patch | 30.94 KB | sun |
#35 | yaml.35.patch | 30.95 KB | sun |
#33 | yaml.33.patch | 30.92 KB | sun |
#31 | interdiff.txt | 6.48 KB | sun |
#31 | yaml.31.patch | 30.87 KB | sun |
Comments
Comment #1
sunComment #3
sunSorry.
Comment #4
larowlanWe had already rejected a Yaml serializer for Drupal core on security reasons (see #1897612: Add YAML support to serialization module) or is this something different?
Comment #5
damiankloip CreditAttribution: damiankloip commented#4, this is not the same this. This would be part of a new internal API used for serializing things like YAML to files etc..
@sun, This seems like both a conflict and a regression on the patch in #1920902: Add a Drupal Yaml wrapper so we can default to PECL Yaml component if it is available. Are we going to this now so we can get some of this new conistency, as that issue will be blocked on parsing details and testbot support.
Comment #6
sunYeah, as outlined by the ultimate goal in the issue summary, this is just about consolidation + centralization + consistency (and thus also DX).
We're using the YAML serialization format in HEAD already. This patch does not add or change any usage of YAML, it only changes how code throughout core encodes and decodes YAML internally.
Comment #7
damiankloip CreditAttribution: damiankloip commentedYes, and I am just saying it conflicts totally with your patch in the other issue :) however, looks like that issue could be a complete no-go now anyway. So no conflict really...
Comment #8
sunHah, note that this is the exact same patch as in the other issue: I just (1) removed the Pecl class, (2) removed the Yaml wrapper, and (3) renamed the Symfony class into Yaml. Hence the gross failure in #1 ;-) — Thus, there is not actually a conflict between the two issues/patches. :) But indeed, given recent findings, the other issue could very well turn out to not actually happen, so it was a good idea to split this out after all. :)
Are there any objections to the proposed change, or can we move forward here? :)
Comment #9
sunComment #10
sunHm. This won't work. Two options:
YamlDiscovery
intoCore
.YamlDiscovery
to use the Yaml serialization class.Serialization
component intoComponent
.(cf. #2208609-16: Move Json utility class into Drupal\Component\Serialization)
A quick grep reveals:
Given what this class is doing — just checking whether a given filename exists in a given list of paths, and parsing all files found — I think we should go with (1) move the
YamlDiscovery
class intoDrupal\Core\Discovery
(orUtility
).Comment #11
sunMoved YamlDiscovery into Drupal\Core\Discovery.
Apparently, it lived in there once in the past already, since some stale/outdated phpDoc still references
Drupal\Core\Discovery\YamlDiscovery
.Comment #12
sunUpdated for #2203411: Convert drupal_get_library() into a service
Comment #14
damiankloip CreditAttribution: damiankloip commentedI would rather see this the other way round dI think. Move serialisation stuff into component. It's relatively generic, like YamlDiscovery.
Comment #15
sun@damiankloip: The same reasons as in #2208609-14: Move Json utility class into Drupal\Component\Serialization also apply to
YamlDiscovery
, because the following is literally all it does:It hard-codes a Drupal-specific concept of providers and corresponding file names that are being looked up in a given set of directories.
I don't even understand why this is a class in the first place... I was very tempted to actually move this into
Drupal\Core\Utility
instead of an own "Discovery" component.In any case, there's no point to expose this as a Component to the outside world. There's no concept and also no generic use-case involved that would make it worth for anyone else on this planet. :-)
Converted new instances + preexisting ones that were missing.
Comment #16
damiankloip CreditAttribution: damiankloip commentedSorry but that is the case for pretty much all of our "components" not sure why we even bother with them really..
Comment #17
sun@damiankloip: Sorry, but that is not true. Let's stick to the facts:
Transliteration
: A port ofMediaWiki
's + other transliteration components + sources, originating from https://drupal.org/project/transliteration. This is some very heavy stuff, I'd be surprised + stunned if you're able to re-implement this on your own.Gettext
: Proper reader/parser + writer forGettext
(.po) files. Epic effort, took several sprints to get right.PhpStorage
: A secure PHP file storage backend.Plugin
: A plugin system for extensible frameworks.Archiver
: A component to manage archive files. (Alternatives exist)Uuid
: A utility component for using the most optimal UUID implementation that exists on a system. (Alternatives exist, but they spawned off from this implementation)Compared to that —
YamlDiscovery
? — LOL. ;)Comment #18
damiankloip CreditAttribution: damiankloip commentedOK. Thanks for the 'evidence'. Unfollowing.
Comment #19
sunApologies, my last comment might have come across as inappropriate. That was not my intention.
What I was trying to say is that
Drupal\Component
is not only meant to contain decoupled and re-usable code (not relying on Drupal), but in addition, the contained components should actually be useful for other PHP projects and developers. — Code of a complexity that can be easily written in 5 minutes by any PHP developer does not really meet the aspect of being useful (and hence it will not get re-used).I originally split these simpler changes into separate smaller issues to facilitate reviews. At this point, the effort of the parent issue is severely blocked on these child issues.
So in case moving the code into
Drupal\Component\Serialization
would help to move forward here, then I'm happy to concede for the sake of making progress. (I'd have to adjust all other patches accordingly.)Is that the only objection and point of dissent?
Comment #20
sunComment #21
sunForgot to update issue summary.
Comment #22
sunHaha + issue title :)
Comment #23
dawehnerThis really makes part of the code way easier to read.
Comment #24
alexpottyaml.20.patch no longer applies.
Comment #25
sundiff context conflict
Comment #26
tstoecklerJust for the record:
This was not the original intention of the \Drupal\Component namespace. See /core/lib/Drupal/Component/README.txt
So if @sun's statement is in fact now community consensus, then we should update the README.txt (not this issue, of course, just sayin').
I personally disagree completely, to me the README.txt expresses exactly what \Drupal\Component is, but also I don't really care much about the location either way, so please continue :-)
Comment #28
sunDiff context conflict.
Comment #29
sunWould be great to move forward here...
#2161591: Change default active config from file storage to DB storage needlessly converts lots of code throughout core to manually pass custom arguments to
Yaml\Dumper::dump()
.Comment #31
sunUpdated new instances.
Comment #33
sunComment #35
sunComment #36
webchickNo longer applies.
Comment #37
sunComment #38
webchickOk, great. Committed/pushed to 8.x. Thanks!