Commit 9b1c15fa authored by alexpott's avatar alexpott

Issue #1972264 by ParisLiakos: Convert aggregator_admin_overview() to a new style controller.

parent 08a58426
...@@ -8,93 +8,6 @@ ...@@ -8,93 +8,6 @@
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\aggregator\Plugin\Core\Entity\Feed; use Drupal\aggregator\Plugin\Core\Entity\Feed;
/**
* Page callback: Displays the aggregator administration page.
*
* @return string
* A HTML-formatted string with administration page content.
*
* @see aggregator_menu()
*/
function aggregator_admin_overview() {
return aggregator_view();
}
/**
* Displays the aggregator administration page.
*
* @return
* The page HTML.
*/
function aggregator_view() {
$result = db_query('SELECT f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block ORDER BY f.title');
$output = '<h3>' . t('Feed overview') . '</h3>';
$header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), t('Operations'));
$rows = array();
foreach ($result as $feed) {
$row = array();
$row[] = l($feed->title, "aggregator/sources/$feed->fid");
$row[] = format_plural($feed->items, '1 item', '@count items');
$row[] = ($feed->checked ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->checked))) : t('never'));
$row[] = ($feed->checked && $feed->refresh ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - REQUEST_TIME))) : t('never'));
$links = array();
$links['edit'] = array(
'title' => t('Edit'),
'href' => "admin/config/services/aggregator/edit/feed/$feed->fid",
);
$links['delete'] = array(
'title' => t('Delete'),
'href' => "admin/config/services/aggregator/delete/feed/$feed->fid",
);
$links['remove'] = array(
'title' => t('Remove items'),
'href' => "admin/config/services/aggregator/remove/$feed->fid",
);
$links['update'] = array(
'title' => t('Update items'),
'href' => "admin/config/services/aggregator/update/$feed->fid",
'query' => array('token' => drupal_get_token("aggregator/update/$feed->fid")),
);
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $links,
),
);
$rows[] = $row;
}
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No feeds available. <a href="@link">Add feed</a>.', array('@link' => url('admin/config/services/aggregator/add/feed')))));
$result = db_query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
$output .= '<h3>' . t('Category overview') . '</h3>';
$header = array(t('Title'), t('Items'), t('Operations'));
$rows = array();
foreach ($result as $category) {
$row = array();
$row[] = l($category->title, "aggregator/categories/$category->cid");
$row[] = format_plural($category->items, '1 item', '@count items');
$links = array();
$links['edit'] = array(
'title' => t('Edit'),
'href' => "admin/config/services/aggregator/edit/category/$category->cid",
);
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $links,
),
);
$rows[] = $row;
}
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'empty' => t('No categories available. <a href="@link">Add category</a>.', array('@link' => url('admin/config/services/aggregator/add/category')))));
return $output;
}
/** /**
* Page callback: Refreshes a feed, then redirects to the overview page. * Page callback: Refreshes a feed, then redirects to the overview page.
* *
......
...@@ -92,10 +92,8 @@ function aggregator_menu() { ...@@ -92,10 +92,8 @@ function aggregator_menu() {
$items['admin/config/services/aggregator'] = array( $items['admin/config/services/aggregator'] = array(
'title' => 'Feed aggregator', 'title' => 'Feed aggregator',
'description' => "Configure which content your site aggregates from other sites, how often it polls them, and how they're categorized.", 'description' => "Configure which content your site aggregates from other sites, how often it polls them, and how they're categorized.",
'page callback' => 'aggregator_admin_overview', 'route_name' => 'aggregator_admin_overview',
'access arguments' => array('administer news feeds'),
'weight' => 10, 'weight' => 10,
'file' => 'aggregator.admin.inc',
); );
$items['admin/config/services/aggregator/add/feed'] = array( $items['admin/config/services/aggregator/add/feed'] = array(
'title' => 'Add feed', 'title' => 'Add feed',
......
aggregator_admin_overview:
pattern: 'admin/config/services/aggregator'
defaults:
_content: '\Drupal\aggregator\Routing\AggregatorController::adminOverview'
requirements:
_permission: 'administer news feeds'
aggregator_admin_settings: aggregator_admin_settings:
pattern: 'admin/config/services/aggregator/settings' pattern: 'admin/config/services/aggregator/settings'
defaults: defaults:
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\ControllerInterface; use Drupal\Core\ControllerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManager; use Drupal\Core\Entity\EntityManager;
/** /**
...@@ -23,21 +24,34 @@ class AggregatorController implements ControllerInterface { ...@@ -23,21 +24,34 @@ class AggregatorController implements ControllerInterface {
*/ */
protected $entityManager; protected $entityManager;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection;
*/
protected $database;
/** /**
* Constructs a \Drupal\aggregator\Routing\AggregatorController object. * Constructs a \Drupal\aggregator\Routing\AggregatorController object.
* *
* @param \Drupal\Core\Entity\EntityManager $entity_manager * @param \Drupal\Core\Entity\EntityManager $entity_manager
* The Entity manager. * The Entity manager.
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/ */
public function __construct(EntityManager $entity_manager) { public function __construct(EntityManager $entity_manager, Connection $database) {
$this->entityManager = $entity_manager; $this->entityManager = $entity_manager;
$this->database = $database;
} }
/** /**
* {inheritdoc} * {inheritdoc}
*/ */
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static($container->get('plugin.manager.entity')); return new static(
$container->get('plugin.manager.entity'),
$container->get('database')
);
} }
/** /**
...@@ -56,4 +70,87 @@ public function feedAdd() { ...@@ -56,4 +70,87 @@ public function feedAdd() {
return entity_get_form($feed); return entity_get_form($feed);
} }
/**
* Displays the aggregator administration page.
*
* @return array
* A render array as expected by drupal_render().
*/
public function adminOverview() {
$result = $this->database->query('SELECT f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block ORDER BY f.title');
$header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), t('Operations'));
$rows = array();
foreach ($result as $feed) {
$row = array();
$row[] = l($feed->title, "aggregator/sources/$feed->fid");
$row[] = format_plural($feed->items, '1 item', '@count items');
$row[] = ($feed->checked ? t('@time ago', array('@time' => format_interval(REQUEST_TIME - $feed->checked))) : t('never'));
$row[] = ($feed->checked && $feed->refresh ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - REQUEST_TIME))) : t('never'));
$links = array();
$links['edit'] = array(
'title' => t('Edit'),
'href' => "admin/config/services/aggregator/edit/feed/$feed->fid",
);
$links['delete'] = array(
'title' => t('Delete'),
'href' => "admin/config/services/aggregator/delete/feed/$feed->fid",
);
$links['remove'] = array(
'title' => t('Remove items'),
'href' => "admin/config/services/aggregator/remove/$feed->fid",
);
$links['update'] = array(
'title' => t('Update items'),
'href' => "admin/config/services/aggregator/update/$feed->fid",
'query' => array('token' => drupal_get_token("aggregator/update/$feed->fid")),
);
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $links,
),
);
$rows[] = $row;
}
$build['feeds'] = array(
'#prefix' => '<h3>' . t('Feed overview') . '</h3>',
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No feeds available. <a href="@link">Add feed</a>.', array('@link' => url('admin/config/services/aggregator/add/feed'))),
);
$result = $this->database->query('SELECT c.cid, c.title, COUNT(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
$header = array(t('Title'), t('Items'), t('Operations'));
$rows = array();
foreach ($result as $category) {
$row = array();
$row[] = l($category->title, "aggregator/categories/$category->cid");
$row[] = format_plural($category->items, '1 item', '@count items');
$links = array();
$links['edit'] = array(
'title' => t('Edit'),
'href' => "admin/config/services/aggregator/edit/category/$category->cid",
);
$row[] = array(
'data' => array(
'#type' => 'operations',
'#links' => $links,
),
);
$rows[] = $row;
}
$build['categories'] = array(
'#prefix' => '<h3>' . t('Category overview') . '</h3>',
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
'#empty' => t('No categories available. <a href="@link">Add category</a>.', array('@link' => url('admin/config/services/aggregator/add/category'))),
);
return $build;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment