Guest User

Untitled

a guest
Jun 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. ...
  2. class ContentTitle extends RulesActionBase {
  3.  
  4. protected function doExecute(EntityInterface $entity) {
  5.  
  6. $entity_id = $entity->id(); // Getting dynamic entity ID
  7. $controller = Drupal::entityManager()->getStorage('node');
  8. $node = $controller->load($entity_id);
  9.  
  10. $title = $entity->label();
  11. $item = $node->get('field_xyz')->value;
  12. $new_title = "Title is " . $title . $item;
  13.  
  14. Drupal::logger('custom_rules')->notice('new_title: ' . $new_title);
  15.  
  16. $data = array(
  17. 'type' => 'custom_content',
  18. 'title' => [
  19. 'value' => $new_title,
  20. ]
  21. );
  22. $node = Drupal::entityManager()
  23. ->getStorage('node')
  24. ->create($data);
  25. $node->save();
  26. }
  27. }
  28.  
  29. use DrupalnodeEntityNode;
  30.  
  31. class ContentTitle extends RulesActionBase {
  32.  
  33. protected function doExecute(EntityInterface $entity) {
  34. $entity_id = $entity->id(); // Getting dynamic entity ID
  35. $controller = Drupal::entityManager()->getStorage('node');
  36. $node = $controller->load($entity_id);
  37. $title = $entity->label();
  38. $item = $node->get('field_xyz')->value;
  39. $new_title = "Title is " . $title . $item;
  40. Drupal::logger('custom_rules')->notice('new_title: ' . $new_title);
  41. $node = Node::create([
  42. 'type' => 'content_type',
  43. 'title' => $new_title,
  44. ]);
  45. $node->save();
  46. }
  47. }
  48.  
  49. $node->set('title', $new_title);
  50. $node->save();
Add Comment
Please, Sign In to add comment