Created
September 18, 2017 04:50
-
-
Save adityaanurag/5a34580bc69fa2d21e804f6edcfbaede to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\article_queue\Plugin\QueueWorker; | |
use Drupal\Core\Queue\QueueWorkerBase; | |
use Drupal\node\Entity\Node; | |
/** | |
* Processes Node Tasks. | |
* | |
* @QueueWorker( | |
* id = "article_queue_processor", | |
* title = @Translation("Task Worker: Node"), | |
* cron = {"time" = 10} | |
* ) | |
*/ | |
class ArticleQueueProcessor extends QueueWorkerBase { | |
/** | |
* {@inheritdoc} | |
*/ | |
public function processItem($response) { | |
if (!empty($response->title)) { | |
$node = Node::create([ | |
'type' => 'article', | |
]); | |
$node->set('title', $response->title); | |
$node->set('created', $response->created); | |
$body = [ | |
'value' => html_entity_decode($response->body->value), | |
'format' => $response->body->format, | |
]; | |
$node->set('body', $body); | |
$node->save(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment