CalendarEntry.php in Content Planner 8
File
modules/content_calendar/src/Component/CalendarEntry.php
View source
<?php
namespace Drupal\content_calendar\Component;
use Drupal\content_calendar\DateTimeHelper;
use Drupal\content_calendar\Entity\ContentTypeConfig;
use Drupal\content_calendar\Form\SettingsForm;
use Drupal\content_planner\Component\BaseEntry;
class CalendarEntry extends BaseEntry {
protected $month;
protected $year;
protected $contentTypeConfig;
protected $node;
protected $config;
public function __construct($month, $year, ContentTypeConfig $content_type_config, \stdClass $node) {
$this->month = $month;
$this->year = $year;
$this->contentTypeConfig = $content_type_config;
$this->node = $node;
$this->config = \Drupal::config(SettingsForm::CONFIG_NAME);
}
public function getNodeID() {
return $this->node->nid;
}
public function getRelevantDate() {
if ($this->node->publish_on) {
return $this->node->publish_on;
}
return $this->node->created;
}
public function formatSchedulingDateAsMySQLDateOnly() {
$datetime = DateTimeHelper::convertUnixTimestampToDatetime($this->node->created);
return $datetime
->format(DateTimeHelper::FORMAT_MYSQL_DATE_ONLY);
}
public function build() {
$user_picture = $this
->getUserPictureURL();
if ($this->node->publish_on) {
$this->node->scheduled = true;
}
else {
$this->node->scheduled = false;
}
$this->node->publish_on_time = DateTimeHelper::convertUnixTimestampToDatetime($this->node->publish_on)
->format('H:i');
$this->node->created_on_time = DateTimeHelper::convertUnixTimestampToDatetime($this->node->created)
->format('H:i');
$options = $this
->buildOptions();
if (\Drupal::currentUser()
->hasPermission('manage content calendar')) {
$this->node->editoptions = true;
}
if (\Drupal::currentUser()
->hasPermission('manage own content calendar')) {
if ($this->node->uid == \Drupal::currentUser()
->id()) {
$this->node->editoptions = true;
}
}
$build = [
'#theme' => 'content_calendar_entry',
'#node' => $this->node,
'#node_type_config' => $this->contentTypeConfig,
'#month' => $this->month,
'#year' => $this->year,
'#user_picture' => $user_picture,
'#options' => $options,
];
return $build;
}
protected function buildOptions() {
$options = [];
$options['bg_color_unpublished_content'] = $this->config
->get('bg_color_unpublished_content') ? $this->config
->get('bg_color_unpublished_content') : SettingsForm::DEFAULT_BG_COLOR_UNPUBLISHED_CONTENT;
return $options;
}
protected function getUserPictureURL() {
if ($this->config
->get('show_user_thumb')) {
return $this
->getUserPictureFromCache($this->node->uid, 'content_calendar_user_thumb');
}
return FALSE;
}
}