Skip to content
Snippets Groups Projects
Commit 0a7825c8 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #1972260 by ParisLiakos, marcingy: Convert...

Issue #1972260 by ParisLiakos, marcingy: Convert aggregator_admin_refresh_feed() to a new style controller.
parent b466d937
No related branches found
No related tags found
No related merge requests found
......@@ -8,27 +8,6 @@
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\aggregator\Plugin\Core\Entity\Feed;
/**
* Page callback: Refreshes a feed, then redirects to the overview page.
*
* @param \Drupal\aggregator\Plugin\Core\Entity\Feed $feed
* An object describing the feed to be refreshed.
*
* @see aggregator_menu()
*/
function aggregator_admin_refresh_feed(Feed $feed) {
// @todo CSRF tokens are validated in page callbacks rather than access
// callbacks, because access callbacks are also invoked during menu link
// generation. Add token support to routing: http://drupal.org/node/755584.
$token = drupal_container()->get('request')->query->get('token');
if (!isset($token) || !drupal_valid_token($token, 'aggregator/update/' . $feed->id())) {
throw new AccessDeniedHttpException();
}
aggregator_refresh($feed);
drupal_goto('admin/config/services/aggregator');
}
/**
* Form constructor to add/edit/delete aggregator categories.
*
......
......@@ -119,10 +119,7 @@ function aggregator_menu() {
);
$items['admin/config/services/aggregator/update/%aggregator_feed'] = array(
'title' => 'Update items',
'page callback' => 'aggregator_admin_refresh_feed',
'page arguments' => array(5),
'access arguments' => array('administer news feeds'),
'file' => 'aggregator.admin.inc',
'route_name' => 'aggregator_feed_refresh',
);
$items['admin/config/services/aggregator/list'] = array(
'title' => 'List',
......
......@@ -29,7 +29,14 @@ aggregator_feed_delete:
aggregator_feed_add:
pattern: '/admin/config/services/aggregator/add/feed'
defaults:
_controller: '\Drupal\aggregator\Routing\AggregatorController::feedAdd'
_content: '\Drupal\aggregator\Routing\AggregatorController::feedAdd'
requirements:
_permission: 'administer news feeds'
aggregator_feed_refresh:
pattern: '/admin/config/services/aggregator/update/{aggregator_feed}'
defaults:
_controller: '\Drupal\aggregator\Routing\AggregatorController::feedRefresh'
requirements:
_permission: 'administer news feeds'
......
......@@ -8,9 +8,13 @@
namespace Drupal\aggregator\Routing;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Database\Connection;
use Drupal\Core\Entity\EntityManager;
use Drupal\aggregator\FeedInterface;
/**
* Returns responses for aggregator module routes.
......@@ -70,6 +74,34 @@ public function feedAdd() {
return entity_get_form($feed);
}
/**
* Refreshes a feed, then redirects to the overview page.
*
* @param \Drupal\aggregator\FeedInterface $aggregator_feed
* An object describing the feed to be refreshed.
* @param \Symfony\Component\HttpFoundation\Request $request
* The current request object containing the search string.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A redirection to the admin overview page.
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* If the query token is missing or invalid.
*/
public function feedRefresh(FeedInterface $aggregator_feed, Request $request) {
// @todo CSRF tokens are validated in page callbacks rather than access
// callbacks, because access callbacks are also invoked during menu link
// generation. Add token support to routing: http://drupal.org/node/755584.
$token = $request->query->get('token');
if (!isset($token) || !drupal_valid_token($token, 'aggregator/update/' . $aggregator_feed->id())) {
throw new AccessDeniedHttpException();
}
// @todo after https://drupal.org/node/1972246 find a new place for it.
aggregator_refresh($aggregator_feed);
return new RedirectResponse(url('admin/config/services/aggregator', array('absolute' => TRUE)));
}
/**
* Displays the aggregator administration page.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment