5 * Contains \Drupal\hacked\Controller\HackedDiffController.
8 namespace Drupal\hacked\Controller;
10 use Drupal\Core\Controller\ControllerBase;
11 use Drupal\diff\DiffEntityComparison;
12 use Drupal\hacked\hackedFileHasher;
13 use Drupal\hacked\hackedProject;
14 use Symfony\Component\DependencyInjection\ContainerInterface;
17 * Controller routines for hacked routes.
19 class HackedDiffController extends ControllerBase {
22 * Wrapper object for writing/reading configuration from diff.plugins.yml
27 * The diff entity comparison service.
29 protected $entityComparison;
32 * Constructs a HackedDiffController object.
34 * @param DiffEntityComparison $entity_comparison
35 * DiffEntityComparison service.
37 public function __construct(DiffEntityComparison $entity_comparison) {
38 $this->config = $this->config('diff.settings');
39 $this->entityComparison = $entity_comparison;
45 public static function create(ContainerInterface $container) {
47 $container->get('diff.entity_comparison')
52 * Shows a diff report for a specific file in a project.
55 * The hackedProject instance.
57 * @param \Drupal\hacked\hackedProject $project
60 public function hackedProjectDiff(hackedProject $project) {
61 if (!\Drupal::moduleHandler()->moduleExists('diff')) {
63 '#markup' => $this->t('The diff module is required to use this feature.')
67 $file = \Drupal::request()->get('file');
68 $project->identify_project();
70 // Find a better way to do this:
71 // $breadcrumb = array(
72 // l('Home', '<front>'),
73 // l('Administer', 'admin'),
74 // l('Reports', 'admin/reports'),
75 // l('Hacked', 'admin/reports/hacked'),
76 // l($project->title(), 'admin/reports/hacked/' . $project->name),
78 // drupal_set_breadcrumb($breadcrumb);
80 if ($project->file_is_diffable($file)) {
81 $original_file = $project->file_get_location('remote', $file);
82 $installed_file = $project->file_get_location('local', $file);
84 /** @var hackedFileHasher $hasher */
85 $hasher = hacked_get_file_hasher();
89 '#header' => [t('Original'), '', t('Current'), ''],
90 '#rows' => $this->entityComparison->getRows($hasher->fetch_lines($original_file), $hasher->fetch_lines($installed_file), TRUE),
93 // Add the CSS for the diff.
94 $build['#attached']['library'][] = 'diff/diff.general';
95 $theme = $this->config->get('general_settings.theme');
97 if ($theme == 'default') {
98 $build['#attached']['library'][] = 'diff/diff.default';
100 elseif ($theme == 'github') {
101 $build['#attached']['library'][] = 'diff/diff.github';
104 // If the setting could not be loaded or is missing use the default theme.
105 elseif ($theme == NULL) {
106 $build['#attached']['library'][] = 'diff/diff.github';
111 '#markup' => $this->t('Cannot hash binary file or file not found: %file', array('%file' => $file))
116 * Menu title callback for the hacked site report page.
118 public function hackedProjectDiffTitle(hackedProject $project) {
119 $file = \Drupal::request()->get('file');
120 return $this->t('Hacked status for @file in project @project', [
121 '@project' => $project->title(),