You are here

function template_preprocess_hacked_detailed_report in Hacked! 8.2

Theme project status report.

File

./hacked.details.inc, line 11

Code

function template_preprocess_hacked_detailed_report(&$variables) {
  $project = $variables['project'];
  $variables['files'] = [
    '#type' => 'table',
    '#attributes' => [
      'class' => [
        'update',
      ],
    ],
    // Attach the library to a variable that gets printed always.
    '#attached' => [
      'library' => [
        'update/drupal.update.admin',
      ],
    ],
  ];
  foreach ($project['files'] as $file => $status) {
    if (!isset($status)) {
      continue;
    }
    $url = NULL;
    if (\Drupal::currentUser()
      ->hasPermission('view diffs of changed files') && \Drupal::moduleHandler()
      ->moduleExists('diff') && $status != HACKED_STATUS_UNHACKED && !empty($project['diffable'][$file])) {
      $url = Url::fromRoute('hacked.project_diff', [
        'project' => $project['project_name'],
        'file' => $file,
      ]);
    }
    $file_status = [
      '#theme' => 'hacked_file_status',
      '#file' => [
        'name' => $file,
        'status' => $status,
        'url' => $url,
      ],
    ];

    // Add the project status row and details.
    $variables['files'][$file]['status'] = $file_status;
    switch ($status) {
      case HACKED_STATUS_UNHACKED:
        $variables['files'][$file]['#attributes'] = [
          'class' => [
            'color-success',
          ],
        ];
        break;
      case HACKED_STATUS_DELETED:
        $variables['files'][$file]['#attributes'] = [
          'class' => [
            'color-error',
          ],
        ];
        break;
      case HACKED_STATUS_HACKED:
      case HACKED_STATUS_PERMISSION_DENIED:
      case HACKED_STATUS_UNCHECKED:
      default:
        $variables['files'][$file]['#attributes'] = [
          'class' => [
            'color-warning',
          ],
        ];
        break;
    }
  }
}