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>&nbsp;&nbsp; /**<br>&nbsp;&nbsp;&nbsp; * Generates Component config entities for all eligible discovered components.<br>&nbsp;&nbsp;&nbsp; *<br>+&nbsp;&nbsp; * @param string|null $source_id<br>+&nbsp;&nbsp; *&nbsp;&nbsp; (optional) A ComponentSource plugin ID. If omitted, will (re)generate<br>+&nbsp;&nbsp; *&nbsp;&nbsp; Component config entities for all ComponentSource plugins.<br>+&nbsp;&nbsp; * @param ComponentSourceSpecificId|null $source_specific_id<br>+&nbsp;&nbsp; *&nbsp;&nbsp; (optional) A source-specific ID in the given $source_id. If omitted, will<br>+&nbsp;&nbsp; *&nbsp;&nbsp; (re)generate Component config entities for all components.<br>+&nbsp;&nbsp; *<br>&nbsp;&nbsp;&nbsp; * @return $this<br>&nbsp;&nbsp;&nbsp; */<br>-&nbsp; public function generateComponents(): self {<br>+&nbsp; public function generateComponents(string $source_id = NULL, string $source_specific_id = NULL): self {<br>&nbsp;&nbsp;&nbsp;&nbsp; if ($this-&gt;isUpdateKernel) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return $this;<br>&nbsp;&nbsp;&nbsp;&nbsp; }</pre><p>This would enable us to change <code>\Drupal\canvas\EntityHandlers\JavascriptComponentStorage::doPostSave()</code> from</p> <pre>&nbsp; protected function doPostSave(EntityInterface $entity, $update): void {<br>&nbsp;&nbsp;&nbsp; parent::doPostSave($entity, $update);<br>&hellip;<br>&nbsp;&nbsp;&nbsp; $this-&gt;componentSourceManager-&gt;generateComponents();<br>&nbsp; }</pre><p>to</p> <pre>&nbsp; protected function doPostSave(EntityInterface $entity, $update): void {<br>&nbsp;&nbsp;&nbsp; parent::doPostSave($entity, $update);<br>&hellip;<br>&nbsp;&nbsp;&nbsp; $this-&gt;componentSourceManager-&gt;generateComponent(JsComponent::PLUGIN_ID, $entity);<br>&nbsp; }</pre><p>or even</p> <pre>&nbsp; protected function doPostSave(EntityInterface $entity, $update): void {<br>&nbsp;&nbsp;&nbsp; parent::doPostSave($entity, $update);<br>&hellip;<br>&nbsp;&nbsp;&nbsp; $this-&gt;componentSourceManager-&gt;generateComponent(JsComponent::PLUGIN_ID, $entity-&gt;id());<br>&nbsp; }</pre><p> (That entity ID is a <code>JavaScriptComponent</code> ID, not a <code>Component</code> ID!)</p>
issue