Passed
Branch feature/linting (138974)
by Christopher
02:18
created

paragraphs_editor_examples_theme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @file
5
 * Provides preprocess logic for example paragraph types.
6
 */
7
8
use Drupal\Component\Utility\Html;
0 ignored issues
show
Bug introduced by
The type Drupal\Component\Utility\Html was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Drupal\paragraphs_editor\Utility\RenderUtility;
10
11
/**
12
 * Implements hook_theme().
13
 */
14
function paragraphs_editor_examples_theme($existing) {
15
  // This hook would not be necessary if the preprocess hooks were implemented
16
  // in the theme layer.
17
  $theme = [];
18
  $template_path = drupal_get_path('module', 'paragraphs_editor_examples') . '/templates';
0 ignored issues
show
Bug introduced by
The function drupal_get_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

18
  $template_path = /** @scrutinizer ignore-call */ drupal_get_path('module', 'paragraphs_editor_examples') . '/templates';
Loading history...
19
  $theme['paragraph__tabs'] = $existing['paragraph'];
20
  $theme['paragraph__tabs']['template'] = 'paragraph--tabs';
21
  $theme['paragraph__tabs']['path'] = $template_path;
22
  return $theme;
23
}
24
25
/**
26
 * Implements hook_preprocess_paragraph__tabs().
27
 */
28
function paragraphs_editor_examples_preprocess_paragraph__tabs(array &$variables) {
29
  // Attach the tab javascript.
30
  $variables['#attached']['library'][] = 'paragraphs_editor_examples/tabs';
31
32
  // Use the tabs entity to build the content to be rendered.
33
  $tabs = $variables['elements']['#paragraph'];
34
  $variables['content'] = [];
35
  foreach ($tabs->field_tabs as $delta => $tab) {
36
    $variables['content']['field_tabs'][$delta] = [
37
      'id' => Html::getId('tabs-' . $delta),
38
      'link' => [
39
        'title' => $tab->entity->field_title->value,
40
      ],
41
    ];
42
43
    // Attach inline editing data to the tab. We have to do this since we aren't
44
    // going to directly render the 'field_content' field in the twig template.
45
    RenderUtility::getEditableData($variables, $tab->entity->field_content)
46
      ->preprocessField($variables['content']['field_tabs'][$delta]);
47
  }
48
}
49