3 namespace Drupal\hacked\Controller;
5 use Drupal\Core\Controller\ControllerBase;
6 use Drupal\diff\DiffEntityComparison;
7 use Drupal\hacked\hackedFileHasher;
8 use Drupal\hacked\hackedProject;
9 use Symfony\Component\DependencyInjection\ContainerInterface;
12 * Controller routines for hacked routes.
14 class HackedDiffController extends ControllerBase {
17 * Wrapper object for writing/reading configuration from diff.plugins.yml
22 * The diff entity comparison service.
24 protected $entityComparison;
27 * Constructs a HackedDiffController object.
29 * @param DiffEntityComparison $entity_comparison
30 * DiffEntityComparison service.
32 public function __construct(DiffEntityComparison $entity_comparison) {
33 $this->config = $this->config('diff.settings');
34 $this->entityComparison = $entity_comparison;
40 public static function create(ContainerInterface $container) {
42 $container->get('diff.entity_comparison')
47 * Shows a diff report for a specific file in a project.
50 * The hackedProject instance.
52 * @param \Drupal\hacked\hackedProject $project
55 public function hackedProjectDiff(hackedProject $project) {
56 if (!\Drupal::moduleHandler()->moduleExists('diff')) {
58 '#markup' => $this->t('The diff module is required to use this feature.')
62 $file = \Drupal::request()->get('file');
63 $project->identify_project();
65 // Find a better way to do this:
66 // $breadcrumb = array(
67 // l('Home', '<front>'),
68 // l('Administer', 'admin'),
69 // l('Reports', 'admin/reports'),
70 // l('Hacked', 'admin/reports/hacked'),
71 // l($project->title(), 'admin/reports/hacked/' . $project->name),
73 // drupal_set_breadcrumb($breadcrumb);
75 if ($project->file_is_diffable($file)) {
76 $original_file = $project->file_get_location('remote', $file);
77 $installed_file = $project->file_get_location('local', $file);
79 /** @var hackedFileHasher $hasher */
80 $hasher = hacked_get_file_hasher();
84 '#header' => [t('Original'), '', t('Current'), ''],
85 '#rows' => $this->entityComparison->getRows($hasher->fetch_lines($original_file), $hasher->fetch_lines($installed_file), TRUE),
88 // Add the CSS for the diff.
89 $build['#attached']['library'][] = 'diff/diff.general';
90 $theme = $this->config->get('general_settings.theme');
92 if ($theme == 'default') {
93 $build['#attached']['library'][] = 'diff/diff.default';
95 elseif ($theme == 'github') {
96 $build['#attached']['library'][] = 'diff/diff.github';
99 // If the setting could not be loaded or is missing use the default theme.
100 elseif ($theme == NULL) {
101 $build['#attached']['library'][] = 'diff/diff.github';
106 '#markup' => $this->t('Cannot hash binary file or file not found: %file', array('%file' => $file))
111 * Menu title callback for the hacked site report page.
113 public function hackedProjectDiffTitle(hackedProject $project) {
114 $file = \Drupal::request()->get('file');
115 return $this->t('Hacked status for @file in project @project', [
116 '@project' => $project->title(),