GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — release/7.2.2 ( daf9d5...db01ca )
by
unknown
24:11 queued 14:05
created

df_tools_acquiadam_menu_local_tasks_alter()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
/**
4
 * @file
5
 * Contains df_tools_acquiadam.module.
6
 */
7
8
use Drupal\Core\Entity\EntityInterface;
9
use Drupal\Core\Form\FormStateInterface;
10
use Drupal\media\MediaInterface;
11
12
/**
13
 * Implements hook_form_alter().
14
 */
15
function df_tools_acquiadam_form_alter(&$form, FormStateInterface $form_state, $form_id) {
0 ignored issues
show
Unused Code introduced by
The parameter $form_state is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

15
function df_tools_acquiadam_form_alter(&$form, /** @scrutinizer ignore-unused */ FormStateInterface $form_state, $form_id) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
  $dam_add_forms = '/^media_acquia_dam_.*_add_form$/';
17
  $dam_edit_forms = '/^media_acquia_dam_.*_edit_form$/';
18
19
  // Hide DAM fields when creating DAM media entities.
20
  if (preg_match($dam_add_forms, $form_id)) {
21
    $fields_to_hide = [
22
      'name',
23
      'acquia_dam_asset_id',
24
      'acquia_dam_alt_text',
25
      'status',
26
    ];
27
    foreach ($fields_to_hide as $field) {
28
      if (isset($form[$field])) {
29
        $form[$field]['#access'] = FALSE;
30
      }
31
    }
32
  }
33
34
  // Disable DAM fields when editing DAM media entities.
35
  if (preg_match($dam_edit_forms, $form_id)) {
36
    $fields_to_disable = [
37
      'name',
38
      'acquia_dam_alt_text',
39
    ];
40
    foreach ($fields_to_disable as $field) {
41
      if (isset($form[$field])) {
42
        $form[$field]['#disabled'] = TRUE;
43
      }
44
    }
45
  }
46
}
47
48
/**
49
 * Implements hook_entity_operation_alter().
50
 */
51
function df_tools_acquiadam_entity_operation_alter(array &$operations, EntityInterface $entity) {
52
  // Remove the clone operation for DAM media entities.
53
  $entityTypeId = $entity->getEntityTypeId();
54
  $bundle = $entity->bundle();
55
56
  if ($entityTypeId == 'media' || strpos($bundle, 'acquia_dam_') === 0) {
57
    unset($operations['clone']);
58
  }
59
}
60
61
/**
62
 * Implements hook_menu_local_tasks_alter().
63
 */
64
function df_tools_acquiadam_menu_local_tasks_alter(&$data, $route_name) {
65
  // Remove the clone operation for DAM media entities.
66
  $routes = ['entity.media.edit_form', 'entity.media.canonical'];
67
  if (in_array($route_name, $routes)) {
68
    $route_match = \Drupal::routeMatch();
69
    $media = $route_match->getParameter('media');
70
71
    if ($media instanceof MediaInterface && strpos($media->bundle(), 'acquia_dam_') === 0) {
72
      unset($data['tabs'][0]['entity_clone.clone:media.clone_tab']);
73
    }
74
  }
75
}
76