class DrupalGapController in DrupalGap 8.2
Same name and namespace in other branches
- 8 src/Controller/DrupalGapController.php \Drupal\DrupalGap\Controller\DrupalGapController
- 8.0.x src/Controller/DrupalGapController.php \Drupal\DrupalGap\Controller\DrupalGapController
Returns responses for DrupalGap module routes.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\drupalgap\Controller\DrupalGapController
Expanded class hierarchy of DrupalGapController
File
- src/
Controller/ DrupalGapController.php, line 17 - Contains \Drupal\drupalgap\Controller\DrupalGapController.
Namespace
Drupal\drupalgap\ControllerView source
class DrupalGapController extends ControllerBase {
/**
* Return the DrupalGap configuration page.
*
* @return string
* A render array containing our DrupalGap configuration page content.
*/
public function drupalgapConfig() {
$output = array();
$output['drupalgap'] = array(
'#attached' => array(
'library' => array(
'drupalgap/drupalgap.config',
),
),
// Render the Status connection and some help docs.
'#markup' => \Drupal::service('renderer')
->render($this
->drupalStatus()),
);
return $output;
}
/**
* Checks the current status and add help link.
*
* @return array
* An array to be rendered with the id for the div where we will check the status and an information link.
*/
public function drupalStatus() {
// Set div id for system connect status message box.
$div_id = 'drupalgap-system-connect-status-message';
// Build more info text and help link string.
$msg = t('Please refer to the <a href="@help_page">DrupalGap Module Help Page</a> for more information.', array(
'@help_page' => 'admin/help/drupalgap',
));
// Create output fieldsets.
$output = array(
'drupalgap_system_connect_status' => array(
'#theme' => 'fieldset',
'#title' => t('System Connect Status'),
'#description' => '<div id="' . $div_id . '"> </div>',
),
'drupalgap_information' => array(
'#theme' => 'fieldset',
'#title' => t('More Information'),
'#description' => "<p>{$msg}</p>",
),
);
return $output;
}
/**
* @see https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityManagerInterface.php/interface/EntityManagerInterface/8
*/
public function drupalgapConnect() {
$response = new Response();
$result = new \stdClass();
//$entity_type = 'node';
//$bundle = 'course';
//$field_name = 'field_address';
// @TODO make this configurable.
$ok_entity_types = array(
'comment',
'file',
'node',
'taxonomy_term',
'user',
);
// Field map.
$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;
}
// All bundle info.
$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->getBundleInfo = \Drupal::entityManager()->getBundleInfo($entity_type);
// Field definitions and storage configs.
$result->fieldDefinitions = array();
$result->fieldStorageConfig = array();
$result->entityFormDisplay = array();
//$result->FieldConfig = \Drupal\field\Entity\FieldConfig::loadByName($entity_type, $bundle, $field_name);
//$result->fieldDefinitions = \Drupal::entityManager()->getFieldDefinitions($entity_type, $bundle);
// For each entity type...
foreach ($ok_entity_types as $entity_type) {
// Add the field definition for each bundle...
$result->fieldDefinitions[$entity_type] = array();
$result->entityFormDisplay[$entity_type] = array();
foreach ($result->allBundleInfo[$entity_type] as $bundle_name => $bundle) {
$result->fieldDefinitions[$entity_type][$bundle_name] = \Drupal::entityManager()
->getFieldDefinitions($entity_type, $bundle_name);
$form_mode = 'default';
$result->entityFormDisplay[$entity_type][$bundle_name] = entity_get_form_display($entity_type, $bundle_name, $form_mode)
->getMode();
}
// Add the field storage config for each field on the entity type.
$result->fieldStorageConfig[$entity_type] = array();
foreach ($result->fieldMap[$entity_type] as $field_name => $_data) {
// @todo we should be using the loadByName function here, but it isn't
// working
// @see http://drupal.stackexchange.com/q/167001/10645
//$result->fieldStorageConfig[$entity_type][$field_name] =
//\Drupal\field\Entity\FieldStorageConfig::loadByName($entity_type, $field_name);
$result->fieldStorageConfig[$entity_type][$field_name] = \Drupal::config('field.storage.' . $entity_type . '.' . $field_name)
->get();
}
// DISPLAYS
//core.entity_form_display.node.course.default
//core.entity_view_display.node.course.default
//core.entity_view_mode.node.full
}
// May be useful at some point...
//$result->getAllViewModes = \Drupal::entityManager()->getAllViewModes();
//$result->getViewModes = \Drupal::entityManager()->getViewModes($entity_type);
//$result->getAllFormModes = \Drupal::entityManager()->getAllFormModes();
// Doesn't work.
//\Drupal\field\Entity\FieldStorageConfig::loadByName($entity_type, $field_name);
// Does work.
//\Drupal::config('field.storage.node.field_address')->get();
//$result->getFieldStorageDefinitions = \Drupal::entityManager()->getFieldStorageDefinitions($entity_type);
//$result->loadMultiple = \Drupal::entityManager()->getStorage('field_storage_config')->loadMultiple();
$response
->setContent(json_encode($result));
$response->headers
->set('Content-Type', 'application/json');
return $response;
}
/**
*
*
*/
public function drupalgapSystemConnect() {
$response = new Response();
// @see https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Session!AccountProxyInterface.php/interface/AccountProxyInterface/8
$user = \Drupal::currentUser();
$_account = $user
->getAccount();
$account = new \stdClass();
$account->uid = $_account
->id();
$account->name = $_account
->getUsername();
$account->roles = $_account
->getRoles();
foreach ($_account as $key => $value) {
$account->{$key} = $value;
}
unset($account->pass);
if (!$_account
->hasPermission('administer users')) {
unset($account->init);
}
if (!$_account
->isAuthenticated()) {
$account->roles = array(
'anonymous user',
);
}
$json = array(
'user' => $account,
'remote_addr' => $_SERVER['REMOTE_ADDR'],
);
$response
->setContent(json_encode($json));
$response->headers
->set('Content-Type', 'application/json');
return $response;
}
/**
* Obtain current user data. This is basically copied from D7 Services module.
* For more info take a look at _system_resource_connect() function (Services).
*/
public function userSystemResources() {
// Currently logged in user.
$output = new \stdClass();
//$output->sessid = \Drupal::currentUser()->getSessionId();
//$output->user_name = \Drupal::currentUser()->getSessionData();
$output->uid = \Drupal::currentUser()
->getAccount()
->id();
$output->roles = (object) \Drupal::currentUser()
->getRoles();
return $output;
}
/**
* Returns a collection of variables from the current Drupal site.
*
* @return array
* Array of variables from the configuration.
*/
public function drupalgapResourceSystemSiteSettings() {
// Config names.
$names = array(
// @TODO for the moment only working for 'user_register'
/*'admin_theme',
'clean_url',
'date_default_timezone',
'site_name',
'theme_default',
'user_pictures',
'user_email_verification',*/
'user.settings' => array(
'register',
),
);
// Invoke hook_drupalgap_site_settings() to let others specify variable names
// to use.
if (sizeof(\Drupal::moduleHandler()
->getImplementations('drupalgap_site_settings')) > 0) {
\Drupal::moduleHandler()
->invokeAll('drupalgap_site_settings', $names);
}
// Now fetch the values.
$settings = new \stdClass();
foreach ($names as $settingKeys => $settingKey) {
foreach ($settingKey as $name) {
$value = \Drupal::config($settingKeys)
->get($name);
$settings->variable = new \stdClass();
$settings->variable->{$name} = $value;
}
}
// Add Drupal core version into settings.
$settings->variable->drupal_core = "8";
return $settings->variable;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
40 |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
DrupalGapController:: |
public | function | Return the DrupalGap configuration page. | |
DrupalGapController:: |
public | function | ||
DrupalGapController:: |
public | function | Returns a collection of variables from the current Drupal site. | |
DrupalGapController:: |
public | function | ||
DrupalGapController:: |
public | function | Checks the current status and add help link. | |
DrupalGapController:: |
public | function | Obtain current user data. This is basically copied from D7 Services module. For more info take a look at _system_resource_connect() function (Services). | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |