RecentCalendarPublicationsBlock.php in Content Planner 8
File
modules/content_calendar/src/Plugin/DashboardBlock/RecentCalendarPublicationsBlock.php
View source
<?php
namespace Drupal\content_calendar\Plugin\DashboardBlock;
use Drupal\content_calendar\ContentService;
use Drupal\content_planner\DashboardBlockBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;
class RecentCalendarPublicationsBlock extends DashboardBlockBase {
public function build() {
$config = $this
->getConfiguration();
$contentService = new ContentService();
$last_publications_limit_config = $this
->getCustomConfigByKey($config, 'last_publications_limit', 3);
$last_nodes = $contentService
->getRecentContent($last_publications_limit_config);
$next_publications_limit_config = $this
->getCustomConfigByKey($config, 'next_publications_limit', 3);
$next_nodes = $contentService
->getFollowingContent($next_publications_limit_config);
return [
'#theme' => 'recent_calendar_content',
'#last_nodes' => $last_nodes,
'#next_nodes' => $next_nodes,
];
}
public function getConfigSpecificFormFields(FormStateInterface &$form_state, Request &$request, array $block_configuration) {
$form = [];
$last_publications_limit_default_value = $this
->getCustomConfigByKey($block_configuration, 'last_publications_limit', 3);
$form['last_publications_limit'] = [
'#type' => 'number',
'#title' => t('Limit number of recently published nodes'),
'#required' => FALSE,
'#default_value' => $last_publications_limit_default_value,
];
$next_publications_limit_default_value = $this
->getCustomConfigByKey($block_configuration, 'next_publications_limit', 3);
$form['next_publications_limit'] = [
'#type' => 'number',
'#title' => t('Limit number of nodes to be published'),
'#required' => FALSE,
'#default_value' => $next_publications_limit_default_value,
];
return $form;
}
}