On hook_entity_presave how do I now if it is a new node?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I'm using the hook



function nvgh_entity_presave(DrupalCoreEntityEntityInterface $entity) 



but I only need to do something when the node is new (not when it is edited). How to do this? I'm inspecting the entity with kint but cannot find a good indicator for this... also kint is disappearing as the node view is redirected into view modes.



How to do this?







share|improve this question


























    up vote
    2
    down vote

    favorite












    I'm using the hook



    function nvgh_entity_presave(DrupalCoreEntityEntityInterface $entity) 



    but I only need to do something when the node is new (not when it is edited). How to do this? I'm inspecting the entity with kint but cannot find a good indicator for this... also kint is disappearing as the node view is redirected into view modes.



    How to do this?







    share|improve this question






















      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm using the hook



      function nvgh_entity_presave(DrupalCoreEntityEntityInterface $entity) 



      but I only need to do something when the node is new (not when it is edited). How to do this? I'm inspecting the entity with kint but cannot find a good indicator for this... also kint is disappearing as the node view is redirected into view modes.



      How to do this?







      share|improve this question












      I'm using the hook



      function nvgh_entity_presave(DrupalCoreEntityEntityInterface $entity) 



      but I only need to do something when the node is new (not when it is edited). How to do this? I'm inspecting the entity with kint but cannot find a good indicator for this... also kint is disappearing as the node view is redirected into view modes.



      How to do this?









      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 16 at 12:30









      Justme

      740317




      740317




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          Use the Entity::isNew() method:



          if ($entity->isNew()) 
          // ...






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "220"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f267646%2fon-hook-entity-presave-how-do-i-now-if-it-is-a-new-node%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote



            accepted










            Use the Entity::isNew() method:



            if ($entity->isNew()) 
            // ...






            share|improve this answer
























              up vote
              4
              down vote



              accepted










              Use the Entity::isNew() method:



              if ($entity->isNew()) 
              // ...






              share|improve this answer






















                up vote
                4
                down vote



                accepted







                up vote
                4
                down vote



                accepted






                Use the Entity::isNew() method:



                if ($entity->isNew()) 
                // ...






                share|improve this answer












                Use the Entity::isNew() method:



                if ($entity->isNew()) 
                // ...







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 16 at 12:32









                Clive♦

                143k13241286




                143k13241286



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdrupal.stackexchange.com%2fquestions%2f267646%2fon-hook-entity-presave-how-do-i-now-if-it-is-a-new-node%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    White Anglo-Saxon Protestant

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    One-line joke