SocialEventEnrollService.php in Open Social 10.2.x
Same filename and directory in other branches
- 8.9 modules/social_features/social_event/src/Service/SocialEventEnrollService.php
- 8.5 modules/social_features/social_event/src/Service/SocialEventEnrollService.php
- 8.6 modules/social_features/social_event/src/Service/SocialEventEnrollService.php
- 8.7 modules/social_features/social_event/src/Service/SocialEventEnrollService.php
- 8.8 modules/social_features/social_event/src/Service/SocialEventEnrollService.php
- 10.3.x modules/social_features/social_event/src/Service/SocialEventEnrollService.php
- 10.0.x modules/social_features/social_event/src/Service/SocialEventEnrollService.php
- 10.1.x modules/social_features/social_event/src/Service/SocialEventEnrollService.php
Namespace
Drupal\social_event\ServiceFile
modules/social_features/social_event/src/Service/SocialEventEnrollService.phpView source
<?php
namespace Drupal\social_event\Service;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\node\NodeInterface;
use Drupal\social_event\EventEnrollmentInterface;
/**
* Class SocialEventEnrollService.
*
* @package Drupal\social_event\Service
*/
class SocialEventEnrollService implements SocialEventEnrollServiceInterface {
/**
* The event settings.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $eventSettings;
/**
* SocialEventEnrollService constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->eventSettings = $config_factory
->get('social_event.settings');
}
/**
* {@inheritdoc}
*/
public function isEnabled(NodeInterface $node) {
if ($this->eventSettings
->get('disable_event_enroll') || !$node
->hasField('field_event_enable_enrollment') || $node
->get('field_event_enable_enrollment')
->isEmpty() || !(bool) $node
->get('field_event_enable_enrollment')
->first()
->getValue()['value']) {
return FALSE;
}
if ($node
->bundle() === 'event' && $node
->hasField('field_event_enroll')) {
$was_not_changed = $node
->get('field_event_enroll')
->isEmpty();
$is_enabled = $node
->get('field_event_enroll')
->first()
->getValue()['value'];
// Make an exception for the invite enroll method.
// This doesn't allow people to enroll themselves, but get invited.
if (!$node
->get('field_enroll_method')
->isEmpty() && (int) $node
->get('field_enroll_method')
->first()
->getValue()['value'] === EventEnrollmentInterface::ENROLL_METHOD_INVITE) {
$is_enabled = TRUE;
}
return $was_not_changed || $is_enabled;
}
return FALSE;
}
}
Classes
Name | Description |
---|---|
SocialEventEnrollService | Class SocialEventEnrollService. |