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

Clash 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?
8
add a comment |Â
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?
8
add a comment |Â
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?
8
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?
8
asked Aug 16 at 12:30
Justme
740317
740317
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
accepted
Use the Entity::isNew() method:
if ($entity->isNew())
// ...
add a comment |Â
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())
// ...
add a comment |Â
up vote
4
down vote
accepted
Use the Entity::isNew() method:
if ($entity->isNew())
// ...
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Use the Entity::isNew() method:
if ($entity->isNew())
// ...
Use the Entity::isNew() method:
if ($entity->isNew())
// ...
answered Aug 16 at 12:32
Cliveâ¦
143k13241286
143k13241286
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
