View source
<?php
use Drupal\Core\Link;
use Drupal\Core\Url;
function drupalgap_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
if ($route_name == 'help.page.drupalgap') {
$moduleReadmePath = drupal_get_path('module', 'drupalgap') . '/README.md';
$moduleReadmeLink = Link::fromTextAndUrl(t('Drupal Module README'), Url::fromUri('base:' . $moduleReadmePath))
->toString();
$jsReadmeLink = Link::fromTextAndUrl(t('SDK README'), Url::fromUri('https://github.com/signalpoint/drupalgap/blob/8.x-1.x/README.md'))
->toString();
$restConfigLink = Link::fromTextAndUrl(t('Configure Drupal 8 REST'), Url::fromRoute('restui.list'))
->toString();
$helloWorld = Link::fromTextAndUrl(t('Hello World'), Url::fromUri('http://docs.drupalgap.org/8/Hello_World'))
->toString();
$troubleshoot = Link::fromTextAndUrl(t('Troubleshoot'), Url::fromUri('http://docs.drupalgap.org/8/Resources/Troubleshoot'))
->toString();
$projectDocs = Link::fromTextAndUrl(t('Docs'), Url::fromUri('http://docs.drupalgap.org/8'))
->toString();
$projectAPI = Link::fromTextAndUrl(t('API'), Url::fromUri('http://api.drupalgap.org/8'))
->toString();
$msg = t('Use DrupalGap to build applications powered by Drupal.');
$help = "<p>{$msg}</p>";
$help .= "<ul>";
$help .= "<li>{$moduleReadmeLink}</li>";
$help .= "<li>{$jsReadmeLink}</li>";
$help .= "<li>{$restConfigLink}</li>";
$help .= "<li>{$helloWorld}</li>";
$help .= "<li>{$troubleshoot}</li>";
$help .= "<li>{$projectDocs}</li>";
$help .= "<li>{$projectAPI}</li>";
$help .= "</ul>";
return $help;
}
}
function drupalgap_jdrupal_connect_alter(&$results) {
$result = array(
'remote_addr' => $_SERVER['REMOTE_ADDR'],
);
$ok_entity_types = array(
'comment',
'node',
'user',
);
$result['fieldMap'] = array();
$fieldMap = \Drupal::entityManager()
->getFieldMap();
foreach ($fieldMap as $entity_type => $_fieldMap) {
if (!in_array($entity_type, $ok_entity_types)) {
continue;
}
$result['fieldMap'][$entity_type] = $_fieldMap;
}
$allBundleInfo = \Drupal::entityManager()
->getAllBundleInfo();
$result['allBundleInfo'] = array();
foreach ($allBundleInfo as $entity_type => $_allBundleInfo) {
if (!in_array($entity_type, $ok_entity_types)) {
continue;
}
$result['allBundleInfo'][$entity_type] = $_allBundleInfo;
}
$result['fieldDefinitions'] = array();
$result['fieldStorageConfig'] = array();
foreach ($ok_entity_types as $entity_type) {
$result['fieldDefinitions'][$entity_type] = array();
foreach ($result['allBundleInfo'][$entity_type] as $bundleName => $bundle) {
$result['fieldDefinitions'][$entity_type][$bundleName] = array();
foreach ($result['fieldMap'][$entity_type] as $fieldName => $field) {
$found = FALSE;
foreach ($field['bundles'] as $_bundle) {
if ($bundleName == $_bundle) {
$found = TRUE;
break;
}
}
if (!$found || strpos($fieldName, 'field_') !== 0 && $fieldName != 'body') {
continue;
}
$result['fieldDefinitions'][$entity_type][$bundleName][$fieldName] = \Drupal::config('field.field.' . $entity_type . '.' . $bundleName . '.' . $fieldName)
->get();
}
}
$result['fieldStorageConfig'][$entity_type] = array();
foreach ($result['fieldMap'][$entity_type] as $field_name => $_data) {
$config = \Drupal::config('field.storage.' . $entity_type . '.' . $field_name)
->get();
if (is_array($config) && empty($config)) {
continue;
}
$result['fieldStorageConfig'][$entity_type][$field_name] = $config;
}
}
foreach ($ok_entity_types as $entity_type) {
foreach ($result['allBundleInfo'][$entity_type] as $bundle => $contentType) {
$viewMode = \Drupal::config('core.entity_view_display.' . $entity_type . '.' . $bundle . '.drupalgap')
->get('content');
if (!$viewMode) {
$viewMode = \Drupal::config('core.entity_view_display.' . $entity_type . '.' . $bundle . '.default')
->get('content');
}
$result['entity_view_mode'][$entity_type][$bundle] = $viewMode;
$formMode = \Drupal::config('core.entity_form_display.' . $entity_type . '.' . $bundle . '.drupalgap')
->get('content');
if (!$formMode) {
$formMode = \Drupal::config('core.entity_form_display.' . $entity_type . '.' . $bundle . '.default')
->get('content');
}
$result['entity_form_mode'][$entity_type][$bundle] = $formMode;
}
}
$results['drupalgap'] = $result;
}