Add the ability for ComponentSourceManager to generate a Component config entity for a single source, or even a single specific component
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3561272. -->
Reported by: [phenaproxima](https://www.drupal.org/user/205645)
Related to !407
>>>
<h3 id="overview">Overview</h3>
<p>See <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3556327" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3556327</a></span>'s <a href="https://git.drupalcode.org/project/canvas/-/merge_requests/378#note_634136">https://git.drupalcode.org/project/canvas/-/merge_requests/378#note_634136</a></p>
<p>It might be helpful for ComponentSourceManager to have the ability to generate <code>Component</code> config entities, if necessary, for a single specific component source, or even a single component in that source. Right now it just generates entities for all the components it can, across all sources.</p>
<h3 id="proposal">Proposed solution</h3>
<pre>diff --git a/src/ComponentSource/ComponentSourceManager.php b/src/ComponentSource/ComponentSourceManager.php<br>index 6ed03cce0..e714bc438 100644<br>--- a/src/ComponentSource/ComponentSourceManager.php<br>+++ b/src/ComponentSource/ComponentSourceManager.php<br>@@ -64,9 +64,16 @@ final class ComponentSourceManager extends DefaultPluginManager {<br> /**<br> * Generates Component config entities for all eligible discovered components.<br> *<br>+ * @param string|null $source_id<br>+ * (optional) A ComponentSource plugin ID. If omitted, will (re)generate<br>+ * Component config entities for all ComponentSource plugins.<br>+ * @param ComponentSourceSpecificId|null $source_specific_id<br>+ * (optional) A source-specific ID in the given $source_id. If omitted, will<br>+ * (re)generate Component config entities for all components.<br>+ *<br> * @return $this<br> */<br>- public function generateComponents(): self {<br>+ public function generateComponents(string $source_id = NULL, string $source_specific_id = NULL): self {<br> if ($this->isUpdateKernel) {<br> return $this;<br> }</pre><p>This would enable us to change <code>\Drupal\canvas\EntityHandlers\JavascriptComponentStorage::doPostSave()</code> from</p>
<pre> protected function doPostSave(EntityInterface $entity, $update): void {<br> parent::doPostSave($entity, $update);<br>…<br> $this->componentSourceManager->generateComponents();<br> }</pre><p>to</p>
<pre> protected function doPostSave(EntityInterface $entity, $update): void {<br> parent::doPostSave($entity, $update);<br>…<br> $this->componentSourceManager->generateComponent(JsComponent::PLUGIN_ID, $entity);<br> }</pre><p>or even</p>
<pre> protected function doPostSave(EntityInterface $entity, $update): void {<br> parent::doPostSave($entity, $update);<br>…<br> $this->componentSourceManager->generateComponent(JsComponent::PLUGIN_ID, $entity->id());<br> }</pre><p>
(That entity ID is a <code>JavaScriptComponent</code> ID, not a <code>Component</code> ID!)</p>
issue