Commit 1187a681 authored by catch's avatar catch

Issue #788900 by ParisLiakos, dawehner, effulgentsia, xjm, et al: Deprecate...

Issue #788900 by ParisLiakos, dawehner, effulgentsia, xjm, et al: Deprecate and remove usages of arg().
parent 09702f84
......@@ -1943,6 +1943,8 @@ function _current_path($path = NULL) {
* The component specified by $index, or NULL if the specified component was
* not found. If called without arguments, it returns an array containing all
* the components of the current path.
*
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
*/
function arg($index = NULL, $path = NULL) {
// Even though $arguments doesn't need to be resettable for any functional
......
......@@ -1984,8 +1984,9 @@ function template_preprocess_html(&$variables) {
$body_classes[] = $variables['logged_in'] ? 'logged-in' : 'not-logged-in';
$variables['attributes']['class'] = $body_classes;
$path_args = explode('/', current_path());
// Populate the body classes.
if ($suggestions = theme_get_suggestions(arg(), 'page', '-')) {
if ($suggestions = theme_get_suggestions($path_args, 'page', '-')) {
foreach ($suggestions as $suggestion) {
if ($suggestion != 'page-front') {
// Add current suggestion to page classes to make it possible to theme
......@@ -2067,9 +2068,6 @@ function template_preprocess_html(&$variables) {
* inside "modules/system/page.html.twig". Look in there for the full list of
* variables.
*
* Uses the arg() function to generate a series of page template suggestions
* based on the current path.
*
* @see drupal_render_page()
*/
function template_preprocess_page(&$variables) {
......@@ -2186,7 +2184,7 @@ function template_preprocess_page(&$variables) {
* additional suggestions or classes on the path of the current page.
*
* @param $args
* An array of path arguments, such as from function arg().
* An array of path arguments.
* @param $base
* A string identifying the base 'thing' from which more specific suggestions
* are derived. For example, 'page' or 'html'.
......
......@@ -66,12 +66,7 @@ public function save(array $form, array &$form_state) {
$feed->save();
if ($insert) {
drupal_set_message($this->t('The feed %feed has been updated.', array('%feed' => $feed->label())));
if (arg(0) == 'admin') {
$form_state['redirect_route']['route_name'] = 'aggregator.admin_overview';
}
else {
$form_state['redirect_route'] = $feed->urlInfo('canonical');
}
$form_state['redirect_route'] = $feed->urlInfo('canonical');
}
else {
watchdog('aggregator', 'Feed %feed added.', array('%feed' => $feed->label()), WATCHDOG_NOTICE, l($this->t('View'), 'admin/config/services/aggregator'));
......
......@@ -43,12 +43,7 @@ public function submit(array $form, array &$form_state) {
$this->entity->delete();
watchdog('aggregator', 'Feed %feed deleted.', array('%feed' => $this->entity->label()));
drupal_set_message($this->t('The feed %feed has been deleted.', array('%feed' => $this->entity->label())));
if (arg(0) == 'admin') {
$form_state['redirect_route'] = $this->getCancelRoute();
}
else {
$form_state['redirect_route'] = new Url('aggregator.sources');
}
$form_state['redirect_route'] = new Url('aggregator.sources');
}
}
drupal.dblog:
version: VERSION
css:
component:
css/dblog.module.css: {}
......@@ -52,15 +52,6 @@ function dblog_menu_link_defaults_alter(&$links) {
return $links;
}
/**
* Implements hook_page_build().
*/
function dblog_page_build(&$page) {
if (arg(0) == 'admin' && arg(1) == 'reports') {
$page['#attached']['css'][] = drupal_get_path('module', 'dblog') . '/css/dblog.module.css';
}
}
/**
* Implements hook_cron().
*
......
......@@ -210,6 +210,9 @@ public function overview() {
'#rows' => $rows,
'#attributes' => array('id' => 'admin-dblog', 'class' => array('admin-dblog')),
'#empty' => $this->t('No log messages available.'),
'#attached' => array(
'library' => array('dblog/drupal.dblog'),
),
);
$build['dblog_pager'] = array('#theme' => 'pager');
......@@ -283,6 +286,9 @@ public function eventDetails($event_id) {
'#type' => 'table',
'#rows' => $rows,
'#attributes' => array('class' => array('dblog-event')),
'#attached' => array(
'library' => array('dblog/drupal.dblog'),
),
);
}
......@@ -383,6 +389,9 @@ public function topLogMessages($type) {
'#header' => $header,
'#rows' => $rows,
'#empty' => $this->t('No log messages available.'),
'#attached' => array(
'library' => array('dblog/drupal.dblog'),
),
);
$build['dblog_top_pager'] = array('#theme' => 'pager');
......
......@@ -651,14 +651,16 @@ function system_element_info() {
* Implements hook_theme_suggestions_HOOK().
*/
function system_theme_suggestions_html(array $variables) {
return theme_get_suggestions(arg(), 'html');
$path_args = explode('/', current_path());
return theme_get_suggestions($path_args, 'html');
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function system_theme_suggestions_page(array $variables) {
return theme_get_suggestions(arg(), 'page');
$path_args = explode('/', current_path());
return theme_get_suggestions($path_args, 'page');
}
/**
......
......@@ -7,6 +7,7 @@
namespace Drupal\taxonomy\Plugin\views\argument_default;
use Drupal\taxonomy\TermInterface;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
......@@ -123,8 +124,8 @@ public function submitOptionsForm(&$form, &$form_state, &$options = array()) {
public function getArgument() {
// Load default argument from taxonomy page.
if (!empty($this->options['term_page'])) {
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) {
return arg(2);
if (($taxonomy_term = $this->request->attributes->get('taxonomy_term')) && $taxonomy_term instanceof TermInterface) {
return $taxonomy_term->id();
}
}
// Load default argument from node.
......
......@@ -29,7 +29,7 @@ public static function getInfo() {
function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules'));
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer themes'));
$this->drupalLogin($admin_user);
}
......
......@@ -12,6 +12,7 @@
*/
use Drupal\Core\Site\Settings;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
// These are internally used constants for this code, do not modify.
......@@ -97,8 +98,11 @@ function update_help($route_name, Request $request) {
* Implements hook_page_build().
*/
function update_page_build() {
if (arg(0) == 'admin' && user_access('administer site configuration')) {
switch (current_path()) {
/** @var \Drupal\Core\Routing\AdminContext $admin_context */
$admin_context = \Drupal::service('router.admin_context');
if ($admin_context->isAdminRoute(\Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_OBJECT)) && \Drupal::currentUser()->hasPermission('administer site configuration')) {
$current_path = current_path();
switch ($current_path) {
// These pages don't need additional nagging.
case 'admin/appearance/update':
case 'admin/appearance/install':
......
......@@ -9,6 +9,7 @@
use Drupal\Core\Session\AccountInterface;
use Drupal\block\BlockBase;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/**
* Provides a 'User login' block.
......@@ -25,7 +26,8 @@ class UserLoginBlock extends BlockBase {
* {@inheritdoc}
*/
public function access(AccountInterface $account) {
return (!$account->id() && !(arg(0) == 'user' && !is_numeric(arg(1))));
$route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
return ($account->isAnonymous() && !in_array($route_name, array('user.register', 'user.login', 'user.logout')));
}
/**
......
......@@ -70,12 +70,13 @@ protected function defineOptions() {
public function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
// Using range(1, 10) will create an array keyed 0-9, which allows arg() to
// properly function since it is also zero-based.
$form['index'] = array(
'#type' => 'select',
'#title' => t('Path component'),
'#default_value' => $this->options['index'],
// range(1, 10) returns an array with:
// - keys that count from 0 to match PHP array keys from explode().
// - values that count from 1 for display to humans.
'#options' => range(1, 10),
'#description' => t('The numbering starts from 1, e.g. on the page admin/structure/types, the 3rd path component is "types".'),
);
......
......@@ -16,6 +16,7 @@
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\PluginBase;
use Drupal\views\Views;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\DependencyInjection\Exception\RuntimeException as DependencyInjectionRuntimeException;
/**
......@@ -2398,8 +2399,9 @@ public function getSpecialBlocks() {
* The rendered exposed form as string or NULL otherwise.
*/
public function viewExposedFormBlocks() {
// avoid interfering with the admin forms.
if (arg(0) == 'admin' && arg(1) == 'structure' && arg(2) == 'views') {
// Avoid interfering with the admin forms.
$route_name = \Drupal::request()->attributes->get(RouteObjectInterface::ROUTE_NAME);
if (strpos($route_name, 'views_ui.') === 0) {
return;
}
$this->view->initHandlers();
......
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