forum_node_presave(EntityInterface $node)
Implements hook_ENTITY_TYPE_presave() for node entities.
Assigns the forum taxonomy when adding a topic from within a forum.
File
- core/modules/forum/forum.module, line 150
- Provides discussion forums.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | function forum_node_presave(EntityInterface $node ) { if (\Drupal::service( 'forum_manager' )->checkNodeType( $node )) { // Make sure all fields are set properly: $node ->icon = ! empty ( $node ->icon) ? $node ->icon : '' ; if (! $node ->taxonomy_forums->isEmpty()) { $node ->forum_tid = $node ->taxonomy_forums->target_id; // Only do a shadow copy check if this is not a new node. if (! $node ->isNew()) { $old_tid = \Drupal::service( 'forum.index_storage' )->getOriginalTermId( $node ); if ( $old_tid && isset( $node ->forum_tid) && ( $node ->forum_tid != $old_tid ) && ! empty ( $node ->shadow)) { // A shadow copy needs to be created. Retain new term and add old term. $node ->taxonomy_forums[ count ( $node ->taxonomy_forums)] = array ( 'target_id' => $old_tid ); } } } } } |
Please login to continue.