Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291981

Remove nojs from menu callbacks in favour of content negotiation from the request object

$
0
0

Over in #1667742-19: Add abstracted dialog to core (resolves accessibility bug) the patch at #19 demonstrates that you can use the Request object and Content negotiation from the DIC to do away with nojs in your menu callbacks, ie decide whether the user has js based on the content negotiation.
This is a task to remove this logic from views.
Discussed with tim.plunkett on irc.

Example negotiation

<?php
// Check for the content-type.
$container = drupal_container();
$type = FALSE;
if (
$container->has('request') && $container->has('content_negotiation')) {
 
$type = $container->get('content_negotiation')->getContentType($container->get('request'));
}
if (
$type == 'ajax') {
 
// ...
}
?>

I did try to sneak a utility wrapper for this into #1737148: Explicitly declare all JS dependencies, don't use drupal_add_js but it was removed until a case could be made for it being re-usable.
Perhaps this is that case?
<?php
/**
* Utility method to get the normalized type of the current request.
*
* Fetches the ContentNegotiation and Request objects from the current container
* and returns the associated request content type. The normalized type is a
* short, lowercase version of the format, such as 'html', 'json' or 'atom'.
*
* @return string
*   The request type
*/
function drupal_get_request_content_type() {
 
$type = &drupal_static(__FUNCTION__);
  if (isset(
$type)) {
    return
$type;
  }
  else {
   
$container = drupal_container();
    if (
$container->has('request') &&
       
$container->has('content_negotiation')) {
     
$type = $container->get('content_negotiation')->getContentType($container->get('request'));
    }
    else {
     
$type = FALSE;
    }
  }
  return
$type;
}
?>

Viewing all articles
Browse latest Browse all 291981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>