ContentHelpController.php in Content Synchronization 8
File
src/Controller/ContentHelpController.php
View source
<?php
namespace Drupal\content_sync\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\content_sync\ContentSyncHelpManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ContentHelpController extends ControllerBase implements ContainerInjectionInterface {
protected $helpManager;
public function __construct(ContentSyncHelpManagerInterface $help_manager) {
$this->helpManager = $help_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('content_sync.help_manager'));
}
public function about(Request $request) {
$build = $this->helpManager
->buildAbout();
unset($build['title']);
$build += [
'#prefix' => '<div class="content_sync-help">',
'#suffix' => '</div>',
];
$build['#attached']['library'][] = 'content_sync/content_sync.help';
return $build;
}
public function video(Request $request, $id) {
$id = str_replace('-', '_', $id);
$video = $this->helpManager
->getVideo($id);
if (!$video) {
throw new NotFoundHttpException();
}
$build = [];
if (is_array($video['content'])) {
$build['content'] = $video['content'];
}
else {
$build['content'] = [
'#markup' => $video['content'],
];
}
if ($video['youtube_id']) {
$build['video'] = [
'#theme' => 'content_sync_help_video_youtube',
'#youtube_id' => $video['youtube_id'],
];
}
return $build;
}
public function videoTitle(Request $request, $id) {
$id = str_replace('-', '_', $id);
$video = $this->helpManager
->getVideo($id);
return isset($video) ? $video['title'] : $this
->t('Watch video');
}
}