Split from #1898466: update.module - Convert theme_ functions to Twig because it was getting too big and not getting any reviews.

This can get consolidated later.

@ Steps to Test
Visit /admin/reports/updates
Compare the updated check time with the link.

Files: 
CommentFileSizeAuthor
#24 2264753-24.patch2.83 KBcfox612
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,298 pass(es). View
#21 2264753-21.patch1.95 KBcfox612
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,201 pass(es), 94 fail(s), and 5 exception(s). View
#16 2264753-16.patch2.82 KBcfox612
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 2264753-16.patch. Unable to apply patch. See the log in the details link for more information. View
#12 2264753-12.patch2.82 KBcfox612
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 2264753-12.patch. Unable to apply patch. See the log in the details link for more information. View
#10 interdiff.txt1.13 KBCottser
#10 2264753-10.patch2.81 KBCottser
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,062 pass(es). View

Comments

joelpittet’s picture

Title: Convert theme_update_last_check and theme_update_report into update-report.html.twig » Convert theme_update_last_check to update-last-check.html.twig
Assigned: joelpittet » Unassigned
Issue summary: View changes
Status: Active » Needs review
Issue tags: +Novice, +Twig
Parent issue: » #1757550: [Meta] Convert core theme functions to Twig templates
Related issues: +#1898466: update.module - Convert theme_ functions to Twig
FileSize
2.66 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 70,624 pass(es). View
leslieg’s picture

Assigned: Unassigned » leslieg
joelpittet’s picture

Assigned: leslieg » Unassigned

@leslieg I'm unassingning you from this issue. You are welcome to assign it to you again if you can still help out but just setting it up for DrupalCon code sprints.

steinmb’s picture

Assigned: Unassigned » steinmb

Stealing

t_en’s picture

Assigned: steinmb » t_en
t_en’s picture

Checked the html markup output before and after applying the patch https://drupal.org/node/2264753#comment-8770653. There are minor differences in whitespace and in the change of some slashes "/" into "%2F" in the destination url. Works ok in Firefox.

Before:

          <div class="update checked">Last checked: 3 min 1 sec ago <span class="check-manually">(<a href="/admin/reports/updates/check?destination=admin/reports/updates">Check manually</a>)</span></div>

After applying the patch:

<div class="update checked">
      Last checked: 22 min 3 sec ago
    <span class="check-manually">(<a href="/admin/reports/updates/check?destination=admin%2Freports%2Fupdates">Check manually</a>)</span>
</div>
markcarver’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/update/templates/update-last-check.html.twig
    @@ -0,0 +1,25 @@
    +  {% if last_checked %}
    +    {% trans %}
    +      Last checked: {{ time }} ago
    +    {% endtrans %}
    +  {% else %}
    +    {{ 'Last checked: never'|t }}
    +  {% endif %}
    

    Ultimately, I would love for the following to work. Unfortunately (and because of my extensive knowledge of the extension), I do not believe that the {% trans %} tag would actually allow shorthand if statements inside it:

    {% trans %}
      Last checked: {{ last_checked ? time + ' ago' : 'never' }}
    {% endtrans %}
    

    That being said, I still think it should at least switch this around so that the if statement was inside the {% trans %} tag and you're not using both the tag and the |t filter:

    {% trans %}
      {% if last_checked %}
        Last checked: {{ time }} ago
      {% else %}
        Last checked: never
      {% endif %}
    {% endtrans %}
    
  2. +++ b/core/modules/update/update.module
    @@ -565,13 +568,11 @@ function _update_project_status_sort($a, $b) {
       $last = $variables['last'];
    ...
    +  $variables['last_checked'] = ($last != NULL);
    

    Why are we adding a variable? If there is a value, it's a timestamp (> 0). Otherwise, it would be "empty" (NULL, FALSE, "", 0, etc). The following would work just fine in the Twig template. No need to create a whole new variable:

    {% if last %}
    
  3. +++ b/core/modules/update/update.module
    @@ -565,13 +568,11 @@ function _update_project_status_sort($a, $b) {
    -  $output .= ' <span class="check-manually">(' . l(t('Check manually'), 'admin/reports/updates/check', array('query' => drupal_get_destination())) . ')</span>';
    ...
    +  $variables['link'] = \Drupal::l(t('Check manually'), 'update.manual_status', array(), array('query' => drupal_get_destination()));
    

    The reason (I am guessing) that the query is being encoded, / => %2F is because we're also switching from using l() to Drupal::l. I am tempted to say that this is scope creep. It is also a little beyond my ability to debug why it is doing that and should perhaps be opened in a separate issue for someone more capable to fix and provide tests.

a-fro’s picture

Status: Needs work » Needs review
FileSize
2.69 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 71,790 pass(es). View
2.22 KB

I removed last_checked per @markcarver's suggestion. However, you can't put if statements within the trans function, so I simply made it more uniform with a duplicate t function. The 3rd issue was discussed between mark and @joelpittet and no changes required.

markcarver’s picture

Assigned: t_en » Unassigned
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

This is good to go.

Cottser’s picture

FileSize
2.81 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,062 pass(es). View
1.13 KB

Minor docs updates here to keep this at RTBC from my perspective.

  1. +++ b/core/modules/update/templates/update-last-check.html.twig
    @@ -0,0 +1,23 @@
    + * Default theme implementation for the last of update data templates.
    
    +++ b/core/modules/update/update.module
    @@ -555,7 +556,9 @@ function _update_project_status_sort($a, $b) {
    + * Prepares variables for last time update data was checked templates.
    

    I think the second way of wording this is much more readable so I made the template wording consistent with the preprocess.

  2. +++ b/core/modules/update/update.module
    @@ -569,13 +572,9 @@ function _update_project_status_sort($a, $b) {
      * @see theme_update_available_updates_form()
    

    Removing this line because this doesn't seem to exist as a theme function or template so not sure it will help anyone.

  3. +++ b/core/modules/update/update.module
    @@ -569,13 +572,9 @@ function _update_project_status_sort($a, $b) {
      * @ingroup themeable
    

    @ingroup themeable needs to go away.

All changes rolled in here.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/update/update.module
@@ -566,16 +569,10 @@ function _update_project_status_sort($a, $b) {
+  $variables['time'] = format_interval(REQUEST_TIME - $variables['last']);

format_interval() is deprecated. Can be replaced with \Drupal::service('date')->formatInterval(). As we're replacing l() with Drupal::l() this seems only right.

cfox612’s picture

FileSize
2.82 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 2264753-12.patch. Unable to apply patch. See the log in the details link for more information. View

Rerolled with updates from comment #11.

cfox612’s picture

Status: Needs work » Needs review

Updating status

Status: Needs review » Needs work

The last submitted patch, 12: 2264753-12.patch, failed testing.

cfox612’s picture

Updating

cfox612’s picture

Status: Needs work » Needs review
FileSize
2.82 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 2264753-16.patch. Unable to apply patch. See the log in the details link for more information. View

Let's try this again... :)

Status: Needs review » Needs work

The last submitted patch, 16: 2264753-16.patch, failed testing.

cfox612’s picture

Okay someone please tell me what I'm missing :)

Cottser’s picture

Thanks @cfox612! It looks like the patch file has been edited directly, that's why it's not applying.

The steps in https://drupal.org/node/707484 (or https://drupal.org/node/1319154) might be helpful along with the instructions at interdiff for creating an interdiff. If you get stuck you can also come to core mentoring which starts in about 40 minutes in #drupal and runs for 2 hours :) or ping me in #drupal-twig anytime.

cfox612’s picture

Ah okay, wasn't sure if I could just make the change there (obviously not)! Thanks I'll update!

cfox612’s picture

Status: Needs work » Needs review
FileSize
1.95 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,201 pass(es), 94 fail(s), and 5 exception(s). View

Okay third time's the charm!

Status: Needs review » Needs work

The last submitted patch, 21: 2264753-21.patch, failed testing.

Cottser’s picture

That's looking much better! The only thing is that we are missing update-last-check.html.twig from the patch, to avoid that git apply --index is your friend!

Fourth time's the charm? :D

cfox612’s picture

Status: Needs work » Needs review
FileSize
2.83 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,298 pass(es). View

Fingers crossed!

Status: Needs review » Needs work

The last submitted patch, 24: 2264753-24.patch, failed testing.

Cottser’s picture

Status: Needs work » Needs review

24: 2264753-24.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 24: 2264753-24.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

24: 2264753-24.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 24: 2264753-24.patch, failed testing.

Cottser’s picture

Status: Needs work » Reviewed & tested by the community

We had a misbehaving testbot but I think it's time to go back to RTBC-land. Thanks for your patience and persistence @cfox612 :)

cfox612’s picture

Let me know if I did miss something! Still learning :)

Cottser - Thanks so much for all your help!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 432b5a7 and pushed to 8.x. Thanks!

  • Commit 432b5a7 on 8.x by alexpott:
    Issue #2264753 by cfox612, Cottser, a-fro, joelpittet: Convert...

Status: Fixed » Closed (fixed)

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