Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JeroenT’s picture

Status: Active » Needs review
FileSize
0 bytes

Replaced drupal_add_html_head_link with #attached.

Patch attached.

Berdir’s picture

Status: Needs review » Needs work

Patch is empty.

JeroenT’s picture

Status: Needs work » Needs review
FileSize
6.43 KB

I'm sorry. This is the right one.

Status: Needs review » Needs work
Issue tags: -D8 cacheability

The last submitted patch, drupal8.base-system.2115061-3.patch, failed testing.

JeroenT’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
6.4 KB

Guess who's back with a brand new patch!

tim.plunkett’s picture

Status: Needs review » Needs work
  1. +++ b/core/includes/theme.inc
    @@ -2564,7 +2564,14 @@ function template_preprocess_html(&$variables) {
    +        'type' => $type
    
    @@ -2847,7 +2854,14 @@ function template_preprocess_maintenance_page(&$variables) {
    +        'type' => $type
    
    +++ b/core/modules/book/book.module
    @@ -698,21 +698,39 @@ function template_preprocess_book_navigation(&$variables) {
    +          'href' => $prev_href
    ...
    +          'href' => $parent_href
    ...
    +          'href' => $next_href
    +        )
    
    +++ b/core/modules/taxonomy/taxonomy.pages.inc
    @@ -24,11 +24,25 @@ function taxonomy_term_page(Term $term) {
    +            $uri['path'], $uri['options']
    +        )
    ...
    +                  $uri['options'], array('alias' => TRUE)
    +              )
    +          )
    
    +++ b/core/modules/views/lib/Drupal/views/Plugin/views/style/Rss.php
    @@ -58,12 +58,15 @@ public function attachTo($display_id, $path, $title) {
    +          'href' => $url
    +        )
    

    Missing trailing comma

  2. +++ b/core/includes/theme.inc
    @@ -2847,7 +2854,14 @@ function template_preprocess_maintenance_page(&$variables) {
    +    $build['#attached']['drupal_add_html_head_link'][] = array(
    +      array(
    ...
    +      ),
    +    );
    
    +++ b/core/modules/book/book.module
    @@ -698,21 +698,39 @@ function template_preprocess_book_navigation(&$variables) {
    +      $build['#attached']['drupal_add_html_head_link'][] = array(
    +        array(
    ...
    +        ),
    +      );
    

    Here and throughout, these could be condensed onto one line and the innards could be outdented

  3. +++ b/core/modules/taxonomy/taxonomy.pages.inc
    @@ -24,11 +24,25 @@ function taxonomy_term_page(Term $term) {
    +      $build['#attached']['drupal_add_html_head_link'][] = array(
    +        array(
    +          'rel' => 'shortlink',
    +          'href' => url(
    +              $uri['path'], array_merge(
    

    This is indented incorrectly.

JeroenT’s picture

Assigned: Unassigned » JeroenT
JeroenT’s picture

Made some coding standards changes as suggested by tim.plunkett.

JeroenT’s picture

Status: Needs work » Needs review

Marking as needs review.

tim.plunkett’s picture

That's not exactly what I had in mind for indentation.

Also are we 100% sure we need each of those drupal_render calls? It seems like some of them are in the context of a render array already. And there are more than one drupal_render call in the same function...

JeroenT’s picture

I deleted some of the unnecessary drupal_render calls.

I think we can also remove this drupal_render in /core/includes/common.inc by replacing the theme function with a renderable array.

$stored_feed_links[$url] = theme('feed_icon', array('url' => $url, 'title' => $title));

    $build['#attached']['drupal_add_html_head_link'][][] = array(
      'rel' => 'alternate',
      'type' => 'application/rss+xml',
      'title' => $title,
      // Force the URL to be absolute, for consistency with other <link> tags
      // output by Drupal.
      'href' => url($url, array('absolute' => TRUE)),
    );
    drupal_render($build);

In /core/includes/theme.inc there is already a drupal_render call to add the default_css files, Maybe we can use this one also to add the html_link_head?

  $default_css = array(
    '#attached' => array(
      'css' => array(
        $path . '/css/system.module.css',
        $path . '/css/system.theme.css',
        $path . '/css/system.admin.css',
        $path . '/css/system.maintenance.css',
      ),
    ),
  );
  drupal_render($default_css);
tim.plunkett’s picture

Looks much better.

+++ b/core/modules/book/book.module
@@ -724,12 +724,15 @@
+  if(!empty($build)) {

Missing space between if(

JeroenT’s picture

Fixed missing space between if.

Patch attached.

Status: Needs review » Needs work

The last submitted patch, 10: drupal_add_html_head_link-2115061-10.patch, failed testing.

JeroenT’s picture

Assigned: JeroenT » Unassigned
Status: Needs work » Needs review
sdboyer’s picture

Title: Remove drupal_add_html_head_link() » Remove direct calls to drupal_add_html_head_link()
Status: Needs review » Reviewed & tested by the community

discussed a bit with @tim.plunkett in irc - this is a fine incremental step, but the title was wrong. the patch does not actually remove drupal_add_html_head_link(). it only removes direct calls to it. moving things into the render arrays is (probably) a step forward, because it provides us an indirection layer through which we could implement alternate, non-global-static storage. but for now, this simply defers the calls to the global function to drupal_render() time.

but RTBC, because that indirection layer is a win.

we really oughtta start marking up those globals as deprecated, or something like that. not that that ACTUALLY makes things better.

catch’s picture

Title: Remove direct calls to drupal_add_html_head_link() » Change notice: Remove direct calls to drupal_add_html_head_link()
Priority: Critical » Major
Status: Reviewed & tested by the community » Active

Yep where we still have direct calls to drupal_render(), which this patch has plenty of, then we don't gain a massive amount. However we could make changes in drupal_render() to make these non global, similar to the 'drupal_render_for_real()' stuff discussed in Prague.

Committed/pushed to 8.x. We'll need a change notice to tell people not to use this function directly any more.

xjm’s picture

Issue tags: +Needs change record
effulgentsia’s picture

Issue tags: +D8 cacheability

Retroactively tagging for posterity.

LewisNyman’s picture

Assigned: Unassigned » LewisNyman
LewisNyman’s picture

Assigned: LewisNyman » Unassigned
Status: Active » Needs review

My change notice proposal:

drupal_add_html_head_link() deprecated in favour of #attached['drupal_add_html_head_link']

Instead of calling drupal_add_html_head_link() directly, attach the link to a render array.

Before

drupal_add_html_head_link(array('rel' => 'shortlink', 'href' => url($uri['path'], array_merge($uri['options'], array('alias' => TRUE)))), TRUE);

After

$build['#attached']['drupal_add_html_head_link'][] = array(
  array(
    'rel' => $rel,
    'href' => url($uri['path'], $uri['options']),
  ),
  TRUE,
);
star-szr’s picture

Looks good, the only thing is the examples don't seem to map 1:1. Can we ditch the $rel in the after example and just use 'shortlink', and either simplify the before example OR do the merging of options and adding in 'alias' => TRUE in the after example?

LewisNyman++ :)

LewisNyman’s picture

Oh yeah, so like this? https://drupal.org/node/2160069

codium’s picture

Using array key 'drupal_add_html_head_link' instead of function call which could be hinted in a IDE is a bad move IMHO... What's the motivation? Maybe shorter key name?

star-szr’s picture

Title: Change notice: Remove direct calls to drupal_add_html_head_link() » Remove direct calls to drupal_add_html_head_link()
Priority: Major » Critical
Status: Needs review » Fixed
Issue tags: -Needs change record

@LewisNyman - yep, that works for me!

@drupality - I think #16 and #17 provide some good background as to why this change was made. The longer term goal if this change is to improve cacheability.

Reverting title, tags, and priority (and marking as fixed) now that the change notice has been written. Thanks @LewisNyman!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.