Skip to content

Instantly share code, notes, and snippets.

@adityaanurag
Created September 18, 2017 04:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityaanurag/5a34580bc69fa2d21e804f6edcfbaede to your computer and use it in GitHub Desktop.
Save adityaanurag/5a34580bc69fa2d21e804f6edcfbaede to your computer and use it in GitHub Desktop.
<?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