class SocialTourController in Open Social 8
Same name and namespace in other branches
- 8.9 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 8.2 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 8.3 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 8.4 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 8.5 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 8.6 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 8.7 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 8.8 modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 10.3.x modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 10.0.x modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 10.1.x modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
- 10.2.x modules/custom/social_tour/src/SocialTourController.php \Drupal\social_tour\SocialTourController
Class SocialTourController.
Returns responses for Social Group routes.
@package Drupal\social_tour
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\social_tour\SocialTourController
Expanded class hierarchy of SocialTourController
1 string reference to 'SocialTourController'
- social_tour.services.yml in modules/
custom/ social_tour/ social_tour.services.yml - modules/custom/social_tour/social_tour.services.yml
1 service uses SocialTourController
- social_tour.onboarding in modules/
custom/ social_tour/ social_tour.services.yml - Drupal\social_tour\SocialTourController
File
- modules/
custom/ social_tour/ src/ SocialTourController.php, line 21
Namespace
Drupal\social_tourView source
class SocialTourController extends ControllerBase {
/**
* Protected var UserData.
*
* @var \Drupal\user\UserData
*/
protected $userData;
/**
* Protected var ConfigFactory.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* Protected var for the current user.
*
* @var \Drupal\Core\Session\AccountProxy
*/
protected $currentUser;
/**
* SocialTourController constructor.
*/
public function __construct(UserData $user_data, ConfigFactory $config_factory, AccountProxy $current_user) {
// We needs it.
$this->userData = $user_data;
$this->configFactory = $config_factory
->get('social_tour.settings');
$this->currentUser = $current_user;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('user.data'), $container
->get('config.factory'), $container
->get('current_user'));
}
/**
* Check if onboarding is enabled.
*
* @return bool
* Returns either TRUE or FALSE.
*/
public function onboardingEnabled() {
// Check if tour is enabled by SM setting.
if ($this->configFactory
->get('social_tour_enabled') == FALSE) {
return FALSE;
}
// Check permissions.
if (!$this->currentUser
->hasPermission('access tour')) {
return FALSE;
}
// Check if current disabled it.
if ($this->userData
->get('social_tour', $this->currentUser
->id(), 'onboarding_disabled') == TRUE) {
return FALSE;
}
return TRUE;
}
/**
* Toggle onboarding.
*
* @param array $account
* Array containing the account.
*/
public function toggleOnboarding(array $account = NULL) {
// No user given, then current user.
$id = $this->currentUser
->id();
if ($account instanceof User) {
$id = $account
->id();
}
$new_value = TRUE;
if ($this->userData
->get('social_tour', $id, 'onboarding_disabled') == TRUE) {
$new_value = FALSE;
}
// Save the value in the user_data.
$this
->setData($new_value);
}
/**
* Enable onboarding for current_user by Ajax call.
*/
public function enableOnboarding() {
// Save the value in the user_data.
$this
->setData(FALSE);
// Return 200.
return new JsonResponse([
'message' => $this
->t('Onboarding has been enabled.'),
], 200, [
'Content-Type' => 'application/json',
]);
}
/**
* Disable onboarding for current_user by Ajax call.
*/
public function disableOnboarding() {
// Save the value in the user_data.
$this
->setData(TRUE);
$redirect = \Drupal::request()
->get('destination') ?: '/stream';
// Set a message that they can be turned on again.
drupal_set_message($this
->t('You will not see tips like this anymore.'));
// Return to Profile.
return new RedirectResponse($redirect);
}
/**
* Set onboarding data value.
*
* @param bool $disabled
* Type of bool, either TRUE or FALSE.
*/
private function setData($disabled = TRUE) {
$this->userData
->set('social_tour', $this->currentUser
->id(), 'onboarding_disabled', $disabled);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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:: |
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. | |
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. | |
SocialTourController:: |
protected | property |
Protected var ConfigFactory. Overrides ControllerBase:: |
|
SocialTourController:: |
protected | property |
Protected var for the current user. Overrides ControllerBase:: |
|
SocialTourController:: |
protected | property | Protected var UserData. | |
SocialTourController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
SocialTourController:: |
public | function | Disable onboarding for current_user by Ajax call. | |
SocialTourController:: |
public | function | Enable onboarding for current_user by Ajax call. | |
SocialTourController:: |
public | function | Check if onboarding is enabled. | |
SocialTourController:: |
private | function | Set onboarding data value. | |
SocialTourController:: |
public | function | Toggle onboarding. | |
SocialTourController:: |
public | function | SocialTourController constructor. | |
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. |