hook_preprocess_node() gets triggered while deleting a node.

Comments

deepak_zyxware created an issue. See original summary.

deepakrmklm’s picture

Title: hook_preprocess_node is triggering while deleting a node. » hook_preprocess_node gets triggered while deleting a node.
Issue summary: View changes
cilefen’s picture

Priority: Major » Normal

This is normal priority absent any indication of why it should be major.

puspanjalim’s picture

This should be fine as we are taking some action to a existing node. We can perform some task before deleting a node inside hook_preprocess_node.

Berdir’s picture

Please provide a backtrace to prove that and that it's not caused by some custom code, I don't see why that would be the case.

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)
puspanjalim’s picture

@deepak_zyxware, How you are deleting a node? hook_preprocess_node gets called only if node get rendered.

So please share some more info.

deepakrmklm’s picture

Please find the backtrace while deleting a translation.

Array
(
    [0] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Theme/ThemeManager.php
            [line] => 287
            [function] => MYTHEME_preprocess_node
        )

    [1] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 435
            [function] => render
            [class] => Drupal\Core\Theme\ThemeManager
            [type] => ->
        )

    [2] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 195
            [function] => doRender
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [3] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Template/TwigExtension.php
            [line] => 474
            [function] => render
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [4] => Array
        (
            [file] => [path]/sites/default/files/php/twig/bbb9e1d6_views-view-unformatted.html.twig_f2c5c9b5c9491a30108fad0315cdd8504b6b24bf1c65280f0e5d19601a98f504/cedd39a19c0704a5739409651aa2a52534080a744a469c0173f6fa8a3e52c0c1.php
            [line] => 54
            [function] => escapeFilter
            [class] => Drupal\Core\Template\TwigExtension
            [type] => ->
        )

    [5] => Array
        (
            [file] => [path]/vendor/twig/twig/lib/Twig/Template.php
            [line] => 432
            [function] => doDisplay
            [class] => __TwigTemplate_40586b6137274649d4e1c136c90bb8b882b1c9a26e9066ef174c4e2f2d4d90cb
            [type] => ->
        )

    [6] => Array
        (
            [file] => [path]/vendor/twig/twig/lib/Twig/Template.php
            [line] => 403
            [function] => displayWithErrorHandling
            [class] => Twig_Template
            [type] => ->
        )

    [7] => Array
        (
            [file] => [path]/vendor/twig/twig/lib/Twig/Template.php
            [line] => 411
            [function] => display
            [class] => Twig_Template
            [type] => ->
        )

    [8] => Array
        (
            [file] => [path]/core/themes/engines/twig/twig.engine
            [line] => 64
            [function] => render
            [class] => Twig_Template
            [type] => ->
        )

    [9] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Theme/ThemeManager.php
            [line] => 384
            [function] => twig_render_template
        )

    [10] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 435
            [function] => render
            [class] => Drupal\Core\Theme\ThemeManager
            [type] => ->
        )

    [11] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 448
            [function] => doRender
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [12] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 195
            [function] => doRender
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [13] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Template/TwigExtension.php
            [line] => 474
            [function] => render
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [14] => Array
        (
            [file] => [path]/sites/default/files/php/twig/bbb9e1d6_views-view.html.twig_0ef62236b277dab907bb8e0d450c33bba7b7cbdcff106dba8256b38d884b569a/379e8e985c104f234e1903b00dabd8e19e372c5ac4d3877fd3debd8af894208c.php
            [line] => 87
            [function] => escapeFilter
            [class] => Drupal\Core\Template\TwigExtension
            [type] => ->
        )

    [15] => Array
        (
            [file] => [path]/vendor/twig/twig/lib/Twig/Template.php
            [line] => 432
            [function] => doDisplay
            [class] => __TwigTemplate_d79be6a91d6cb87bf2dd4560cf9bff68dc775873ce45b89f996e64013ae1d297
            [type] => ->
        )

    [16] => Array
        (
            [file] => [path]/vendor/twig/twig/lib/Twig/Template.php
            [line] => 403
            [function] => displayWithErrorHandling
            [class] => Twig_Template
            [type] => ->
        )

    [17] => Array
        (
            [file] => [path]/vendor/twig/twig/lib/Twig/Template.php
            [line] => 411
            [function] => display
            [class] => Twig_Template
            [type] => ->
        )

    [18] => Array
        (
            [file] => [path]/core/themes/engines/twig/twig.engine
            [line] => 64
            [function] => render
            [class] => Twig_Template
            [type] => ->
        )

    [19] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Theme/ThemeManager.php
            [line] => 384
            [function] => twig_render_template
        )

    [20] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 435
            [function] => render
            [class] => Drupal\Core\Theme\ThemeManager
            [type] => ->
        )

    [21] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 448
            [function] => doRender
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [22] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 195
            [function] => doRender
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [23] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
            [line] => 226
            [function] => render
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [24] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 574
            [function] => Drupal\Core\Render\MainContent\{closure}
            [class] => Drupal\Core\Render\MainContent\HtmlRenderer
            [type] => ->
        )

    [25] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
            [line] => 227
            [function] => executeInRenderContext
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [26] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
            [line] => 117
            [function] => prepare
            [class] => Drupal\Core\Render\MainContent\HtmlRenderer
            [type] => ->
        )

    [27] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php
            [line] => 90
            [function] => renderResponse
            [class] => Drupal\Core\Render\MainContent\HtmlRenderer
            [type] => ->
        )

    [28] => Array
        (
            [file] => [path]/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php
            [line] => 111
            [function] => onViewRenderArray
            [class] => Drupal\Core\EventSubscriber\MainContentViewSubscriber
            [type] => ->
        )

    [29] => Array
        (
            [file] => [path]/vendor/symfony/http-kernel/HttpKernel.php
            [line] => 149
            [function] => dispatch
            [class] => Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
            [type] => ->
        )

    [30] => Array
        (
            [file] => [path]/vendor/symfony/http-kernel/HttpKernel.php
            [line] => 64
            [function] => handleRaw
            [class] => Symfony\Component\HttpKernel\HttpKernel
            [type] => ->
        )

    [31] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/Session.php
            [line] => 57
            [function] => handle
            [class] => Symfony\Component\HttpKernel\HttpKernel
            [type] => ->
        )

    [32] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php
            [line] => 47
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\Session
            [type] => ->
        )

    [33] => Array
        (
            [file] => [path]/core/modules/page_cache/src/StackMiddleware/PageCache.php
            [line] => 99
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\KernelPreHandle
            [type] => ->
        )

    [34] => Array
        (
            [file] => [path]/core/modules/page_cache/src/StackMiddleware/PageCache.php
            [line] => 78
            [function] => pass
            [class] => Drupal\page_cache\StackMiddleware\PageCache
            [type] => ->
        )

    [35] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php
            [line] => 47
            [function] => handle
            [class] => Drupal\page_cache\StackMiddleware\PageCache
            [type] => ->
        )

    [36] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php
            [line] => 50
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\ReverseProxyMiddleware
            [type] => ->
        )

    [37] => Array
        (
            [file] => [path]/vendor/stack/builder/src/Stack/StackedHttpKernel.php
            [line] => 23
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\NegotiationMiddleware
            [type] => ->
        )

    [38] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/DrupalKernel.php
            [line] => 652
            [function] => handle
            [class] => Stack\StackedHttpKernel
            [type] => ->
        )

    [39] => Array
        (
            [file] => [path]/index.php
            [line] => 19
            [function] => handle
            [class] => Drupal\Core\DrupalKernel
            [type] => ->
        )

)
deepakrmklm’s picture

Status: Postponed (maintainer needs more info) » Needs work
Berdir’s picture

Category: Bug report » Support request
Status: Needs work » Fixed
   [4] => Array
        (
            [file] => [path]/sites/default/files/php/twig/bbb9e1d6_views-view-unformatted.html.twig_f2c5c9b5c9491a30108fad0315cdd8504b6b24bf1c65280f0e5d19601a98f504/cedd39a19c0704a5739409651aa2a52534080a744a469c0173f6fa8a3e52c0c1.php
            [line] => 54
            [function] => escapeFilter
            [class] => Drupal\Core\Template\TwigExtension
            [type] => ->
        )

This is a view, and since it happens in the final render process, I'm 90% sure it is from a view block, which means it is specific to your site. Which means this isn't a bug but a support request. Try figuring out why you have a views block displayed there.

deepakrmklm’s picture

Status: Fixed » Needs review

Found to be triggering from Search API views.

Array
(
    [0] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Theme/ThemeManager.php
            [line] => 287
            [function] => MYTHEME_preprocess_node
        )

    [1] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 435
            [function] => render
            [class] => Drupal\Core\Theme\ThemeManager
            [type] => ->
        )

    [2] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 195
            [function] => doRender
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [3] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 151
            [function] => render
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [4] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 574
            [function] => Drupal\Core\Render\{closure}
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [5] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 152
            [function] => executeInRenderContext
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [6] => Array
        (
            [file] => [path]/modules/contrib/search_api/src/Plugin/search_api/processor/RenderedItem.php
            [line] => 299
            [function] => renderPlain
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [7] => Array
        (
            [file] => [path]/modules/contrib/search_api/src/Item/Item.php
            [line] => 245
            [function] => addFieldValues
            [class] => Drupal\search_api\Plugin\search_api\processor\RenderedItem
            [type] => ->
        )

    [8] => Array
        (
            [file] => [path]/modules/contrib/search_api/src/Entity/Index.php
            [line] => 952
            [function] => getFields
            [class] => Drupal\search_api\Item\Item
            [type] => ->
        )

    [9] => Array
        (
            [file] => [path]/modules/contrib/search_api/src/Entity/Index.php
            [line] => 1055
            [function] => indexSpecificItems
            [class] => Drupal\search_api\Entity\Index
            [type] => ->
        )

    [10] => Array
        (
            [file] => [path]/modules/contrib/search_api/src/Entity/Index.php
            [line] => 1027
            [function] => trackItemsInsertedOrUpdated
            [class] => Drupal\search_api\Entity\Index
            [type] => ->
        )

    [11] => Array
        (
            [file] => [path]/modules/contrib/search_api/search_api.module
            [line] => 299
            [function] => trackItemsUpdated
            [class] => Drupal\search_api\Entity\Index
            [type] => ->
        )

    [12] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Extension/ModuleHandler.php
            [line] => 501
            [function] => search_api_node_access_records_alter
        )

    [13] => Array
        (
            [file] => [path]/core/modules/node/src/NodeAccessControlHandler.php
            [line] => 151
            [function] => alter
            [class] => Drupal\Core\Extension\ModuleHandler
            [type] => ->
        )

    [14] => Array
        (
            [file] => [path]/core/modules/node/src/Entity/Node.php
            [line] => 137
            [function] => acquireGrants
            [class] => Drupal\node\NodeAccessControlHandler
            [type] => ->
        )

    [15] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Entity/EntityStorageBase.php
            [line] => 469
            [function] => postSave
            [class] => Drupal\node\Entity\Node
            [type] => ->
        )

    [16] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php
            [line] => 304
            [function] => doPostSave
            [class] => Drupal\Core\Entity\EntityStorageBase
            [type] => ->
        )

    [17] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Entity/EntityStorageBase.php
            [line] => 395
            [function] => doPostSave
            [class] => Drupal\Core\Entity\ContentEntityStorageBase
            [type] => ->
        )

    [18] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php
            [line] => 761
            [function] => save
            [class] => Drupal\Core\Entity\EntityStorageBase
            [type] => ->
        )

    [19] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Entity/Entity.php
            [line] => 364
            [function] => save
            [class] => Drupal\Core\Entity\Sql\SqlContentEntityStorage
            [type] => ->
        )

    [20] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Entity/ContentEntityDeleteForm.php
            [line] => 66
            [function] => save
            [class] => Drupal\Core\Entity\Entity
            [type] => ->
        )

    [21] => Array
        (
            [function] => submitForm
            [class] => Drupal\Core\Entity\ContentEntityDeleteForm
            [type] => ->
        )

    [22] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Form/FormSubmitter.php
            [line] => 111
            [function] => call_user_func_array
        )

    [23] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Form/FormSubmitter.php
            [line] => 51
            [function] => executeSubmitHandlers
            [class] => Drupal\Core\Form\FormSubmitter
            [type] => ->
        )

    [24] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Form/FormBuilder.php
            [line] => 585
            [function] => doSubmitForm
            [class] => Drupal\Core\Form\FormSubmitter
            [type] => ->
        )

    [25] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Form/FormBuilder.php
            [line] => 314
            [function] => processForm
            [class] => Drupal\Core\Form\FormBuilder
            [type] => ->
        )

    [26] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Controller/FormController.php
            [line] => 74
            [function] => buildForm
            [class] => Drupal\Core\Form\FormBuilder
            [type] => ->
        )

    [27] => Array
        (
            [function] => getContentResult
            [class] => Drupal\Core\Controller\FormController
            [type] => ->
        )

    [28] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php
            [line] => 123
            [function] => call_user_func_array
        )

    [29] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/Render/Renderer.php
            [line] => 574
            [function] => Drupal\Core\EventSubscriber\{closure}
            [class] => Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber
            [type] => ->
        )

    [30] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php
            [line] => 124
            [function] => executeInRenderContext
            [class] => Drupal\Core\Render\Renderer
            [type] => ->
        )

    [31] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php
            [line] => 97
            [function] => wrapControllerExecutionInRenderContext
            [class] => Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber
            [type] => ->
        )

    [32] => Array
        (
            [function] => Drupal\Core\EventSubscriber\{closure}
            [class] => Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber
            [type] => ->
        )

    [33] => Array
        (
            [file] => [path]/vendor/symfony/http-kernel/HttpKernel.php
            [line] => 144
            [function] => call_user_func_array
        )

    [34] => Array
        (
            [file] => [path]/vendor/symfony/http-kernel/HttpKernel.php
            [line] => 64
            [function] => handleRaw
            [class] => Symfony\Component\HttpKernel\HttpKernel
            [type] => ->
        )

    [35] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/Session.php
            [line] => 57
            [function] => handle
            [class] => Symfony\Component\HttpKernel\HttpKernel
            [type] => ->
        )

    [36] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php
            [line] => 47
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\Session
            [type] => ->
        )

    [37] => Array
        (
            [file] => [path]/core/modules/page_cache/src/StackMiddleware/PageCache.php
            [line] => 99
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\KernelPreHandle
            [type] => ->
        )

    [38] => Array
        (
            [file] => [path]/core/modules/page_cache/src/StackMiddleware/PageCache.php
            [line] => 78
            [function] => pass
            [class] => Drupal\page_cache\StackMiddleware\PageCache
            [type] => ->
        )

    [39] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php
            [line] => 47
            [function] => handle
            [class] => Drupal\page_cache\StackMiddleware\PageCache
            [type] => ->
        )

    [40] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php
            [line] => 50
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\ReverseProxyMiddleware
            [type] => ->
        )

    [41] => Array
        (
            [file] => [path]/vendor/stack/builder/src/Stack/StackedHttpKernel.php
            [line] => 23
            [function] => handle
            [class] => Drupal\Core\StackMiddleware\NegotiationMiddleware
            [type] => ->
        )

    [42] => Array
        (
            [file] => [path]/core/lib/Drupal/Core/DrupalKernel.php
            [line] => 652
            [function] => handle
            [class] => Stack\StackedHttpKernel
            [type] => ->
        )

    [43] => Array
        (
            [file] => [path]/index.php
            [line] => 19
            [function] => handle
            [class] => Drupal\Core\DrupalKernel
            [type] => ->
        )

)
Berdir’s picture

Status: Needs review » Fixed

Yes. that's triggered by an $entity->save(), which happens if you "delete" a translation. That causes search_api to re-index and you have the rendered entity enabled I guess.

Everything working as expected. You could for example disable immediate indexing, then that will happen later on cron.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.