Problem/Motivation

The following list prooves that noone is aware of http://cgit.drupalcode.org/drupal/tree/core/lib/Drupal/Component/README.txt

  • \Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery relies on Doctrine\Common\Annotations\SimpleAnnotationReader
  • \Drupal\Component\Bridge\ZfExtensionManagerSfContainer relies on symfony and Zend, obviously
  • \Drupal\Component\Discovery\YamlDiscovery does not actually work
  • \Drupal\Component\Serialization\Yaml relies on Symfony\compotent\yaml

Current text:

Drupal Components are independent libraries that do not depend on the rest of
Drupal in order to function.  Components MAY depend on other Components, but
that is discouraged. Components MAY NOT depend on any code that is not part of
PHP itself or another Drupal Component.

Each Component should be in its own namespace, and should be as self-contained
as possible.  It should be possible to split a Component off to its own
repository and use as a stand-alone library, independently of Drupal.

Proposed resolution

Adapt README.txt to reality and allow us to share code with other folks!

Remaining tasks

User interface changes

API changes

Comments

dawehner’s picture

Issue summary: View changes

add current text

Crell’s picture

Since sun claimed in the previous issue that there was ambiguity, I want to just call out this line:

"Components MAY NOT depend on any code that is not part of PHP itself or another Drupal Component."

There is absolutely no ambiguity in that line. People have just been ignoring it.

sun’s picture

Status: Active » Needs review
StatusFileSize
new1.05 KB

The quoted sentence defeats the purpose of modern, decoupled OO packages/libraries. Like any other PHP package, Drupal\Component components should be able to depend on other PHP packages.

But anyway, let's shoot for a crystal clear clarification here. → See attached patch.


In case we disagree, then I can only assume the original intended policy must have been this:

  1. Drupal Components MUST consist of truly original art and fully independent library code only.
  2. Code that has any internal or external dependencies MUST NOT live in Drupal\Component.
  3. Components with only internal dependencies MUST live in Drupal\Core.
  4. Components with only external dependencies MUST be developed as a stand-alone package outside of Drupal, registered with Packagist, and pulled into Drupal via Composer.

Such a (weird) stance would cut down Drupal\Component to just a handful of [semi-]original art; e.g., Transliteration, Plugin, Gettext, PhpStorage.

I couldn't disagree more with that idea, because it attempts to enforce artificial limitations for components that would not exist otherwise.

sun’s picture

StatusFileSize
new1.09 KB
new840 bytes

Adjusted the alternative wording to be more clear.

dawehner’s picture

\Drupal\Components is the place for me where the Drupal community developers code which can also be used by other folks.
If there is an invidium (sdboyer) who decides to write his own library and include it into core via composer, this is fine as well.

  1. +++ b/core/lib/Drupal/Component/README.txt
    @@ -1,7 +1,13 @@
    +
    

    +1 for the visual distinction.

  2. +++ b/core/lib/Drupal/Component/README.txt
    @@ -1,7 +1,13 @@
    +Components MAY depend on other Drupal Components or external libraries/packages,
    +but MUST NOT depend on any other Drupal code or Drupal environment aspects.
    

    +1 for mentioning enviroment aspects! I think it is fine to drop PHP from here, because this is really kinda obvious. I tried to have a look whether symfony do have a definition, but they don't seem to have one, yet.

ParisLiakos’s picture

Like any other PHP package, Drupal\Component components should be able to depend on other PHP packages.

+1
I can understand why we dont want a component to depend on Drupal stuff, but i do not see why we cant depend on other php libraries

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Yes, let's do this.

catch’s picture

Status: Reviewed & tested by the community » Needs review

What's a Drupal environment aspect?

Crell’s picture

I wrote the original text as part of the initial namespace patch.

The intent was 2-fold:

1) Encourage the development of Drupal-decoupled (not just loosely coupled but entirely decoupled) components with the very explicit intent of them being offerable via Composer independently of Drupal.

2) Encourage the generally good practice of fully decoupled low-level components. Symfony Components consist of a mix of decoupled (eg, YAML) and loosely coupled (eg, HttpKernel) components. Generally speaking the lower-level the component the more decoupled it should be. We want to avoid "loosely coupled but deep dependency tree" systems in favor of a broad-and-shallow dependency tree.

The (admittedly rather strict) description in the current text therefore does not "defeat[] the purpose of modern, decoupled OO packages/libraries." It encourages fully separated but reusable components.

So the question is, if we soften the standard, what do we lose? I don't want to see a bunch of "components" that still have 8 layers of dependencies on each other or various other packages so that every one is a hidden megabyte worth of code. (An extreme example, yes, but given Drupal's history I think it's a not unreasonable fear.)

sun’s picture

So the question is, if we soften the standard, what do we lose? I don't want to see a bunch of "components" that still have 8 layers of dependencies on each other or various other packages so that every one is a hidden megabyte worth of code.

In case there is community consensus on that stance, then in my mind, the only remotely sensible model would be:

  1. Totally decoupled components: External libraries pulled in via Composer.

    Totally decoupled components are not Drupal code. Why would we even attempt to maintain them within Drupal to begin with? Just to have "Drupal" in their name? No, marketing is not an argument. We've learned how to integrate and contribute upstream in the meantime.

    → For example, Plugin is removed and added back to Drupal via Composer.

    → Ditto for e.g. Transliteration. (Being one of the original Transliteration module maintainers, I still care for its future.)

  2. Decoupled components that don't rely on Drupal but happen to "share" its dependencies: Drupal\Component

    → The vast majority that doesn't fit in (1) stays where it is. They'll have composer.json files, but only for potential future subtree splits.

  3. Bridge components + Drupal-specific core components: Drupal\Core

    → As-is. Any kind of dependencies, inside and outside of Drupal.

catch’s picture

#10 seems like a reasonable split, either way the wording needs fixing to reflect what's actually supposed to be in Component, but still think #8 needs fixing.

dawehner’s picture

Totally decoupled components: External libraries pulled in via Composer.

Totally decoupled components are not Drupal code. Why would we even attempt to maintain them within Drupal to begin with? Just to have "Drupal" in their name? No, marketing is not an argument. We've learned how to integrate and contribute upstream in the meantime.

→ For example, Plugin is removed and added back to Drupal via Composer.

→ Ditto for e.g. Transliteration. (Being one of the original Transliteration module maintainers, I still care for its future.)

Well, I think having Drupal as vendor would still be nice, given that the Drupal community worked on it. I would though agree that having
them separate would help us to ensure that we use proper semv.

@sun

→ As-is. Any kind of dependencies, inside and outside of Drupal.

This blocks us from sharing useful code on top of other NON-Drupal components, for example #2296205: Create a \Drupal\Component\Routing\ namespace and move Drupal-independent routing classes into it. I think it would be great to specify that in case your code just depends
on other external components, it is fine to put it somewhere where a potential subtree can happen.

jhedstrom’s picture

StatusFileSize
new702 bytes
new1.06 KB

What's a Drupal environment aspect?

This patch simply removes that second part of the sentence. I think

MUST NOT depend on any other Drupal code.

is clear enough?

Crell’s picture

Status: Needs review » Reviewed & tested by the community

I still do not support this, but the patch more accurately describes what we're doing in practice despite the potential downsides.

dawehner’s picture

A different approach could be also to add composer.json files to the Drupal/Core directories and add some suggested dependencies.

catch’s picture

Component: base system » documentation
Status: Reviewed & tested by the community » Fixed

Honestly describing what we actually do ++.

Can always revise the wording if we start handling things differently.

Committed/pushed to 8.0.x, thanks!

  • catch committed 75d9d82 on 8.0.x
    Issue #2303777 by sun, jhedstrom: Fixed Allow drupal components to...
dawehner’s picture

When each \Drupal\Components have a composer.jsonwe do have kind of explicit documentation on what other external packages they rely/build upon on.

Crell’s picture

dawehner: There's another issue somewhere to add composer.json files to everything. One or two already have them. Please add more. :-)

kim.pepper’s picture

Looks like @dawehner has created that issue already #2337283: Add a composer.json file to every component

mile23’s picture

Status: Fixed » Closed (fixed)

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