class CalendarEventController in Fullcalendar View 8
Same name and namespace in other branches
- 8.3 src/Controller/CalendarEventController.php \Drupal\fullcalendar_view\Controller\CalendarEventController
- 8.2 src/Controller/CalendarEventController.php \Drupal\fullcalendar_view\Controller\CalendarEventController
- 6.x src/Controller/CalendarEventController.php \Drupal\fullcalendar_view\Controller\CalendarEventController
- 5.x src/Controller/CalendarEventController.php \Drupal\fullcalendar_view\Controller\CalendarEventController
Calendar Event Controller.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\fullcalendar_view\Controller\CalendarEventController
Expanded class hierarchy of CalendarEventController
File
- src/
Controller/ CalendarEventController.php, line 15
Namespace
Drupal\fullcalendar_view\ControllerView source
class CalendarEventController extends ControllerBase {
/**
* Construct the Controller.
*
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
* Logger factory object.
*/
public function __construct(LoggerChannelFactoryInterface $loggerFactory) {
$this->loggerFactory = $loggerFactory;
}
/**
* Create a CalendarEventController instance.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* Container object.
*
* @return \Drupal\fullcalendar_view\Controller\CalendarEventController
* The instance of CalendarEventController.
*/
public static function create(ContainerInterface $container) {
$loggerFactory = $container
->get('logger.factory');
return new static($loggerFactory);
}
/**
* Event Update Handler.
*/
public function updateEvent(Request $request) {
$user = $this
->currentUser();
if (!empty($user)) {
$nid = $request->request
->get('nid', '');
$start_date = $request->request
->get('start', '');
$end_date = $request->request
->get('end', '');
$start_field = $request->request
->get('start_field', '');
$end_field = $request->request
->get('end_field', '');
if (!empty($nid) && !empty($start_date) && !empty($start_field)) {
$node = $this
->entityTypeManager()
->getStorage('node')
->load($nid);
if (!empty($node) && $node
->access('update')) {
if (isset($node->{$start_field})) {
// Field definitions.
$fields_def = $node
->getFieldDefinition($start_field);
$start_type = $fields_def
->getType();
if (isset($node->{$end_field}) && !empty($end_date)) {
$fields_def = $node
->getFieldDefinition($end_field);
$end_type = $fields_def
->getType();
}
// Multiple value of start field.
if (is_array($node->{$start_field})) {
if ($start_type === 'datetime') {
$length = strlen($node->{$start_field}[0]);
if ($length > 10) {
// Only update the first value.
$node->{$start_field}[0] = [
'value' => substr(gmdate(DATE_ATOM, strtotime($start_date)), 0, $length),
];
}
else {
$node->{$start_field}[0] = [
'value' => $start_date,
];
}
}
}
else {
// Dateime field.
if ($start_type === 'datetime') {
$length = strlen($node->{$start_field}->value);
if ($length > 10) {
// UTC Date with time.
$node->{$start_field}->value = gmdate("Y-m-d\\TH:i:s", strtotime($start_date));
}
else {
$node->{$start_field}->value = $start_date;
}
}
elseif ($start_type === 'timestamp') {
$node->{$start_field}->value = strtotime($start_date);
}
}
// End date.
if (isset($end_type)) {
// Multiple value of end field.
if (is_array($node->{$end_field})) {
if ($end_type === 'datetime') {
$length = strlen($node->{$end_field}[0]);
if ($length > 10) {
// Only update the first value.
$node->{$end_field}[0] = [
'value' => substr(gmdate(DATE_ATOM, strtotime($end_date)), 0, $length),
];
}
else {
$node->{$end_field}[0] = [
'value' => $end_date,
];
}
}
}
else {
// Dateime field.
if ($end_type === 'datetime') {
$length = strlen($node->{$end_field}->value);
if ($length > 10) {
// UTC Date with time.
$node->{$end_field}->value = gmdate("Y-m-d\\TH:i:s", strtotime($end_date));
}
else {
$node->{$end_field}->value = $end_date;
}
}
elseif ($end_type === 'timestamp') {
$node->{$end_field}->value = strtotime($end_date);
}
}
}
$node
->save();
// Log the content changed.
$this->loggerFactory
->get('content')
->notice($node
->getType() . ': updated ' . $node
->getTitle());
return new Response($node
->getTitle() . ' is updated to from ' . $start_date . ' to ' . $end_date);
}
}
else {
return new Response('Access denied!');
}
}
else {
return new Response('Parameter Missing.');
}
}
else {
return new Response('Invalid User!');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CalendarEventController:: |
public static | function |
Create a CalendarEventController instance. Overrides ControllerBase:: |
|
CalendarEventController:: |
public | function | Event Update Handler. | |
CalendarEventController:: |
public | function | Construct the Controller. | |
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:: |
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. | |
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. |