Answers.Body: <p>Maybe you better use this kind of a event for your custom logic?</p>
  <pre><code>use craft\elements\Entry;
  use craft\events\ModelEvent;
  use yii\base\Event;
  
  ....
  
      Event::on(
          Entry::class,
          Entry::EVENT_BEFORE_SAVE,
          static function (ModelEvent $e) {
            
          }
      );
  </code></pre>
  <p>or</p>
  <pre><code>Event::on(
      Element::class,
      Element::EVENT_BEFORE_SAVE,
      static function (ModelEvent $$e) {
          // ...
      }
  );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-07T13:11:52.640Z
Answers.Text: Actually, the function on `EVENT_BEFORE_PREPARE` has already been made, but a problem was found. So, I would like to prevent the function only if `$event` is saving an entry.
Answers.UserDisplayName: Kota.M
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-07T20:58:56.557Z
Answers.Text: Not really sure what you want to do, but try looking at these options -> https://craftcms.com/docs/3.x/extend/events.html#event-code-generator
  https://i.imgur.com/zGP07xe.png
  Perhaps your problem is that every time you save the entry, you re-save the assets
Answers.UserDisplayName: RomanAvr
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-10-06T22:04:24.363Z
Answers.LastActivityDate: 2022-10-06T22:04:24.363Z
Answers.UserDisplayName: RomanAvr
Body: <p>I have been implementing my own module like this;</p>
  <pre><code>protected function myFunction()
  {
      Event::on(
      ElementQuery::class,
      ElementQuery::EVENT_BEFORE_PREPARE,
      function(Event $event) {
  
          if ($event-&gt;sender-&gt;elementType === 'craft\elements\Asset')
          {
              // DO SOMETHING...
  </code></pre>
  <p>However, I do not want to perform this function when an entry is saved. It seems that <code>EVENT_BEFORE_PREPARE</code> is triggered when I save an entry. So, is it possible to detect if the event is saving an entry or not?</p>
  
Tags: <craft3><php><modules><events>
Title: Can I detect if the event is saving entry?
ThreadText: # Can I detect if the event is saving entry?
  
  (Asked by: username_0 on 2022-10-06)
  
  I have been implementing my own module like this;
  
  ```
  protected function myFunction()
  {
      Event::on(
      ElementQuery::class,
      ElementQuery::EVENT_BEFORE_PREPARE,
      function(Event $event) {
  
          if ($event->sender->elementType === 'craft\elements\Asset')
          {
              // DO SOMETHING...
  
  ```
  
  However, I do not want to perform this function when an entry is saved. It seems that `EVENT_BEFORE_PREPARE` is triggered when I save an entry. So, is it possible to detect if the event is saving an entry or not?
  
  **Tags:** craft3, php, modules, events
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-10-06. Score: 1
  
  Maybe you better use this kind of a event for your custom logic?
  
  ```
  use craft\elements\Entry;
  use craft\events\ModelEvent;
  use yii\base\Event;
  
  ....
  
      Event::on(
          Entry::class,
          Entry::EVENT_BEFORE_SAVE,
          static function (ModelEvent $e) {
            
          }
      );
  
  ```
  
  or
  
  ```
  Event::on(
      Element::class,
      Element::EVENT_BEFORE_SAVE,
      static function (ModelEvent $$e) {
          // ...
      }
  );
  
  ```
  
  > **Comments:**
  > **username_0**: Actually, the function on `EVENT_BEFORE_PREPARE` has already been made, but a problem was found. So, I would like to prevent the function only if `$event` is saving an entry.  
  > **username_1**: Not really sure what you want to do, but try looking at these options -> https://craftcms.com/docs/3.x/extend/events.html#event-code-generator https://i.imgur.com/zGP07xe.png Perhaps your problem is that every time you save the entry, you re-save the assets  
  
  ---
  
  