-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrown_d8react_integration.module
More file actions
73 lines (67 loc) · 2.32 KB
/
brown_d8react_integration.module
File metadata and controls
73 lines (67 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* @file
* Contains brown_d8react_integration.module.
* @author James Morton <james_morton@brown.edu>
*/
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Access\AccessResult;
/**
* App List Function
* Return list of react apps based on contents of /apps directory
*
* @return array
* An array of possible key and value options.
*
* @see options_allowed_values()
*/
function brown_d8react_integration_available_react_apps() {
$current_path = \Drupal::service('extension.path.resolver')->getPath('module', 'brown_d8react_integration');
$apps = array_diff(scandir($current_path.'/apps'), array('..', '.'));
$options = [];
foreach ($apps as $app) {
$appName = pathinfo($current_path.'/apps/'.$app, PATHINFO_FILENAME);
if ($appName === "sitewide") {
continue;
}
$appNameNice = ucwords(str_replace("-", " ", $appName));
$options[$appName] = $appNameNice;
}
return $options;
}
/**
* Theme Integration
* Add paragraph type template to display the chosen react app
*
* Implements hook_theme().
*
* @return array
* Location of template and base hook to see if the template should be used
*/
function brown_d8react_integration_theme() {
return array(
'paragraph__react_app' => array(
'template' => 'paragraph--brown-d8react-integration',
'base hook' => 'paragraph'
),
);
}
function brown_d8react_integration_page_attachments(array &$page) {
$canOnlyEditConfig = false;
$user = \Drupal::currentUser();
if ($user->hasPermission('edit react app config') && !$user->hasPermission('insert react micro-app')) {
$canOnlyEditConfig = true;
}
if (\Drupal::service('router.admin_context')->isAdminRoute()) {
$page['#attached']['library'][] = 'brown_d8react_integration/dreact_permissions';
$page['#attached']['drupalSettings']['brown_d8react_integration']['dreact_permissions']['canOnlyEditConfig'] = $canOnlyEditConfig;
}
$config = \Drupal::config('brown_d8react_integration.adminsettings');
if (!\Drupal::service('router.admin_context')->isAdminRoute()) {
if($config->get('sitewide_app') !== 'none') {
$page['#attached']['library'][] = 'brown_d8react_integration/'.$config->get('sitewide_app');
}
}
}