Problem/Motivation

Drupal Components are abstracted parts of Drupal core. They can be used independently in their own projects. In order to use the Drupal Components outside of a Drupal project however, you have to download Drupal 8, and then copy/paste the files of the Drupal Component into your own project. This can be tedious and there are easier ways of exposing the components to outside projects.

Proposed resolution

Mimic how Symfony exposes its components and allow projects outside of Drupal to use the Drupal components by...

  1. Introducing a composer.json for each component
  2. Creating a subpath split in a new repository for each component: #2513388: Create (and maintain) a subtree split of each Drupal Component
  3. The subpath split needs to be automated as a post-commit hook or re-executed on a daily basis.
  4. Post the components on https://packagist.org

For each item in the Drupal\Compnent namespace:

  • Add composer.json.
  • Add README, LICENSE, whatever else.
  • Make subtree split.
  • Ignore tests (for now).
  • Publish to packagist.org.

The development process for these packages is:

  • People use the packages through Composer.
  • They find a bug.
  • They read TESTING.txt which says "You can't test this unless you get the full-stack Drupal."
  • They read the README.txt which says, "Find us in https://www.drupal.org/project/issues/drupal"
  • They start submitting patches on d.o.

Remaining tasks

  • Allow licensing text files in our coding standard.
  • Determine how to be flexible with licensing: #1713080: Allow code in Drupal\Component to be used by non-GPL projects
  • Figure out who will maintain the packagist.org entries.The DA does, via our ownership of github's Drupal acct, and our ownership of the drupal/ namespace on packagist
  • Determine a composer.json template for components.
  • Create composer.json files per Component: #2337283: Add a composer.json file to every component
  • Add subtree split support as an automated process somewhere in our infrastructure.
  • Create Drupal project issue components for each component released in this way.

User interface changes

No UI changes.

API changes

Outside projects could then state that they require "drupal/plugin", and Composer would download the Plugin Component.

Comments

EclipseGc’s picture

Plus a 1000000000000000 for this!

Tor Arne Thune’s picture

Oh yes, share the goods.

RobLoach’s picture

Issue summary: View changes

dfgs

sun’s picture

One task, perhaps the most essential and most troublesome, is missing in the task list:

The subpath split needs to be automated as a post-commit hook or re-executed on a daily basis.

sun’s picture

Issue summary: View changes

das

RobLoach’s picture

The subpath split needs to be automated as a post-commit hook or re-executed on a daily basis.

Thanks, added.

Crell’s picture

This is exactly what I was hoping we'd move to with the Components namespace. +1 google. :-)

RobLoach’s picture

Made a sub-tree split of /core:
http://github.com/robloach/core/tree/8.x

RobLoach’s picture

Issue summary: View changes

fsd

EclipseGc’s picture

Title: Expose Drupal Components outside of Drupal » [Meta] Expose Drupal Components outside of Drupal
Issue summary: View changes
flip101’s picture

I'm a symfony 2 developer and i'm interested in the component that lets you compose a form in the user interface (does that have a name?). Using the same packaging strategy as symfony 2 allows the components to get more traction and thus more cooperation. +1

fgm’s picture

@flip01 you are probably thinking of the webform module http://drupal.org/project/webform : this is a contributed module, not part of core, so not affected by this discussion.

Mile23’s picture

The issue summary says this:

  1. Introducing a composer.json for each component
  2. Creating a subpath split in a new repository for each component
  3. The subpath split needs to be automated as a post-commit hook or re-executed on a daily basis.
  4. Post the components on https://packagist.org

But that's not what needs to happen.

Each component must become its own d.o project.

For instance, with Drupal\Component\Plugin, we'd need the following:

  1. Figure out who will maintain this new project.
  2. Perform the subpath split once on core/lib/Drupal/Component/Plugin.
  3. Move all the resulting files into a src/ directory.
  4. Figure out how to move tests/lib/Drupal/Tests/Component/Plugin under tests/ without losing history.
  5. Add README.
  6. Add documentation.
  7. Add composer.json.
  8. Push to awaiting d.o project, named something like component_plugin.
  9. Add packagist.org entry.
  10. Remove Drupal\Component\Plugin namespace from core.
  11. Add dependency within Drupal.
  12. Have api.drupal.org spider the new project.
tim.plunkett’s picture

@Mile23, please open a 9.x issue for that.

Mile23’s picture

Can't just promote this one to 9.x?

dawehner’s picture

@Mile23
The way how you also could do it, is to provide subtree splits ... as well as add composer.json to all components in core directly.

EclipseGc’s picture

Tests are a problem here, but I don't see how that negates the current IS.

Eclipse

dawehner’s picture

Well, in that case we could move around the tests and adapt our phpunit configuration to point to those specific tests.
I don't see a big problem with doing that, beside that its maybe out of scope of 8.0

EclipseGc’s picture

Yeah, I'm not sure delivering tests with the component is of greater value than exposing the component. I'd much rather make our stuff available w/o tests than delay the whole thing till we can reorganize the code.

Eclipse

dawehner’s picture

The only advantage I see is that new people coming to the project willing to work on a component will have a easier time finding those tests.

EclipseGc’s picture

I absolutely agree.

Crell’s picture

Moving the tests around is a nice-to-have IMO. One wouldn't be able to send in patches or PRs against one of the forked components anyway; you'd need to work against Drupal itself. For now let's just add a bunch of composer.json files.

dawehner’s picture

Mile23’s picture

Clarifying the original issue with some steps to take.

davidwbarratt’s picture

Mile23’s picture

Mile23’s picture

Issue summary: View changes
xjm’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue tags: +Needs framework manager review

Moving to 8.1.x as per #2600718-17: Add composer.json to \Drupal\Component\Bridge component.. Also tagging for framework manager review. Thanks!

xjm’s picture

Come to think of it, we probably also need to have Dries sign off on this, since it's the philosophy and structure of the project and blah blah etc. Not assigning to him just yet though until the framework managers can give their review.

EclipseGc’s picture

So I understand that this isn't in the list of things we can commit in 8.0.x, but I don't see why we couldn't alter that for composer.json files in Components. Do we have a documented reason why that sort of change would not be acceptable? I'll admit, from all the conversations I've had on this topic, I'd always assumed that composer.json files during the 8.0.x release cycle were completely ok. I could also understand requiring them in 8.1.x first with backports, but I'd hate to see this entire meta's scope postponed to the next Drupal version. (looking for clarity here, I realize we probably need Dries to point the way on this)

On a similar note, I have been encouraged on multiple occasions to just make Plugins & company available via composer on github repos. I have resisted thus far, because I feel like doing that would slow down the process of exposing our own components, which I think is of great value. If we could:

  1. Get Dries perspective on this
  2. Assuming that's a general green light, get d.o perspective on this

I think those two things would go a LONG way toward setting reasonable expectations around this, and we could discuss what other related solutions we might want to consider in the mean time.

Eclipse

dawehner’s picture

Come to think of it, we probably also need to have Dries sign off on this, since it's the philosophy and structure of the project and blah blah etc.

This is odd, because we already expose multple of them, and well, those didn't needed signoff dries:

In general this is not a decision in my point of view ...
If there is a reason against exposing this to the wider PHP community, we have an insurmountable philosophical disagreement.

What I also don't understand, is how this changes
anything on the structure of the project. We don't split up the repository.

Mile23’s picture

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

So there are a few steps here...

One is to add some files to the repo. #2337283: Add a composer.json file to every component

Another is to split the repo using subtree split, and maintain that, and maintain listings on packagist. #2513388: Create (and maintain) a subtree split of each Drupal Component

Is it possible that we can do the former in 8.0.x, while we have work being done by newbies who are motivated, and postpone the latter, with the possibility that maybe we can revisit it when the former is done?

alexpott’s picture

Version: 8.0.x-dev » 8.1.x-dev
Issue tags: -Needs framework manager review

These changes are not bug fixes and therefore there's no need to do this in 8.0.x as @xjm said in #27. 8.0.x is for bug fixes to stable code.

Re #28 Dries already approved this in #2176065-33: Introduce a composer.json for Drupal\Component\Utility

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

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now 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.

Mile23’s picture

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

Wondering if there's any possibility for this during 8.1.x instead of 8.2.x.

xjm’s picture

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

This needs to be done in the development minor, which is 8.3.x now. Thanks!

dawehner’s picture

Well one more important part is to actually expose them on packagist, which the owner of the namespace have to do.

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.

davidwbarratt’s picture

Has any progress been made on this? I would like to use some of Drupal's components in a non-Drupal project. :/

Mile23’s picture

Mile23’s picture

dawehner’s picture

IMHO we could have issues for the following bits:

  • expose the components in core/lib/Drupal/Core/*. It is tricky to get the dependencies right
  • Expose the individual modules in core/modules/*. It is tricky to get the dependencies right
  • Expose the individual themes in core/themes/*
Mile23’s picture

New child issue that cleans up the composer dependencies of the components: #2867960: Merge Component composer.json files to account for them during build

Actually *requiring* the components (instead of just replacing them, like we do now in core/composer.json) would mean having two copies of the code, one under core/lib and one under vendor/.

Also this one, which is pretty big in scope: #2385395: Make Drupal core folder agnostic and allow it to be placed in vendor/drupal/core

Mixologic’s picture

Status: Active » Reviewed & tested by the community

Everything on this meta is done, except for the licensing issue, and based on that issue, its not even clear that it is something that needs to be/should be done.

Im going to mark this RTBC and somebody else can close it.

Mile23’s picture

Status: Reviewed & tested by the community » Active

Once #2867960: Merge Component composer.json files to account for them during build is fixed, we'll have made all the components consumable by other projects.

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

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

Version: 8.5.x-dev » 8.6.x-dev

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

Mile23’s picture

Status: Active » Reviewed & tested by the community
alexpott’s picture

@Mile23 has there been any discussion about where the tests for each component should live? I guess we can't move them into each component whilst each component folder doesn't have a src folder too. That would be quite a bit re-organisation but it would be nice.

I guess we could mark this fixed? It would be nice if someone goes through the issue summary and uses the strikethrough to mark what's done.

Mixologic’s picture

Issue summary: View changes

I struck out the stuff in the issue summary that I was aware of being done.

I did find a couple issues that we'll need to follow up on:

Add README, LICENSE, whatever else

The LICENSE.txt file for both the Serialization and the Transliteration components are blank files.

Ignore tests (for now).

Maybe a follow up for putting the tests for components with the components.

Allow licensing text files in our coding standard.

I dont know if this is done or not. But we're not codesniffing txt files so....

Create Drupal project issue components for each component released in this way.

Not sure what this means exactly... have a 'project' on drupal.org so we have component specific issues?

Anyhow, these are on packagist.org, and drupalci happily depends on core-annotation and core-plugin. Thanks for the code Drupal!

Mile23’s picture

Create Drupal project issue components for each component released in this way.

Basically I think this is saying make each component its own d.o project. I guess we're deciding not to do that by figuring out how to move the tests to the components.

@Mile23 has there been any discussion about where the tests for each component should live? I guess we can't move them into each component whilst each component folder doesn't have a src folder too.

Since we're merging the components' composer.json now, we can specify autoload and autoload-dev per component, and take the Drupal\Component namespace out of core/composer.json's autoload section. Then we can put the tests in the component directory. That would mean a composer dumpautoload per live site, so it's a teensy bit disruptive, but not really since you're going to composer install the update anyway. It's also not terribly tricky.

Mile23’s picture

Status: Reviewed & tested by the community » Active

Added child issue. I guess this meta's still active. :-)

#2943842: Allow component namespaces to be autoloaded independently

Mile23’s picture

Mixologic’s picture

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Mile23’s picture

Issue tags: +Drupal 9

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

joachim’s picture

The components all need READMEs that actually explain how to use them, otherwise there is no point in making them usable as standalone packages.

Currently, all they say is a cheery "Thanks for using this Drupal component."

Great, but HOW do I use it?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xjm’s picture

We need a way to make the composer.json files maintainable: #3272110: Drupal 9 and 10's Drupal\Component composer.json files are totally out of date

They are broken for D9+ but no one has noticed...

cilefen’s picture

Is this a feature in search of a use-case in 2022? There is a nonzero support burden. Would anyone actually use these things?

parisek’s picture

I'm using it in https://packagist.org/packages/parisek/twig-attribute eg. in WordPress theming :)

xjm’s picture

@cilefen I said similar things in Slack (and actually my original issue was significantly more, er, scathing).

Apparently some people use them. I drilled in a bit on package usage. A whole four non-core components depend on the Render component, for example. @larowlan also mentioned using them to add utility functionality to D7 sites. 🤷‍♀️

Is it worth the maintenance burden for that? Meh. For me, I'm inclined to say no unless the process for updating them can be wholly automated, and I hope that the people who want these packages to exist could take the time to do the automating.

Mile23’s picture

DrupalCI uses drupal/core-annotation.

neclimdul’s picture

Hey, guess why I'm here... I found myself needing to use Attribute and some render components for twig stuff outside Drupal today. 🙃 Glad Parisek's project was there because it pretty much exactly what I was looking for but would have been nice to have been exposed by core.

I also use core-utility in a Laravel app that need align some processing with the main Drupal site.

Also, I don't currently use it, but I've used NestedArray and Timer from core-utility for misc one of scripts and testing because I've not found a lot similarly useful libraries.

_Also_ I've been arguing since we started building /lib that doing this provides its own value. Pushing things down to components that can be split forces us to unravel complexity and write better less smelly code. Still see that as true.

Mile23’s picture

+1 on less smelly.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.