-
Notifications
You must be signed in to change notification settings - Fork 0
/
views_feed_xml.drush.inc
44 lines (37 loc) · 1.04 KB
/
views_feed_xml.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* @file
* © 2016 Valiton GmbH.
*/
use Drupal\views_feed_xml\Util\XmlHelper;
use Drupal\node\Entity\Node;
/**
* Implements hook_drush_command().
*/
function views_feed_xml_drush_command() {
$items = [];
$items['views-feed-xml-test-feed'] = [
'callback' => 'views_feed_xml_test_feed',
'description' => dt('Test command. Selects a number of articles und displays the XML exported string.'),
'options' => [],
'examples' => [],
];
return $items;
}
/**
* Provide views-feed-xml-test-feed drush command.
*/
function views_feed_xml_run_test_feed() {
$q = \Drupal::entityQuery('node')
->condition('type', 'article')
->sort('created', 'DESC')
->range(0, 50);
$nodes = Node::loadMultiple($q->execute());
/** @var \Symfony\Component\Serializer\Serializer $serializer */
$serializer = \Drupal::service('views_feed_xml.serializer');
$xml = $serializer->serialize($nodes, 'xml');
$xml = XmlHelper::stripInvalidControlChars($xml);
$doc = new DOMDocument();
$doc->loadXML($xml);
print $doc->saveXML();
}