View source
<?php
namespace Drupal\tweet_feed\Controller;
use Drupal\Core\Link;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class TwitterFeedsController extends ControllerBase {
public function display_feeds() {
$config = $this
->config('tweet_feed.twitter_feeds');
$header = [
[
'data' => 'Feed Name',
],
[
'data' => 'Type',
],
[
'data' => 'Feed Criteria',
],
[
'data' => '# Per Pull',
],
[
'data' => 'Edit',
],
[
'data' => 'Delete',
],
];
$rows = [];
$types = [
'',
'Search',
'Timeline',
'List',
];
$feeds = $config
->get('feeds');
foreach ($feeds as $key => $feed) {
$edit_link = Link::createFromRoute($this
->t('Edit'), 'tweet_feed.edit_feed', [
'feed_machine_name' => $key,
]);
$delete_link = Link::createFromRoute($this
->t('Delete'), 'tweet_feed.delete_feed', [
'feed_machine_name' => $key,
]);
$row = [
[
'data' => $feed['feed_name'],
],
[
'data' => $key,
],
[
'data' => $types[$feed['query_type']],
],
[
'data' => $feed['pull_count'],
],
[
'data' => $edit_link,
],
[
'data' => $delete_link,
],
];
$rows[] = $row;
}
return [
'#type' => 'table',
'#attributes' => [
'class' => [
'table table-striped',
],
],
'#prefix' => NULL,
'#header' => $header,
'#rows' => $rows,
'#empty' => 'THERE ARE NO TWITTER FEEDS CURRENTLY CREATED.',
];
}
}