HackedDiffController.php in Hacked! 8.2
File
src/Controller/HackedDiffController.php
View source
<?php
namespace Drupal\hacked\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\diff\DiffEntityComparison;
use Drupal\hacked\hackedFileHasher;
use Drupal\hacked\hackedProject;
use Symfony\Component\DependencyInjection\ContainerInterface;
class HackedDiffController extends ControllerBase {
protected $config;
protected $entityComparison;
public function __construct(DiffEntityComparison $entity_comparison) {
$this->config = $this
->config('diff.settings');
$this->entityComparison = $entity_comparison;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('diff.entity_comparison'));
}
public function hackedProjectDiff(hackedProject $project) {
if (!\Drupal::moduleHandler()
->moduleExists('diff')) {
return [
'#markup' => $this
->t('The diff module is required to use this feature.'),
];
}
$file = \Drupal::request()
->get('file');
$project
->identify_project();
if ($project
->file_is_diffable($file)) {
$original_file = $project
->file_get_location('remote', $file);
$installed_file = $project
->file_get_location('local', $file);
$hasher = hacked_get_file_hasher();
$build = [
'#theme' => 'table',
'#header' => [
t('Original'),
'',
t('Current'),
'',
],
'#rows' => $this->entityComparison
->getRows($hasher
->fetch_lines($original_file), $hasher
->fetch_lines($installed_file), TRUE),
];
$build['#attached']['library'][] = 'diff/diff.general';
$theme = $this->config
->get('general_settings.theme');
if ($theme) {
if ($theme == 'default') {
$build['#attached']['library'][] = 'diff/diff.default';
}
elseif ($theme == 'github') {
$build['#attached']['library'][] = 'diff/diff.github';
}
}
elseif ($theme == NULL) {
$build['#attached']['library'][] = 'diff/diff.github';
}
return $build;
}
return [
'#markup' => $this
->t('Cannot hash binary file or file not found: %file', array(
'%file' => $file,
)),
];
}
public function hackedProjectDiffTitle(hackedProject $project) {
$file = \Drupal::request()
->get('file');
return $this
->t('Hacked status for @file in project @project', [
'@project' => $project
->title(),
'@file' => $file,
]);
}
}