Answers.Body: <p>Turns out there is a <code>sites</code> key that can be set on an event source</p>
  <pre><code>$event-&gt;sources[] = [
      'key' =&gt; 'keyName',
      'sites' =&gt; 1,
      'label' =&gt; 'Source label',
      'criteria' =&gt; [
              ....
      ],
      'data' =&gt; [
          'handle' =&gt; 'exampleHandle',
      ],
  ];
  </code></pre>
  <p>The sites key can be set to a specific siteId value or an array of siteIds.</p>
  <p>Under Craft CMS 5, it would appear the sites value needs to be an array e.g. <code>sites =&gt; [1]</code></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-03-30T08:27:41.093Z
Answers.LastActivityDate: 2024-12-17T09:29:11.067Z
Answers.LastEditDate: 2024-12-17T09:29:11.067Z
Answers.UserDisplayName: James White
Body: <p>Is it possible to register an element source for a specific site ID, while it not appearing in another?</p>
  <p>I have a module which is currently registering element sources, however we are now looking to use Craft CMS multi-site to house another site which doesn't need these element sources. Currently the code does not have any specific site/site ID awareness in the module as there has only even been one site.</p>
  <p>What is the best way to ensure the element sources only appear on the desired site ID?</p>
  <p>I'm referring to when going to entries and switching between the sites from the dropdown next to the entries header. For both sites the element sources are appearing. I only want them to appear on one. Many of the primary sites element sources that are out of the box Craft are removed, but not the custom element sources.</p>
  <p>Thanks!</p>
  
Tags: <craft3><events><element>
Title: Registering an element source with EVENT_REGISTER_SOURCES for a specific site ID
ThreadText: # Registering an element source with EVENT_REGISTER_SOURCES for a specific site ID
  
  (Asked by: username_0 on 2023-03-21)
  
  Is it possible to register an element source for a specific site ID, while it not appearing in another?
  
  I have a module which is currently registering element sources, however we are now looking to use Craft CMS multi-site to house another site which doesn't need these element sources. Currently the code does not have any specific site/site ID awareness in the module as there has only even been one site.
  
  What is the best way to ensure the element sources only appear on the desired site ID?
  
  I'm referring to when going to entries and switching between the sites from the dropdown next to the entries header. For both sites the element sources are appearing. I only want them to appear on one. Many of the primary sites element sources that are out of the box Craft are removed, but not the custom element sources.
  
  Thanks!
  
  **Tags:** craft3, events, element
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2023-03-30. Score: 2
  
  Turns out there is a `sites` key that can be set on an event source
  
  ```
  $event->sources[] = [
      'key' => 'keyName',
      'sites' => 1,
      'label' => 'Source label',
      'criteria' => [
              ....
      ],
      'data' => [
          'handle' => 'exampleHandle',
      ],
  ];
  
  ```
  
  The sites key can be set to a specific siteId value or an array of siteIds.
  
  Under Craft CMS 5, it would appear the sites value needs to be an array e.g. `sites => [1]`
  
  
  ---
  
  